呵呵,我的程序完成了,谢谢各位
程序如下:
#include <reg52.h>
#include <string.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define BUF_LEN 50
sbit dula = P2 ^ 6;
sbit wela = P2 ^ 7;
uchar inbuf[BUF_LEN];
uchar innbuf[] = "strong";
uchar flag, count = 0 ,clean;
void init();
void main()
{
for(clean=0; clean < BUF_LEN; clean++ )
inbuf[clean] = '\0';
init();
while (1)
{
if (flag == 1)
{
flag = 0;
if(strcmp(inbuf,"openled1")==0)
{
P1 = 0XFE; ES = 0;TI = 1; printf("led1 on ok\n"); TI = 0; ES = 1;
}
else if(strcmp(inbuf,"openled2")==0)
{
P1 = 0XFD; ES = 0;TI = 1; printf("led2 on ok\n"); TI = 0; ES = 1;
}
else if(strcmp(inbuf,"openled3")==0)
{
P1 = 0XFB; ES = 0;TI = 1; printf("led3 on ok\n"); TI = 0; ES = 1;
}
else if(strcmp(inbuf,"openled4")==0)
{
P1 = 0XF7; ES = 0;TI = 1; printf("led4 on ok\n"); TI = 0; ES = 1;
}
else if(strcmp(inbuf,"openled5")==0)
{
P1 = 0XEF; ES = 0;TI = 1; printf("led5 on ok\n"); TI = 0; ES = 1;
}
else if(strcmp(inbuf,"openled6")==0)
{
P1 = 0XDF; ES = 0;TI = 1; printf("led6 on ok\n"); TI = 0; ES = 1;
}
else
{
P1 = 0X00; ES = 0;TI = 1; printf("%s,ERROR\n",inbuf); TI = 0; ES = 1;
}
for(clean=0; clean < BUF_LEN; clean++ )
inbuf[clean] = '\0';
}
}
}
void init()
{
TMOD = 0x20;
TH1 = 0xfd;
TL1 = 0xfd;
SCON = 0X50;
TR1 = 1;
ES = 1;
EA = 1;
}
void ser() interrupt 4
{
uchar ch;
if (RI)
{
RI = 0;
count++;
ch = SBUF;
inbuf[count - 1] = ch;
if (ch == '\#')
{
inbuf[count-1]= '\0';
count = 0;
flag = 1;
}
}
} |