#include "12C5A60S2.h" #define uint8 unsigned char #define uint16 unsigned int uint8 num=0; void UartInit(void) //9600bps@11.0592MHz { AUXR &= 0xf7; //波特率不倍速 S2CON = 0x50; //8位數據,可變波特率 BRT = 0xFD; //設定獨立波特率發生器重裝值 AUXR &= 0xfb; //獨立波特率發生器時鐘為Fosc/12,即12T AUXR |= 0x10; //啟動獨立波特率發生器 EA=1; IE2=0x01; } void send(uint8 ch) {
IE2=0x00; S2CON&=~S2TI; S2BUF=ch; while(!(S2CON&S2TI)); S2CON &=~S2TI; IE2=0x01; }
void main() { UartInit(); while(1); } void Uart2() interrupt 8 { if(S2CON&S2RI) { S2CON&=~S2RI; num=S2BUF; send(num); } } |