📄 sci.c
字号:
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#include"sci.h"
/*-------串口初始化----------------------*/
void SciInit()
{
SCI0BDL = (unsigned char)((48000000UL /* OSC freq */ / 2) / 9600 /* baud rate */ / 16 /*factor*/);
SCI0CR1=0; /*normal,no parity*/
SCI0CR2=0X2C; /*RIE=1,TE=1,RE=1*/
}
/*-------发射端程序----------------------*/
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);
SciTx('\r');
SciTx('\n');
switch(data)
{
case '+':
PWMDTY1+=5;
break;
case '-':
PWMDTY1-=5;
break;
case '0':
PWMDTY1=0;
PWMDTY0=0;
break;
case '1':
PWMDTY0=99;
PWMDTY1=0;
break;
case '2':
PWMDTY0=0;
PWMDTY1=99;
break;
default:
break;
}
// light();
EnableInterrupts;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -