The source code is as follows:
Include <reg51.h>
# Include <string. h>
Void main ()
{
Unsigned char tab [] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f}; // segment code table
Void display (unsigned char I );
Void delay (unsigned char I );
Ie = 0x81;
Scon = 0x00;
Tcon = 0x00;
Tmod = 0x10;
While (1)
{
P0 = 0x9e;
P1 = 0xf7; // the red light on the east and west, and the green light on the north and south
Display (55 );
P0 = 0xae;
P1 = 0xfb; // red light on east/west, yellow light on north and south
Display (5 );
P0 = 0xf3;
P1 = 0xfc; // the green light on the east and west, and the red light on the north and south
Display (55 );
P0 = 0x75;
P1 = 0xfd; // yellow light on East and West, red light on north and south
Display (5 );
}
}
Void inter0 (void) interrupt 0
{
P0 = 0xb6;
P1 = 0xfd; // the red light is on both the east and west sides
Display (30 );
}
Void display (unsigned char I)
{
While (I! = 0)
{
Unsigned char J, K;
J = I % 10;
Sbuf = tab [J];
While (Ti! = 1 );
Ti = 0;
K = I/10;
Sbuf = tab [k];
While (Ti! = 1 );
Ti = 0;
Delay (20 );
I --;
}
}
Void delay (unsigned char I)
{
Tr1 = 1;
While (I! = 0)
{
Th1 = 0x9e;
TL1 = 0x58;
While (TF1! = 1 );
TF1 = 0;
I --;
}
Tr1 = 0;
}
After compilation, an error occurs: 'tab': Undefined identifier. What is the problem? I don't know much about C language. Thank you for your understanding!