#define uchar unsigned char /* defines the data type uchar as unsigned char */
#define unit unsigned int /* defines the data type uint as an unsigned integer */
Void delay 1ms(uint t) /* declares and implements a function named dedelay1ms1ms with uint as the parameter and void*/
{
uint i,j; /* Declare two variables of type I and T */
for(I = 0; I & ltt;; I++) /* According to the input parameter t, determine the number of times of loop execution */
for(j = 0; j & lt 120; j++); /* Execute 120 null code to realize delay function */
}
Void main() /*main function is a program entry function, which will automatically execute */
{
Uchar key, symbol; /* Define two parameters key and uchar */
P2 = 0x0f; /*? P2 from here and there, estimated in the referenced header file? Don't know much about the referenced header file? */
flag = 0; /* Assign flag value 0*/
At the same time (1) /* Perform this loop wirelessly */
{
key = P2; /* Assign the/* key to the value of P2 *//* Not responsible for guessing */
Key = Key & 0x0f/* Sum the value of key and 0x0f bitwise, and assign the result to key, which actually clears the upper 4 bits and keeps the lower 4 bits */
If (key! =0x0f) /* If the key is not 0x0f */
{
delay 1 ms( 10); /* Delay 10MS, but there is a problem. There seems to be a bracket mismatch */
key = P2; The/* key is assigned to the value of P2 */
Key = Key & 0x0f/* Sum the value of key and 0x0f bitwise, and assign the result to key, which actually clears the upper 4 bits and keeps the lower 4 bits */
If(key==0x0f) /* If the value of key equals 0X0f*/
flag = 0; The/* flag is assigned to 0*/
Else /* If the value of key is not equal to 0x0f*/
{
Switch(key) /* Judge the value of key */
{
case 0x0e:flag = 1; Break; /* If 0x0e, the flag is assigned to 1*/
Case 0x0d:flag = 2;; Break; /* If 0x0d, the flag will be assigned to 2*/
Case 0x0b:flag = 3;; Break; /* If it is 0x0b, the flag is assigned to 3*/
Case 0x07: Flag = 4; Break; /* If it is 0x07, the flag is assigned to 4*/
/* There is no grammatical problem with this writing, but it is generally best to have a default process */
}
}
}
if(flag = = 1){ p 1 = 0x ff; delay 1 ms(500); p 1 = 0x 00; delay 1 ms(500); }/* If the flag is 1, assign P 1 to 0xff, and after a delay of 500ms, assign p 1 to 0x00, and then delay for 500 ms */
if(flag = = 2){ p 1 = 0x aa; delay 1 ms(300); p 1 = 0x 55; delay 1 ms(300); }/* If the flag is 2, assign P 1 to 0xaa, then assign p 1 to 0x55 after a delay of 300ms, and then delay for 300 ms..
if(flag = = 3){ p 1 = 0x0f; delay 1 ms(200); p 1 = 0xf 0; delay 1 ms(200); }/* If the flag is 3, assign P 1 to 0x0f, and then assign p 1 to 0xf0 after a delay of 200ms, and delay it for 500 ms */
if(flag = = 4){ p 1 = 0x ff; }/* If the flag is 4, assign P 1 to 0xff*/
if(flag = = 0){ p 1 = 0x ff; }/* If the flag is 0, assign P 1 to 0xff*/
}
/* The code had better be in a regular format, otherwise it will look very tired */
/* This program modifies the value of P 1 according to the value obtained by P2. It is speculated that if the value of P2 is dynamically modified and the value of P 1 is modified, the impact should be in the included header file */
}