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