project.c(26): error C202: 'P1': undefined identifier

Thread Starter

vivekbinwal_200

Joined Jul 8, 2015
3
Hello friends...i need your expert advice.
I am need to microcontroller programming...trying to make a time delay of 30secs ON & 5 min OFF.
Here goes my program-
#include <REG2.H>

#include <stdio.h>

void delay30(void)

{
long i;
i=1500000;
while (i--);
}

void delay150(void)
{
long i1;
i=15000000;
while (i--);
}

void main(void)
{
while(1)
{
P1=0x01;
delay30();
P1=0x00;
delay150();
}
}

It is not gtg compiled & compiler is showing error as "project.c(26): error C202: 'P1': undefined identifier"
Kindly guide me...
 

WBahn

Joined Mar 31, 2012
29,978
Well, where do you declare P1? The compiler is not a mind reader.

You might also try properly formatting your code so that others can read it more easily. Also, it helps if you use [CODE] tags around your code. You can even get automatic syntax highlighting now by including the language (if supported) [CODE=C]

C:
#include <REG2.H>
#include <stdio.h>

void delay30(void)
{
   long i;
   i=1500000;
   while (i--)
      ; // EMPTY LOOP
}

void delay150(void)
{
   long i1;
   i=15000000;
   while (i--)
      ; // EMPTY LOOP
}

void main(void)
{
   while(1)
   {
      P1=0x01;
      delay30();
      P1=0x00;
      delay150();
   }
}
Why does 'delay30()' count to 15 million while 'delay150()' counts to 150 million? The name implies a delay that is 5 times as long, not 10?

Why does 'delay150()' use the variable 'i' when it declares a variable 'i1'?
 

Thread Starter

vivekbinwal_200

Joined Jul 8, 2015
3
Thanks WBahn...!!!
Thanks for guiding me...actually, i am new to micro controllers...just trying to do my first project which can provide Logic 1 for 30 secs and Logic 0 for 5 mins. I know, i have to vary the loop variables to get exact time interval as time delay depends on crystal frequency as well.
Can you just correct the faults in my program...so that i can compile it successfully...thanks once again.
 

Thread Starter

vivekbinwal_200

Joined Jul 8, 2015
3
OK..I got it...I have to include "#include "REGX52.h" //for 89S52 controller" in program starting...
Now above said error is not coming...instead, it is showing..."project.c(17): error C202: 'i': undefined identifier"..
Now my program follows as:
#include <REG2.H>

#include <stdio.h>

void delay30(void)

{
long i;
i=1500000;
while (i--); //EMPTY LOOP
}

void delay150(void)
{
long i1;
i1=15000000;
while (i--); //EMPTY LOOP
}

void main(void)
{
while(1)
{
P1=0x01;
delay30();
P1=0x00;
delay150();
}
}
 

theonewho

Joined Jul 9, 2015
17
You only updated one of your references to i in your delay150 function:

C:
void delay150(void)
{
long i1;
i1=15000000;
while (i--); // <-- Forgot to update that one
}

Please enclose your pasted code in code tags.
 
Top