📄 main.c
字号:
//Demonstration of simple buffered SCI
#include <hidef.h> /* common defines and macros */
#include <mc9s12xdt512.h> /* derivative information */
#include "xgate.h"
#pragma LINK_INFO DERIVATIVE "mc9s12xdt512"
#include <string.h>
#include "xgate.h"
extern tBuffer Buffer0;
interrupt void SCI_ISR();
/************************* Macros ******************************************/
#define ROUTE_INTERRUPT(vec_adr, cfdata) \
INT_CFADDR= (vec_adr) & 0xF0; \
INT_CFDATA_ARR[((vec_adr) & 0x0F) >> 1]= (cfdata)
#define SCI0_VEC 0xD6 /* vector address= $xxD6 */
//Initialise the XGATE
static void SetupXGATE(void)
{
/* initialize the XGATE vector block and
set the XGVBR register to its start address */
XGVBR= (unsigned int)(void*__far)(XGATE_VectorTable - XGATE_VECTOR_OFFSET);
/* switch SCI0 interrupt to XGATE */
ROUTE_INTERRUPT(SCI0_VEC, 0x81); /* RQST=1 and PRIO=1 */
/* enable XGATE mode and interrupts */
XGMCTL= 0xFBC1; /* XGE | XGFRZ | XGIE */
}
void main(void)
{
/* put your own code here */
EnableInterrupts;
SetupXGATE();
//Initial first SCI Buffer
Buffer0.size = 4;
Buffer0.character[0]='1';
Buffer0.character[1]='2';
Buffer0.character[2]='3';
Buffer0.character[3]=' ';
//Configure baudrate = 19200 at 25MHz
SCI0BD = 53;
//Enable transmitter
SCI0CR2_TE = 1;
/* Enable the SCI Tx interrupt to start the transfer */
SCI0CR2_SCTIE = 1;
for(;;) {} /* wait forever */
/* please make sure that you never leave this function */
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
//CPU Interrupt generated by XGATE when SIMPLE is not defined - see xgate.cxgate file
interrupt void SCI_Handler()
{
unsigned char temp;
//Clear XGATE interrupt flag - SCI0 is channel $6B
XGIF1 = 0x0800;
//Initialise buffer with new values
Buffer0.size = 4;
temp = Buffer0.character[0];
Buffer0.character[0] = Buffer0.character[1];
Buffer0.character[1] = Buffer0.character[2];
Buffer0.character[2] = temp;
/* Enable the SCI Tx interrupt to start the transfer */
SCI0CR2_SCTIE = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -