📄 main.c
字号:
/* Variable Declarations */
/* Begin Function SPI0Setup() */
RegBase->SPI0.BR = 0x42; /* setup for a 1 MHz SPI bus */
RegBase->SPI0.CR1 = 0x54; /* SPE = 1; MSTR = 1; CPOL = 0; CPHA = 1 */
} /* end SPI0Setup */
/*************************************************************************************/
static void SPI2Setup(void)
{
/* Variable Declarations */
/* Begin Function SPI2Setup() */
RegBase->SPI2.BR = 0x42; /* setup for a 1 MHz SPI bus */
RegBase->SPI2.CR1 = 0x5d; /* SPE = 1; MSTR = 1; CPOL = 1; CPHA = 1; LSBFE = 1 */
} /* end SPI2Setup */
/*************************************************************************************/
static void PITSetup(void)
{
/* Variable Declarations */
/* Begin Function PITSetup() */
RegBase->PITMUX = 0x0E; /* select micro timer 0 as the source for PIT channel 0 & micro timer 1 as the source for PIT channel 1, 2 & 3 */
RegBase->PITMTLD0 = 0; /* use a /1 for micro timer 0 */
RegBase->PITMTLD1 = 200; /* use a /200 for micro timer 1 */
RegBase->PITLD0 = 6248; /* sets up a period of 1/(40000000/100/64); refresh rate of 100 Hz for 64 grids => 156 uS */
RegBase->PITLD1 = 5000; /* 25 mS period for GDIC */
RegBase->PITLD2 = 5000; /* 25 mS period for switch debounce */
RegBase->PITLD3 = 20000; /* 100 mS period for performance calculator */
RegBase->PITINTE = 0x0F; /* enable interrupts on PIT channel 0, 1, 2 & 4 */
RegBase->PITCFLMT = 0xA0; /* enable the PIT timer module, freeze in BDM */
} /* end PITSetup */
/*************************************************************************************/
static void InterruptModuleSetup(void)
{
/* Variable Declarations */
/* Begin Function InterruptModuleSetup() */
RegBase->IVBR = 0xff; /* interrupt vector base address at $ff00 */
S12X_SetInterruptPriority(RTICh, 0x07); /* RTI Channel , interrupt priority 7, handled by HC12,ABS control */
S12X_SetInterruptPriority(PORTJCh, 0x07); /* PJ0, interrupt priority 7, handled by HC12,brake signal processing */
// S12X_SetInterruptPriority(TimerCh0Ch, 0x02); /* Timer Channel 0, interrupt priority 2, handled by HC12 */
// S12X_SetInterruptPriority(SPI0Ch, RQST + 0x03); /* SPI0, interrupt priority 7, handled by XGate */
// S12X_SetInterruptPriority(SPI1Ch, RQST + 0x07); /* SPI1, interrupt priority 7, handled by XGate */
// S12X_SetInterruptPriority(SPI2Ch, RQST + 0x07); /* SPI2, interrupt priority 7, handled by XGate */
// S12X_SetInterruptPriority(PIT1Ch, RQST + 0x03); /* PIT Channel 1, interrupt priority 3, handled by XGate */
// S12X_SetInterruptPriority(PIT2Ch, RQST + 0x02); /* PIT Channel 2, interrupt priority 2, handled by XGate */
// S12X_SetInterruptPriority(PIT3Ch, 0x04); /* PIT Channel 3, interrupt priority 4, handled by HC12 */
// S12X_SetInterruptPriority(CAN1RxCh, RQST + 0x06); /* CAN0 Rx, interrupt priority 6, handled by XGate */
// S12X_SetInterruptPriority(XGSwTrig0Ch, RQST + 0x06);/* XGate SW trigger used for CAN2 transmit trigger, interrupt priority 6, handled by XGate */
// S12X_SetInterruptPriority(XGSwTrig6Ch, RQST + 0x01);/* XGate SW trigger used for performance mesurement, interrupt priority 1, handled by XGate */
// S12X_SetInterruptPriority(XGSwTrig7Ch, RQST + 0x01);/* XGate SW trigger used for performance mesurement, interrupt priority 1, handled by XGate */
} /* end InterruptModuleSetup */
/*************************************************************************************/
static void EnableTimers(void)
{
RegBase->PITCE = 0x01; /* enable PIT channel 0 to start the display */
RegBase->PITCE |= 0x02; /* enable PIT channel 1 to sweep the gauges */
RegBase->PITCE |= 0x04; /* enable PIT channel 2 to read the switches */
RegBase->PITCE |= 0x08; /* enable PIT channel 3 to start performance calculation */
RegBase->TC0 = RegBase->TCNT + 50000; /* set up a 10 mS delay on TC1 */
RegBase->TIE |= 0x01; /* enable TC0 interrupts */
// RegBase->XGSWT = 0x0101; /* initiate a CAN message transmit */
RegBase->XGSWT = 0x8080; /* start XG idle task */
} /* EnableTimers */
/*************************************************************************************/
static void uSDelay5(void) // delay by 5 uS
{
#asm // 4 (JSR)
ldx #164 // 2
XLoop: dbne x,XLoop // 3 * x
#endasm
} /* end uSDelay */ // 5 (RTS)
extern uint HC12IdleCounter;
int tickCounter;
void WaitTick(int ticks)
{
tickCounter = ticks;
while (tickCounter > 0) {
HC12IdleCounter++;
uSDelay5();
}
}
void WaitTrue(int *condition)
{
while (*condition) {
HC12IdleCounter++;
uSDelay5();
}
}
/*************************************************************************************/
static long FullIdleCount = 0;
static uint HC12FullIdleCount = 0;
extern long XGIdleCount;
extern uint HC12IdleCount;
static void Calibrate(void)
{
CalibrationPhase = 1;
RegBase->XGSWT = 0x8080; /* start XG idle task */
RegBase->PITCE = 0x04; /* enable PIT channel 2 to read the switches */
RegBase->PITCE |= 0x08; /* enable PIT channel 3 to read the switches & do performance snapshots */
RegBase->TC0 = RegBase->TCNT + 50000; /* set up a 10 mS delay on TC1 */
RegBase->TIE |= 0x01; /* enable TC0 interrupts */
WaitTick(20); /* delay for 200ms to calibrate the idle counters */
FullIdleCount = XGIdleCount;
HC12FullIdleCount = HC12IdleCount;
RegBase->PITCE = 0x00; /* disenable all PIT channels */
RegBase->TIE = 0x00; /* disenable all TC interrupts */
maxDt = 0;
CalibrationPhase = 0;
}
/*************************************************************************************/
void On_ButtonDown(uchar buttons)
{
static uchar DemoMode = 0;
if (buttons & 0x40) {
DemoMode = (DemoMode + 1) % 2;
switch (DemoMode) {
case 0:
CarSimulation = 0;
break;
case 1:
CarSimulation = 1;
break;
}
}
if (buttons & 0x80) { /* SW10 */
BMPTfrByXG ^= 1;
}
}
/*************************************************************************************/
void DoXGTransfer(void);
void main(void)
{
/* Variable Declarations */
uint x;
/* Begin Function main() */
InterruptModuleSetup();
S12X_SetupXGATE();
VFDSetup();
SPI0Setup();
SPI1Setup();
SPI2Setup();
TimerSetup();
GDICInit(); /* go initialize, calibrate & zero the 4 gauges */
PITSetup();
MSCANInit();
_asm("cli");
Calibrate();
EnableTimers();
PWMSetup();
for (;;) {
GSlideDown(FreescaleLogo, GBuffer);
WaitTick(200);
GSlideRight(Sixteen, GBuffer);
WaitTick(200);
GSlideDown(S12X, GBuffer);
WaitTick(200);
GBarnDoorOpen(WithXGate,GBuffer);
for (x = 0; x < 12; x++) {
WaitTick(10);
GInvert(GBuffer);
}
WaitTick(150);
GBarnDoorOpen(CodeWarrior,GBuffer);
WaitTick(200);
ClearGBuff(GBuffer);
WaitTick(100);
}
} /* end main */
/*************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -