|
#include <STC8.H>
void delay(unsigned int x)
{
while(x--);
}
void main()
{
int x,k;
S3CON = 0x10; //8位數(shù)據(jù),可變波特率24k
S3CON &= 0xBF; //串口3選擇定時(shí)器2為波特率發(fā)生器
AUXR |= 0x04; //定時(shí)器時(shí)鐘1T模式
T2L = 0x8F; //設(shè)置定時(shí)初始值
T2H = 0xFD; //設(shè)置定時(shí)初始值
AUXR |= 0x10; //定時(shí)器2開(kāi)始計(jì)時(shí)
while(1)
{
// if(S3CON & 0x01)
// {
// x=S3BUF;
// delay(20000);
// S3CON &=0xfe;
// if(x==0x22)
// P0=0;else P0=0xff;//檢查P0的燈不對(duì)
//
// }
S3BUF=x;
while(!(S3CON & 0x01));
S3CON &=(0xff-0x01);
x=S3BUF; S3BUF=x;
delay(20000);
if(x==0x02)
P3=0;else P3=0xff;//檢查P3燈有沒(méi)有亮,正常
}
}
這個(gè)檢測(cè)寄存器,因?yàn)槭谴?用到P0口,寫完之后檢查也是用P0口,一直不對(duì),檢查換P3口就可以了
|
|