UART.h
#ifndef __UART_H__
#define __UART_H__void UART_Init();
void UART_SendByte(unsigned char Byte);#endif
UART.H
#include <REGX52.H>/*** @brief 串口初始化,4800bps@12.000MHz* @param 无* @retval 无*/
void UART_Init()
{SCON=0x40;PCON |= 0x80;TMOD &= 0x0F; //设置定时器模式TMOD |= 0x20; //设置定时器模式TL1 = 0xF3; //设定定时初值TH1 = 0xF3; //设定定时器重装值ET1 = 0; //禁止定时器1中断TR1 = 1; //启动定时器1
}/*** @brief 串口发送一个字节数据* @param Byte 要发送的一个字节数据* @retval 无*/
void UART_SendByte(unsigned char Byte)
{SBUF=Byte;while(TI==0);TI=0;
}
C
#include <REGX52.H>
#include "Delay.h"
#include "UART.h"unsigned char Sec;void main()
{UART_Init();while(1){UART_SendByte(Sec++);Delay(1000);}}