我用的是C8051F040的片子.部分程序略: 问题是:写了中断接受函数好用,但发送发送的就是乱码????????为什么啊!! 程序代码如下:
void UART0_Init (void) { char SFRPAGE_SAVE = SFRPAGE; SFRPAGE = UART0_PAGE; SCON0 = 0X50; SCON0 &= 0xFC; //清中断标志 SSTA0 = 0x10; //禁止UART0波特率2分频//SMOD0=1 IE = 0x90; //开UART1中断 SFRPAGE = TIMER01_PAGE; TMOD = 0x20; // TMOD: timer 1, mode 2, 8-bit reload CKCON = 0x10; //TIM=1
TH1 = 0x70; TL1 = TH1; // initialize Timer1 TR1 = 1; // start Timer1
SFRPAGE = UART0_PAGE; TI0 = 1; // Indicate TX1 ready SFRPAGE = CONFIG_PAGE; CTRL = 0; //485收发控制 SFRPAGE = SFRPAGE_SAVE; // Restore SFR page } //************************************************************* //****************发送函数************************************* //************************************************************* void SendUART0(uchar PP) //发送 { EA = 0;
SFRPAGE = CONFIG_PAGE; CTRL = 1; //485发送控制
SFRPAGE=UART0_PAGE; SBUF0=PP; while(TI0==0); TI0 = 0;
SFRPAGE = CONFIG_PAGE; CTRL = 0;
EA = 1;
}
void main (void) { UART0_Init ();EA = 1; SendUART0('A'); wait_ms(100);//} |