#include <reg51.h>
sbit k1=P1^0;
int i=0;
unsigned char Data[7]= {0X7E,0X05,0X44,0X00,0X01,0X40,0XEF};
void delay20ms(void)
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=222;b>0;b--)
for(a=40;a>0;a--);
}
void uart_Init()
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD;
TL1 = TH1;
PCON = 0x00;
EA = 1;
ES = 1;
TR1 = 1;
}
void data_send_uart()
{
for(i=0; i<7; i++)
{
SBUF = Data[i];
while(!TI);
TI = 0;
}
}
void main()
{
uart_Init();
delay20ms();
if(k1==0)
{data_send_uart();}
}
串口调试时,按下按键后,无法发送整个数组,串口调试助手显示结果如下:
将if(k1==0)删了后,串口调试如下