MC9S12G128 SCI设置

来源:互联网 发布:配音秀软件 编辑:程序博客网 时间:2024/05/18 02:02
[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  
原创粉丝点击