#include<reg51.h>
#include"DelayTime.h"
#include"Led.h"
#include"Buzzer.h"
#include"LowPower.h"
#include"UART.h"
#define unsigned char usendnumber;
//******************主函数********************
unsigned char uSendData;
main()
{
Uart_initial();
usendnumber = 0x00;
while(1)
{
if(usendnumber<2)
{
uSendData = 0x27;
Uart_send(uSendData);
DelayTimeNms(50);
}
}
}
#include<reg52.h>
#define uchar unsigned char
//***************串口程序****************************//
sfr AUXR = 0x8e;
sfr BRT = 0x9c;
#define RELOAD_COUNT 0xFD //11.0592MHz,12T,SMOD=0,9600bps
void Uart_initial()
{
SCON = 0x50; //0101,0000 方式1:8位可变波特率
PCON = 0X00; //设置SMOD=0 波特率不加倍
TMOD = 0x21; //0011,0001 设置定时器1为8位自动重装计数器
TH1 = RELOAD_COUNT; //设置定时器1自动重装数
TL1 = RELOAD_COUNT;
TR1 = 1; //开定时器1
AUXR = 0X00; //不允许独立波特率发生器运行,用定时器1做波特率发生器
ES = 1; //允许串口中断
EA = 1; //开总中断
}
//*********************串口发送***************
uchar usendnumber = 0x00; //控制发送值的次数
void Uart_send (unsigned char uData)
{
//EA = 0;
ES = 0; //关串口中断
TI = 0; //清零串口发送完成中断请求标志
//SBUF = Sendword;
SBUF = uData; //发送值
while(TI==0) //等待发送
{
;
}
usendnumber++;
TI = 0; //清零串口发送完成中断请求标志
ES = 1; //允许串口中断
} |