1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Problem in C coding of 89c51; urgent help required.

Discussion in '8051/8951' started by Qaisar Azeemi, Feb 28, 2012.

  1. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    I have an error C202: 'P3_3' undefined identifier. What changes should i make in my prog please tell me.
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK
    What compiler????
     
  3. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Keil C. Now i am getting error in for loop. It says semicolon before <= and bracket missing but i have put it.
    for(tno=1; tno<=no;tno++);
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK

    As far as I'm aware, the header file contains the definitions for bit access... You will need to open this file to see them..

    I would also need to see your code, as when the C text file is parsed then error may be on a different line... If the line above isn't terminated the compiler will just read on until something doesn't match!!
     
  6. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    How do i snd you the code. I am unable to do so
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK
    copy and paste into the thread.... Then I'll clean it up with code tags.. Then I'll be able to help more..
     
  8. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Unaltered code
    Code (c):

    #include < stdio.h >
    #include < reg51.h >
    #include < Delay.h >

    sbit INTO = P3 ^ 2;
    sbit TRG = P3 ^ 3;
    sbit Buzzer = P3 ^ 7;

    void Beep(unsigned char No, unsigned int Delay);
    void tmrInit(void);
    void tmrReset(void);

    unsigned int L1 = 100, L2 = 20;

    unsigned int T0_ISR_count = 0;
    unsigned int US = 0;
    unsigned int CM = 0;

    void T0_ISR(void) interrupt 1 {
      T0_ISR_count++;
      TF0 = 0;
    }

    void main(void) {
      Beep(3, 20000);
      TRG = 0;
      tmrInit();
      while (1) {

        tmrReset();

        TRG = 1;
        DelayI(1000);
        TRG = 0;
        while (INT0 == 0)
          TR0 = 1;
        while (INT0 == 1)

          TR0 = 0;

        US = (unsigned int)((TH0 << 8) | TL0 | ((unsigned int) T0_ISR_count << 16));

        CM = US / 58;

        if ((CM <= L1) && (CM >= L2)) {
          Beep(1, 50 * CM);
        }
        if (CM <= L2) {
          Buzzer = 0;
        } else {
          Buzzer = 1;
        }
        DelayL(2000);
      }

      void tmrReset(void)
      T0_ISR_count = 0;
      TH0 = 0;
      TL0 = 0;
      TR0 = 0;

      void tmrInit(void)
      TMOD = (TMOD & 0xF0) | 0x09;

      void Beep(unsigned char No, unsigned int Delay)
      unsigned char tNo;

      for (tNo = 1; tNo <= No; tNo++) {
        Buzzer = 0;
        DelayI(Delay);
        Buzzer = 1;
        DelayI(Delay);
      }
    }
     
    Code fixed..
    Code (c):

    #include<stdio.h>
    #include<reg51.h>
    #include<Delay.h>
    sbit INTO=P3^2;
    sbit TRG=P3^3;
    sbit Buzzer=P3^7;

    void Beep(unsigned char No,unsigned int Delay);
    void tmrInit(void);
    void tmrReset(void);

    unsigned int L1=100,L2=20;

    unsigned int T0_ISR_count=0;
    unsigned int US=0;
    unsigned int CM=0;

    void T0_ISR (void) interrupt 1
       {
       T0_ISR_count++;
       TF0=0;
       }

    void main (void)
       {
       Beep(3,20000);
       TRG=0;
       tmrInit();
       while(1)
         {
         tmrReset();
         TRG=1;
         DelayI(1000);
         TRG=0;
         while(INT0==0)
         TR0=1;
         while(INT0==1)
           TR0=0;
         US=(unsigned int)((TH0<<8)|TL0|((unsigned int)T0_ISR_count<<16));
         CM=US/58;
         if((CM<=L1)&&(CM>=L2))
           {
           Beep(1,50*CM);
           }
         if(CM<=L2)
           {
           Buzzer=0;
           }
         else
           {
           Buzzer=1;
           }
         }
       DelayL(2000);
       }

     
    void tmrReset(void)
       {
       T0_ISR_count=0;
       TH0=0;
       TL0=0;
       TR0=0;
       }
    ///////////////////////

    void tmrInit(void)
       {
       TMOD=(TMOD & 0xF0)|0x09;
       }

    void Beep(unsigned char No,unsigned int Delay)
       {
       unsigned char tNo;

       for(tNo=1;tNo<=No;tNo++)
         {
         Buzzer=0;
         DelayI(Delay);
         Buzzer=1;
         DelayI(Delay);
         }
       }
     
     
    Last edited by a moderator: Sep 29, 2016
  9. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Please correct the whole code. I am new to this. And there are many errors appearing as i solve 1 nxt appears
     
  10. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,500
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    It looks to me like you're missing a whole lot of brackets.
     
  11. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Please tell me where.. and is the rest of the code correct??
     
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK
    I made changes to your code..

    All the functions have to be encapsulated with { }
     
  13. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Ok thank u. Please post the changes
     
  14. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,500
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    You need to enclose all of your functions in brackets {}.

    For example, here is some of your original code:

    Code (c):
     void tmrReset(void)
      T0_ISR_count = 0;
      TH0 = 0;
      TL0 = 0;
      TR0 = 0;

     void tmrInit(void)
      TMOD = (TMOD & 0xF0) | 0x09;

     void Beep(unsigned char No, unsigned int Delay)
     unsigned char tNo;

     for (tNo = 1; tNo <= No; tNo++) {
        Buzzer = 0;
        DelayI(Delay);
        Buzzer = 1;
        DelayI(Delay);
     }
    There are three functions there (tmrReset, tmrInit, and Beep), but no brackets to separate them. It should look like this:

    Code (c):
     void tmrReset(void) {
      T0_ISR_count = 0;
      TH0 = 0;
      TL0 = 0;
      TR0 = 0;
    }
     void tmrInit(void) {
      TMOD = (TMOD & 0xF0) | 0x09;
    }

     void Beep(unsigned char No, unsigned int Delay) {
       unsigned char tNo;

       for (tNo = 1; tNo <= No; tNo++) {
         Buzzer = 0;
         DelayI(Delay);
         Buzzer = 1;
         DelayI(Delay);
      }
    }

    Ian Rogers , could you show your edits in a separate post please? I think it would be more useful for Aayesha's original code to be visible, and have your edits shown separately.
     
  15. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Can u please check the entire prog if there are any other mistakes.
     
  16. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    I am getting error that says: redefinition INT0
     
  17. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Is the DelayI(1000); statement correct or i should give DelayI();
     
  18. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK
    There you go.... BTW there was one curly bracket missing in the superloop as well!!!!
     
  19. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Which one
     
  20. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,250
    Likes:
    911
    Location:
    Rochdale UK
    No idea.... The function will be declared in delay.h.... Take a look and see...

    Again... a closing brace.... Before or after the delay statement!!

    I think I slipped it in the wrong place as the delayL(2000) is superfluous now...

    Looking at the code I would say delayI() is for integer variables and delayL() is for longs... so delayI() wouldn't be used as there is no parameter...
     
  21. Aayesha

    Aayesha New Member

    Joined:
    Sep 29, 2016
    Messages:
    12
    Likes:
    0
    Thank you for the help. I'l compile the program and let you know if i need any more help.
     

Share This Page