[c]代码库
#include <REG52.H>
//sbit
sbit SEND = P3^1;
sbit RECIEVE = P3^0;
sbit SLED = P0^0;
sbit RLED = P0^1;
typedef unsigned char uchar;
typedef unsigned int uint;
//variable
uchar str[] = "Thanks,Sio\n";
uchar start[] = ":"
//declare
void UartInit(void);
void sendByte(uchar dat);
void Delay100ms(uint t);
void sendStr(uchar *str);
//main
int main(){
UartInit();
REN = 1;
while(1){
sendStr(str);
Delay100ms(10);
SLED = !SLED;
}
return 0;
}
//functions
void UartInit(void) //9600bps@11.0592MHz
{
//PCON &= 0x7F; //波特率不倍速
SCON = 0x50; //8位数据,可变波特率
//TMOD &= 0x0F; //清除定时器1模式位
TMOD |= 0x20; //设定定时器1为8位自动重装方式
TL1 = 0xfd; //设定定时初值
TH1 = 0xfd; //设定定时器重装值
ET1 = 0; //禁止定时器1中断
TR1 = 1; //启动定时器1
ES = 1;
EA = 1;
}
void sendByte(uchar dat){
SBUF = dat;
while(!TI);
}
void sendStr(uchar *str){
while(*str!='\0'){
sendByte(*str++);
}
}
void UART_is() interrupt 4{
if(RI){
RI = 0;
}
if(TI){
REN = 0;
TI = 0;
}
REN = 1;
}
void Delay100ms(uint t) //@11.0592MHz
{
unsigned char i, j;
uint x;
for(x=t;x>0;x--){
i = 180;
j = 73;
do
{
while (--j);
} while (--i);
}
}
by: 发表于:2017-08-08 11:14:57 顶(0) | 踩(0) 回复
??
回复评论