使用delay函数能串口能接收到字符串。 但是,中断就悲剧了 想来很久,还是不知道原因在哪里。 求解。。。
#include <reg51.h> typedef unsigned char uint8; typedef unsigned int uint16;
uint16 cnt=0;
uint8 Buf[]="hello world!\r\n";
void delay(uint16 ms) { uint8 i; while(ms--) { for(i=0;i<120;i++); }
}
void UART_init(void) {
ES=1; EA=1;
SCON=0x50; TMOD=0x20; // TMOD=0x21; PCON=0x00;
// TH0=0xD8; //设置定时器0 // TL0=0xF0;
TH1=0xFA; //设置波特率 TL1=0xFA;
// TR0=1; TR1=1;
// ET0=1; ET1=0; }
void UART_send_byte(uint8 dat) { SBUF=dat; while(TI==0); TI=0; }
void UART_send_string(uint8 *buf) { while(*buf!='\0') { UART_send_byte(*buf++); } }
main() { UART_init(); while(1) { UART_send_string(Buf); delay(1000); } // while(1); } /* void timeint() interrupt 1 {
cnt++; TH0=0xD8; TL0=0xF0; if(cnt==200) { UART_send_string(Buf); cnt=0; }
} */
|