📄 vfd.c
字号:
/* Begin Function InterruptModuleSetup() */
RegBase->IVBR = 0xff; /* interrupt vector base address at $ff00 */
SetInterruptPriority(PIT0Ch, RQST + 0x07); /* PIT Channel 0, interrupt priority 7, handled by XGate */
SetInterruptPriority(TimerCh1Ch, RQST + 0x07); /* Timer Channel 0, interrupt priority 7, handled by XGate */
SetInterruptPriority(TimerCh0Ch, 0x02); /* Timer Channel 0, interrupt priority 2, handled by HC12 */
SetInterruptPriority(SPI0Ch, RQST + 0x03); /* SPI0, interrupt priority 7, handled by XGate */
SetInterruptPriority(SPI1Ch, RQST + 0x07); /* SPI1, interrupt priority 7, handled by XGate */
SetInterruptPriority(SPI2Ch, RQST + 0x07); /* SPI2, interrupt priority 7, handled by XGate */
SetInterruptPriority(PIT1Ch, RQST + 0x03); /* PIT Channel 1, interrupt priority 3, handled by XGate */
SetInterruptPriority(PIT2Ch, RQST + 0x02); /* PIT Channel 2, interrupt priority 2, handled by XGate */
SetInterruptPriority(PIT3Ch, 0x04); /* PIT Channel 3, interrupt priority 4, handled by HC12 */
SetInterruptPriority(CAN1RxCh, RQST + 0x06); /* CAN0 Rx, interrupt priority 6, handled by XGate */
SetInterruptPriority(XGSwTrig0Ch, RQST + 0x06);/* XGate SW trigger used for CAN2 transmit trigger, interrupt priority 6, handled by XGate */
SetInterruptPriority(XGSwTrig6Ch, RQST + 0x01);/* XGate SW trigger used for performance mesurement, interrupt priority 1, handled by XGate */
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;
}
}
/*************************************************************************************/
#ifdef __MWERKS__
void SetupXGATE(void);
#endif
void DoXGTransfer(void);
void main(void)
{
/* Variable Declarations */
uint x;
/* Begin Function main() */
InterruptModuleSetup();
#ifdef __MWERKS__
SetupXGATE();
#else
XGateSetup();
#endif
VFDSetup();
SPI0Setup();
SPI1Setup();
SPI2Setup();
TimerSetup();
GDICInit(); /* go initialize, calibrate & zero the 4 gauges */
PITSetup();
MSCANInit();
_asm("cli");
Calibrate();
EnableTimers();
PWMSetup();
while(1)
{
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 + -