MC9S12G128 SCI设置

[objc]  view plain  copy
 print ?
  1. 以下代码SCI开启了接收中断。  
[objc]  view plain  copy
 print ?
  1. /*************************************************************/  
  2. /*                        初始化SCI                          */  
  3. /*************************************************************/  
  4. void INIT_SCI(void)   
  5. {  
  6.   SCI0BD = BUS_CLOCK/16/BAUD;   //设置SCI0波特率为9600 clock的宏定义根据自己的时钟,baud也根据需求定义  
  7.   SCI0CR1 = 0x00;        //设置SCI0为正常模式,八位数据位,无奇偶校验  
  8.   SCI0CR2 = 0x2c;        //允许接收和发送数据,允许接收中断功能   
  9. }  
[objc]  view plain  copy
 print ?
  1.   
[html]  view plain  copy
 print ?
  1. /*************************************************************/  
  2. /*                       串口发送函数                        */  
  3. /*************************************************************/  
  4. void SCI_send(unsigned char data)   
  5. {  
  6.   while(!SCI0SR1_TDRE);         //等待发送数据寄存器(缓冲器)为空  
  7.     SCI0DRL = data;  
  8. }  
[html]  view plain  copy
 print ?
  1. /*************************************************************/  
  2. /*                       串口接收函数                        */  
  3. /*************************************************************/  
  4. unsigned char SCI_receive(void)   
  5. {  
  6.   //while(!SCI0SR1_RDRF);          //等待发送数据寄存器满  
  7.   if(SCI0SR1_RDRF){  
  8.   return(SCI0DRL);  
  9.   }  
  10.   return -1;  
  11. }  
[html]  view plain  copy
 print ?
  1. 接收中断。  
[html]  view plain  copy
 print ?
  1. <pre name="code" class="html">#pragma CODE_SEG __NEAR_SEG NON_BANKED  
  2. void interrupt VectorNumber_Vsci0 receivedata(void)   
  3. {  
  4.   DisableInterrupts;  
  5.     data_receive = SCI_receive();  
  6.   EnableInterrupts;         
  7.   
  8. }  
  9. #pragma CODE_SEG DEFAULT  
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值