Urgent!LOOKING coding error

Status
Not open for further replies.

Ni yanfang

Member level 3
Joined
Jul 30, 2013
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
432
hi, I will get error after i run my program. Kindly teach me how to edit. thank you so much.

Code:
#include<at89x51.h> // include at89x51 . h 
#define E P22
#define RW P21
#define RS P20
#define LCD_DATA P0

void strobe()
{
   E = 1;
   delay();
   E = 0;
   delay();
}

MYWORK6.C(9): error C202: 'P22': undefined identifier
 
Last edited by a moderator:

I suggest you reexamine the device specific header file, AT89X51.H, you will notice there are no P22, P21 or P20 identifiers/symbols defined within the header file.

Are you referring to PIN 2, PIN 1, PIN 0 of PORT2?

If so there are, P2_2, P2_1 and P2_0 defined and available.


Code:
#include <at89x51.h> // include at89x51 . h 
#define E [COLOR="#FF0000"]P2_2[/COLOR]
#define RW [COLOR="#FF0000"]P2_1[/COLOR]
#define RS [COLOR="#FF0000"]P2_0[/COLOR]
#define LCD_DATA P0

void strobe()
{
   E = 1;
   delay();
   E = 0;
   delay();
}

You need to reference the device specific header file when writing your code.
AT89X51.H
Code:
/*--------------------------------------------------------------------------
AT89X51.H

Header file for the low voltage Flash Atmel AT89C51 and AT89LV51.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/

#ifndef __AT89X51_H__
#define __AT89X51_H__

/*------------------------------------------------
Byte Registers
------------------------------------------------*/
[COLOR="#FF0000"]sfr P0      = 0x80;[/COLOR]
sfr SP      = 0x81;
sfr DPL     = 0x82;
sfr DPH     = 0x83;
sfr PCON    = 0x87;
sfr TCON    = 0x88;
sfr TMOD    = 0x89;
sfr TL0     = 0x8A;
sfr TL1     = 0x8B;
sfr TH0     = 0x8C;
sfr TH1     = 0x8D;
sfr P1      = 0x90;
sfr SCON    = 0x98;
sfr SBUF    = 0x99;
sfr P2      = 0xA0;
sfr IE      = 0xA8;
sfr P3      = 0xB0;
sfr IP      = 0xB8;
sfr PSW     = 0xD0;
sfr ACC     = 0xE0;
sfr B       = 0xF0;

/*------------------------------------------------
P0 Bit Registers
------------------------------------------------*/
sbit P0_0 = 0x80;
sbit P0_1 = 0x81;
sbit P0_2 = 0x82;
sbit P0_3 = 0x83;
sbit P0_4 = 0x84;
sbit P0_5 = 0x85;
sbit P0_6 = 0x86;
sbit P0_7 = 0x87;

/*------------------------------------------------
PCON Bit Values
------------------------------------------------*/
#define IDL_    0x01

#define STOP_   0x02
#define PD_     0x02    /* Alternate definition */

#define GF0_    0x04
#define GF1_    0x08

#define SMOD_   0x80

/*------------------------------------------------
TCON Bit Registers
------------------------------------------------*/
sbit IT0  = 0x88;
sbit IE0  = 0x89;
sbit IT1  = 0x8A;
sbit IE1  = 0x8B;
sbit TR0  = 0x8C;
sbit TF0  = 0x8D;
sbit TR1  = 0x8E;
sbit TF1  = 0x8F;

/*------------------------------------------------
TMOD Bit Values
------------------------------------------------*/
#define T0_M0_   0x01
#define T0_M1_   0x02
#define T0_CT_   0x04
#define T0_GATE_ 0x08
#define T1_M0_   0x10
#define T1_M1_   0x20
#define T1_CT_   0x40
#define T1_GATE_ 0x80

#define T1_MASK_ 0xF0
#define T0_MASK_ 0x0F

/*------------------------------------------------
P1 Bit Registers
------------------------------------------------*/
sbit P1_0 = 0x90;
sbit P1_1 = 0x91;
sbit P1_2 = 0x92;
sbit P1_3 = 0x93;
sbit P1_4 = 0x94;
sbit P1_5 = 0x95;
sbit P1_6 = 0x96;
sbit P1_7 = 0x97;

/*------------------------------------------------
SCON Bit Registers
------------------------------------------------*/
sbit RI   = 0x98;
sbit TI   = 0x99;
sbit RB8  = 0x9A;
sbit TB8  = 0x9B;
sbit REN  = 0x9C;
sbit SM2  = 0x9D;
sbit SM1  = 0x9E;
sbit SM0  = 0x9F;

