?? dg128sci.c
字號:
/*-------------------------------------------------------
SCI Module
Donald
Apr 17, 2007
-------------------------------------------------------*/
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg128.h> /* derivative information */
#include "DG128SCI.h"
#include "MotorD.h"
void SciInit(void){
SCI0BDH = 0; // bus clock = 8M, SCI baud rate is 9600
SCI0BDL = 0x34; // SCI baud rate = SCI module clock / (16 * BR)
SCI0CR1_PE = 0; // Parity disabled
SCI0CR2_TE = 1; // Transmitter enabled
SCI0CR2_RE = 1; // Receiver enabled
SCI0CR2_RIE = 1; // Receive Interrupt enabled
}
void SciTx(unsigned char cTx){
unsigned char tmp;
tmp=SCI0SR1; // clear flag
while (!(SCI0SR1&0x80)); // wait for output buffer empty
SCI0DRH=0;
SCI0DRL=cTx;
}
char SciRx(void){
char result,tmp;
tmp=SCI0SR1; // clear flag
while(!(SCI0SR1&0x20));
result=SCI0DRL;
return result;
}
void PutStr(char* str){
char* pTmp;
pTmp = str;
while(*pTmp++ != '\0'){
SciTx(*pTmp);
}
}
interrupt void SciSrv(void){
unsigned char cDat;
DisableInterrupts;
cDat = SciRx();
/* // show what input
if (cDat == '\r'){
SciTx('\r');
SciTx('\n');
}else
SciTx(cDat);
*/
// Menu Function
SciTx(cDat);
SciTx('\r');
SciTx('\n');
switch (cDat){
case '1':
PORTB = 0x01 ^ 0xff;
break;
case '2':
PORTB = 0x02 ^ 0xff;
break;
case '3':
PORTB = 0x04 ^ 0xff;
break;
case '4':
PORTB = 0x08 ^ 0xff;
break;
case '5':
PORTB = 0x10 ^ 0xff;
break;
case '6':
PORTB = 0x20 ^ 0xff;
break;
case '7':
PORTB = 0x40 ^ 0xff;
break;
case '8':
PORTB = 0x80 ^ 0xff;
break;
case '+':
PORTB = PORTB ^ 0XFF;
break;
case '-':
PORTB = PORTB ^ 0XFF;
break;
default:
//PORTB = PORTB ^ 0XFF;
;
}
EnableInterrupts;
}
void Delay(void){
word i, j;
for (i = 0; i < 6; i++)
for(j = 0; j < 3000; j++);
}
void BinToHex(unsigned char cBin, char* cHexH, char* cHexL){
if((cBin & 0x0F) > 9){
*cHexL = (cBin & 0x0F) - 0x0a + 'A';
} else{
*cHexL = (cBin & 0x0F) + '0';
}
cBin >>= 4;
if ((cBin & 0x0F) > 9){
*cHexH = (cBin & 0x0F) - 0x0a + 'A';
} else{
*cHexH = (cBin & 0x0F) + '0';
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -