- 以下代码SCI开启了接收中断。
- /*************************************************************/
- /* 初始化SCI */
- /*************************************************************/
- void INIT_SCI(void)
- {
- SCI0BD = BUS_CLOCK/16/BAUD; //设置SCI0波特率为9600 clock的宏定义根据自己的时钟,baud也根据需求定义
- SCI0CR1 = 0x00; //设置SCI0为正常模式,八位数据位,无奇偶校验
- SCI0CR2 = 0x2c; //允许接收和发送数据,允许接收中断功能
- }
- /*************************************************************/
- /* 串口发送函数 */
- /*************************************************************/
- void SCI_send(unsigned char data)
- {
- while(!SCI0SR1_TDRE); //等待发送数据寄存器(缓冲器)为空
- SCI0DRL = data;
- }
- /*************************************************************/
- /* 串口接收函数 */
- /*************************************************************/
- unsigned char SCI_receive(void)
- {
- //while(!SCI0SR1_RDRF); //等待发送数据寄存器满
- if(SCI0SR1_RDRF){
- return(SCI0DRL);
- }
- return -1;
- }
- 接收中断。
- <pre name="code" class="html">#pragma CODE_SEG __NEAR_SEG NON_BANKED
- void interrupt VectorNumber_Vsci0 receivedata(void)
- {
- DisableInterrupts;
- data_receive = SCI_receive();
- EnableInterrupts;
- }
- #pragma CODE_SEG DEFAULT