sci.c

来自「网上得到FREESCALE 9S12程序」· C语言 代码 · 共 68 行

C
68
字号
#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 + =
减小字号Ctrl + -
显示快捷键?