# include & ltSTC89。H & gt
無符號字符tmp
sbit shebei1=p1^0;//定義控制設備的IO端口。
sbit shebei2=p1^1;
sbit shebei3=p1^2;
sbit shebei4=p1^3;
sbit shebei5=p1^4;
sbit shebei6=p1^5;
void main()
{
TMOD = 0x 20;//定時器1工作在8位自動重載模式下產生波特率。
th 1 = 0x FD;//波特率9600
TL 1 = 0x FD;
SCON = 0x 50;//設置串口的工作模式
PCON & amp;= 0xef//波特率不相乘
tr 1 = 1;//啟動計時器1
IE = 0x0//禁用任何中斷。
while(1)
{
if(ri)//有數據來了嗎?
{
RI = 0;//清除接收標記
tmp = SBUF//臨時存儲接收到的數據。
開關(tmp)
{
case 0x 22:shebei 1 = 0;打破;//關閉設備1
case 0x 33:shebei 1 = 1;打破;//打開設備1
案例0x 44:shebei 2 = 0;打破;
case 0x 55:shebei 2 = 1;打破;
案例0x 66:shebei 3 = 0;打破;
case 0x 77:shebei 3 = 1;打破;
案例0x 88:shebei 4 = 0;打破;
case 0x 99:shebei 4 = 1;打破;
//case 0x aa:shebei 5 = 0;打破;
//case 0x bb:shebei 5 = 1;打破;
//case 0x cc:shebei 6 = 0;打破;
//case 0x DD:shebei 6 = 1;打破;
案例0x 17:shebei 5 = 0;打破;
case 0x 18:shebei 5 = 1;打破;
案例0x 19:shebei 6 = 0;打破;
case 0x 20:shebei 6 = 1;打破;
}
}
}
}
void延遲符號(無符號字符毫秒)
//延遲子程序
{
無符號字符I;
當(毫秒)
{
for(I = 0;我& lt120;i++);
}
}