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

Discussion in 'Programmer's Corner' started by vivekbinwal_200, Jul 11, 2015.

  1. vivekbinwal_200

    Thread Starter New Member

    Jul 8, 2015
    3
    0
    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...
     
  2. WBahn

    Moderator

    Mar 31, 2012
    17,757
    4,800
    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]

    Code (C):
    1.  
    2. #include <REG2.H>
    3. #include <stdio.h>
    4.  
    5. void delay30(void)
    6. {
    7.    long i;
    8.    i=1500000;
    9.    while (i--)
    10.       ; // EMPTY LOOP
    11. }
    12.  
    13. void delay150(void)
    14. {
    15.    long i1;
    16.    i=15000000;
    17.    while (i--)
    18.       ; // EMPTY LOOP
    19. }
    20.  
    21. void main(void)
    22. {
    23.    while(1)
    24.    {
    25.       P1=0x01;
    26.       delay30();
    27.       P1=0x00;
    28.       delay150();
    29.    }
    30. }
    31.  
    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'?
     
  3. vivekbinwal_200

    Thread Starter New Member

    Jul 8, 2015
    3
    0
    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.
     
  4. vivekbinwal_200

    Thread Starter New Member

    Jul 8, 2015
    3
    0
    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();
    }
    }
     
  5. theonewho

    New Member

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

    Code (C):
    1. void delay150(void)
    2. {
    3. long i1;
    4. i1=15000000;
    5. while (i--); // <-- Forgot to update that one
    6. }

    Please enclose your pasted code in code tags.
     
Loading...