大家好,本人学习单片机通讯,发送01点亮一个灯,再次发送熄灭。程序中不需要单片机发送数据给电脑,可是每次用串口调试助手发送01之后,就会都到6个数据,不知道为什么,请高手指点。晶振是11.0592,波特率9600,程序如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED0 = P1^0;
sbit LED1 = P1^1;
sbit LED2 = P1^2;
sbit LED3 = P1^3;
sbit LED4 = P1^4;
sbit LED5 = P1^5;
sbit LED6 = P1^6;
sbit LED7 = P1^7;
void Init_Uart(void)
{
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = 1;
SCON = 0x50;
PCON = 0;
EA = 1;
}
void main(void)
{
uchar i = 0;
Init_Uart();
while(1)
{
while(!RI);
RI = 0;
i = SBUF;
switch(i)
{
case 0x01: LED0 = ~LED0;break;
case 0x02: LED1 = ~LED1;break;
case 0x03: LED2 = ~LED2;break;
case 0x04: LED3 = ~LED3;break;
case 0x05: LED4 = ~LED4;break;
case 0x06: LED5 = ~LED5;break;
case 0x07: LED6 = ~LED6;break;
case 0x08: LED7 = ~LED7;break;
}
}
}
|