/*------------------------------------------------
P2 Bit Registers
------------------------------------------------*/
[COLOR="#FF0000"]sbit P2_0 = 0xA0;[/COLOR]
[COLOR="#FF0000"]sbit P2_1 = 0xA1;[/COLOR]
[COLOR="#FF0000"]sbit P2_2 = 0xA2;[/COLOR]
sbit P2_3 = 0xA3;
sbit P2_4 = 0xA4;
sbit P2_5 = 0xA5;
sbit P2_6 = 0xA6;
sbit P2_7 = 0xA7;

/*------------------------------------------------
IE Bit Registers
------------------------------------------------*/
sbit EX0  = 0xA8;       /* 1=Enable External interrupt 0 */
sbit ET0  = 0xA9;       /* 1=Enable Timer 0 interrupt */
sbit EX1  = 0xAA;       /* 1=Enable External interrupt 1 */
sbit ET1  = 0xAB;       /* 1=Enable Timer 1 interrupt */
sbit ES   = 0xAC;       /* 1=Enable Serial port interrupt */
sbit ET2  = 0xAD;       /* 1=Enable Timer 2 interrupt */

sbit EA   = 0xAF;       /* 0=Disable all interrupts */

/*------------------------------------------------
P3 Bit Registers (Mnemonics & Ports)
------------------------------------------------*/
sbit P3_0 = 0xB0;
sbit P3_1 = 0xB1;
sbit P3_2 = 0xB2;
sbit P3_3 = 0xB3;
sbit P3_4 = 0xB4;
sbit P3_5 = 0xB5;
sbit P3_6 = 0xB6;
sbit P3_7 = 0xB7;

sbit RXD  = 0xB0;       /* Serial data input */
sbit TXD  = 0xB1;       /* Serial data output */
sbit INT0 = 0xB2;       /* External interrupt 0 */
sbit INT1 = 0xB3;       /* External interrupt 1 */
sbit T0   = 0xB4;       /* Timer 0 external input */
sbit T1   = 0xB5;       /* Timer 1 external input */
sbit WR   = 0xB6;       /* External data memory write strobe */
sbit RD   = 0xB7;       /* External data memory read strobe */

/*------------------------------------------------
IP Bit Registers
------------------------------------------------*/
sbit PX0  = 0xB8;
sbit PT0  = 0xB9;
sbit PX1  = 0xBA;
sbit PT1  = 0xBB;
sbit PS   = 0xBC;
sbit PT2  = 0xBD;

/*------------------------------------------------
PSW Bit Registers
------------------------------------------------*/
sbit P    = 0xD0;
sbit F1   = 0xD1;
sbit OV   = 0xD2;
sbit RS0  = 0xD3;
sbit RS1  = 0xD4;
sbit F0   = 0xD5;
sbit AC   = 0xD6;
sbit CY   = 0xD7;

/*------------------------------------------------
Interrupt Vectors:
Interrupt Address = (Number * 8) + 3
------------------------------------------------*/
#define IE0_VECTOR	0  /* 0x03 External Interrupt 0 */
#define TF0_VECTOR	1  /* 0x0B Timer 0 */
#define IE1_VECTOR	2  /* 0x13 External Interrupt 1 */
#define TF1_VECTOR	3  /* 0x1B Timer 1 */
#define SIO_VECTOR	4  /* 0x23 Serial port */

#endif

BigDog
 
Greetings,
As suggested by bigdogguru, to define port pins use Px^y where x is number of port and y is port pin number.
#define E P2^2
OR you can use
#sbit E = P2^2;

Good Luck
 
Greetings,
As suggested by bigdogguru, to define port pins use Px^y where x is number of port and y is port pin number.
#define E P2^2
OR you can use
#sbit E = P2^2;

Good Luck
Ok thank you
 

Urgent.hi does anyone know about "delay"

this is my code. after run my program. But got error. Kindly check for me. Thank you.

Code:
#include<at89x51.h> // include at89x51 . h 
#define E P2_2
#define RW P2_1
#define RS P2_0
#define LCD_DATA P0
void delay ();
void strobe()
{
   E = 1;
   delay (150);
   E = 0;
   delay (150);
}

MYWORK9.C(10): error C267: 'delay': requires ANSI-style prototype

Use CODE or SYNTAX Tags When Posting Your Code
 
Last edited by a moderator:

You must provide the delay() function/routine either in the main source code file or an additional source code file with an accompanying header file containing the function/routine prototype.

Unfortunately, the KEIL C51 Compiler does not provide any software delay routines, therefore you will need to write your own.

BigDog
 
Post your full code here and do use code syntax.
This is my full code. kindly check for me. thanks.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#define RS P2_0
#define LCD_DATA P0
void delay();
void strobe()
{
  
   E = 1;
   delay (150);
   E = 0;
   delay (150);
  }
 
