相关代码:
#include “STC15F2K60S2.H”
unsigned char command = 0x00;
void SendByte(unsigned char dat)
{
SBUF = dat;
while(TI == 0);
TI = 0;
}
void Sendstring(unsigned char *str)
{
while(*str != ‘\0’)
{
SendByte(*str++);
}
}
void Working()
{
if(command != 0x00)
{
switch(command & 0xf0)
{
case 0xa0:
P0 = (P0 | 0x0f) & (~command | 0xf0);
command = 0x00;
break;
case 0xb0 :
P0 = (P0 | 0xf0) & (~command << 4 | 0x0f);
command = 0x00;
break;
case 0xc0:
Sendstring(“The system is working…\r\n”);
command = 0x00;
}
}
}
void Working()
{
P0 = ~(command);//输入可以使0x10之类
}
void main()
{
TMOD = 0x20;
TH1 = 0xfd;
TL1 = 0xfd;
TR1 = 1;
SCON = 0x50;
AUXR = 0x00;
ES = 1;
EA = 1;
P2 = P2 & 0x1f | 0x80;
P0 = 0xff;
Sendstring("hello, welcome...\r\n");
while(1)
{
Working();
}
}
void TNT0() interrupt 4
{
if(RI == 1)
{
RI = 0;
command = SBUF;
}
}