Continue to Site

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.

  • 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.

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

Status
Not open for further replies.
I have an error C202: 'P3_3' undefined identifier. What changes should i make in my prog please tell me.
 
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++);
 
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!!
 
Unaltered 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..
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:
Please correct the whole code. I am new to this. And there are many errors appearing as i solve 1 nxt appears
 
It looks to me like you're missing a whole lot of brackets.
 
Please tell me where.. and is the rest of the code correct??

You need to enclose all of your functions in brackets {}.

For example, here is some of your original 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:

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.
 
Is the DelayI(1000); statement correct or i should give DelayI();
No idea.... The function will be declared in delay.h.... Take a look and see...

Which one
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...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top