void data_write(unsigned char X)
{
    LCD_DATA= X;
    RS=1;
    RW=0;
    strobe();
}
void control_write(unsigned char X )
{
  LCD_DATA=X;
    RS=0;
    RW=0;
    strobe();
}
void main()
{
  initialise_lcd();
  control_write(0*01);
  data_write(0*48);
  data_write(0*49);
  for(;;);
}



MYWORK9.C(11): error C267: 'delay': requires ANSI-style prototype
 
Last edited by a moderator:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#define RS P2_0
#define LCD_DATA P0
void delay(int x)
{
int a,b;
for( a = 0; a < x; a++)
for( b = 0; b < 50; b++);
}
void strobe()
{
 
E = 1;
delay (150);
E = 0;
delay (150);
}
 
void data_write(unsigned char X)
{
LCD_DATA= X;
RS=1;
RW=0;
strobe();
}
void control_write(unsigned char X )
{
LCD_DATA=X;
RS=0;
RW=0;
strobe();
}
void main()
{
initialise_lcd();
control_write(0*01);
data_write(0*48);
data_write(0*49);
for(;;);
}



- - - Updated - - -

you didnt defined the function delay as well as the parameter should be int....
 

Greetings,
First things First, Use Code tags for posting codes. Select # from tool pane then write code in between code tags.

Missing statements/Functions are:
#include <at89x51.h> // include at89x51 . h
#define E P2^2
#define RW P2^1


Missing Functions:
1. intialise_lcd();
2. delay()

Here is an example of your missing Function(delay):
Code:
void delay(unsigned int t)
 {
  unsigned int i,j;
  for(i=0;i<t;i++)
   {
    for(j=0;j<50;j++)
       {}
   }
 }

For lcd initialization you can use:
Code:
void initialise_lcd()
{
 control_write(0X38);
 delay(1);
 control_write(0X0E);
 delay(1);
 control_write(0X01);
 delay(1);
 control_write(0X06);
 delay(1);
 control_write(0X80);
 delay(1);
 data_write('T');
 delay(1);
}

And it is better if you use ready function:
Code:
void lcdready()
 {
  busy = 1;
  RS = 0;
  RW = 1;
  while(busy==1)
  {
   strobe();
  }
  return;
 }
Code:
Code:
#include <at89x51.h> // include at89x51.h or use #include <reg52.h>
#define LCD_DATA P0
sbit E = P2^2;
sbit RW = P2^1;
sbit RS = P2^0;
sbit busy = P0^7;
void lcdready();
void initialize_lcd();
void delay(unsigned int t);
void delay();
void strobe()
{
E = 1;
delay (150);
E = 0;
}

void data_write(unsigned char X)
{
LCD_DATA= X;
RS=1;
RW=0;
strobe();
}
void control_write(unsigned char X )
{
LCD_DATA=X;
RS=0;
RW=0;
strobe();
}
void main()
{
initialize_lcd();                       // LCD initialization
while(1)
{
control_write(0x01);               // To send clear command to lcd or to clear lcd screen
data_write(0x48);          
data_write(0x49);
data_write('T');                    // Display T on lcd
 delay(1);
}
}
void initialise_lcd()
{
 control_write(0x38);               // For 2 Line and 5x7 matrix
 delay(1);
 control_write(0x0E);               // Display on, cursor Blink
 delay(1);
 control_write(0x01);               // Clear display screen
 delay(1);
 control_write(0x06);              // increment cursor(shift cursor to right)
 delay(1);
 control_write(0x80);             // Force cursor to begging of 1st Line or Use 0xc0 to begin from 2nd line
 delay(1);
}
void lcdready()
 {
  busy = 1;
  RS = 0;
  RW = 1;
  while(busy==1)
  {
   strobe();
  }
  return;
 }
void delay(unsigned int t)
 {
  unsigned int i,j;
  for(i=0;i<t;i++)
   {
    for(j=0;j<50;j++)
       {}
   }
 }

Note:- Always Use pull-up resistors on port P0.

Good Luck
 
Last edited:

OK. Thanks.
 

I thought I should mention caution should be taken when implementing software delay routines with C loop structures.

Code:
void delay(unsigned int t)
 {
  unsigned int i,j;
  for(i=0;i<t;i++)
   {
    for(j=0;j<50;j++)
       {}
   }
 }

Although, they can perform the task in many cases, their lack of accuracy and precision coupled with compiler optimization issues as well as differences in compiler versions can be a source of frustration and are therefore the less than optimal solution.

Typically, software delays are written in assembly language as routines which can be called by the main C code.

The following discussion concerns the implementation of software delay routines in KEIL C Compilers.

KEIL Delay routine problem

**broken link removed**


BigDog
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…