?? sci.c
字號:
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
/*-------串口初始化----------------------*/
void SciInit()
{
SCI0BDL = (unsigned char)((16000000UL /* OSC freq */ / 2) / 9600 /* baud rate */ / 16 /*factor*/);
SCI0CR1=0; /*normal,no parity*/
SCI0CR2=0X2C; /*RIE=1,TE=1,RE=1*/
}
/*-------發(fā)射端程序----------------------*/
void SciTx(unsigned char text)
{
unsigned char temp;
temp=SCI0SR1; /*clear flag*/
while (!(SCI0SR1&0x80)); /* wait for output buffer empty */
SCI0DRH=0;
SCI0DRL=text;
}
/*-------接受端程序----------------------*/
char SciRx(void)
{
char result,temp;
temp=SCI0SR1; /*clear flag*/
while(!(SCI0SR1&0x20));
result=SCI0DRL;
return result;
}
/*--------中斷程序-----------------------*/
void interrupt 20 Serv_int(void)
{
unsigned char data;
DisableInterrupts;
data=SciRx();
SciTx(data);
light();
EnableInterrupts;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -