周工; 你好,我做了串口中断处理程序,我通过通过中断来发送数据,结果发送数据中断不响应,请帮忙看看是怎么回事,程序如下: //设置波特率 #include "config.h" #define UART0BPS 115200 #define BEEPCON 1 << 7
static uint8 readData; uint8* sentData; //设置引脚 void Pinsel0_Init() { PINSEL0 = 0x05; IO0DIR = BEEPCON; IO0SET = BEEPCON; } //初始化串口0 void Uart0_Init(void) { uint16 bps = (Fpclk / 16) / UART0BPS; U0LCR = 0x83; //设置DLAB = 1 U0DLL = bps % 256; //设置波特率余数 U0DLM = bps / 256; //设置波特率除数 U0FCR = 0x00; // U0LCR = 0X03; //设置DLAB = 0,1位停止位,无奇偶校验 字长度8 U0FCR = 0x00; //U0IER = 0x05; } //串口0中断程序 void __irq Uart0_IRQ(void) { uint8 iir; uint8 lsr; //IO0CLR = BEEPCON; while(((iir = U0IIR) & 0x01) == 0) //清除中断 iir = U0IIR; { switch(iir &0x0e) { case 0x06: //接收线状态 lsr = U0LSR; //清除中断 break; case 0x04: readData = U0RBR; //接收数据,同时清除中断 break; case 0x02: while(*sentData++ != '\0') U0THR = *sentData; //发送数据,同时清除中断 break; case 0x0a: //字符超时中断 break; } } VICVectAddr =0; //VIC控制器禁止中断 }
void Uart_INT() { VICIntSelect = 0x00000000; VICVectCntl5 = 0x26; VICVectAddr5 = (uint32)Uart0_IRQ; VICIntEnable = 0x00000040; } //读取数据 uint8 ReadData(void) { while((U0LSR & 0x01) == 0x00); U0IER = 0x01; return readData; }
int main (void) { uint8 test[23] = {"Hello,How old are you\n"}; //int num = 21; Pinsel0_Init(); Uart0_Init(); Uart_INT(); sentData = test; U0IER = 0x02; while(1); return 0; } /********************************************************************************************************* ** End Of File ********************************************************************************************************/
相关链接:https://bbs.21ic.com/upfiles/img/20079/200792623533657.rar |