⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vfd.c

📁 关于XD256的应用实例,用于汽车电子开发之用
💻 C
📖 第 1 页 / 共 4 页
字号:
 RegBase->PWMDTY7 = 100;
 
 RegBase->PWME = 0xf0;				/* enable PWM Ch. 0 - 7 */
 
}	/* end PWMSetup */

/*************************************************************************************/

static void TimerSetup(void)

 {
  
 /* Variable Declarations */

 
 /* Begin Function TimerSetup() */
 
 RegBase->TIOS = 0x03;		/* configure TC0 & TC1 as an output compare */
 RegBase->TSCR1 = 0xB0;		/* enable timer, freeze in BDM, fast flag clearing */
 
 RegBase->TSCR2 = 0x03;		/* prescaler :8 -> one tick is 200nS */
 
}	/* end TimerSetup */

/*************************************************************************************/

static void VFDSetup(void)

 {
  
 /* Variable Declarations */

 
 /* Begin Function VFDSetup() */
 
 RegBase->PORTT = 0x02;     /* initial value of BLK1 = 0, BLK2 = 1, LAT1/2/GLAT = 0, GBLK = 0 */
 RegBase->DDRT = 0x0f;      /* PortT pins 0 - 3 are outputs to the VF display */
 
 RegBase->PORTB |= 0x03;    /* PB0 = 1 (off, controls VFD 5V switcher), PB1 = 1 (off, controls VFD 55V switcher), PB2 = 0 (off, controls VFD filament supply)  */
 RegBase->DDRB |= 0x07;     /* make all 3 pins outputs */

 RegBase->PORTT |= 0xf0;    /* GDIC reset lines & chip selects initially at 1 */
 RegBase->DDRT |= 0xf0;     /* make PT4 - PT7 outputs */

 GridData[7] = 0x01;        /* initial VFD grid data is 0x8000000000000001 */
 GridData[0] = 0x80; 

 RegBase->MODRR = 0x60;     /* route SPI1 & SPI2 to PortH */

 RegBase->PORTB &= ~0x01;   /* turn on switched 5V supply */
 Delay_mSec(100);           /* wait 100 mS for switched 5V to ramp up */
 RegBase->PORTB |= 0x04;    /* turn on VFD filament supply */
 Delay_mSec(300);           /* wait 300 mS for filament supply to ramp up */
 RegBase->PORTB &= ~0x02;   /* turn on VFD HV supply */
 Delay_mSec(300);           /* wait 300 mS for HV supply to ramp up */

 SwLEDData.CurState = 0x00; /* assume no switches are pressed */
 RegBase->ATD1DIEN1 = 0xff; /* enable A/D channels 8 - 15 as digital inputs */
 
 RegBase->PORTS = 0x80;     /* for testing */
 RegBase->DDRS = 0x80;

}	/* end VFDSetup */

/*************************************************************************************/

static void SPI1Setup(void)

 {
  
 /* Variable Declarations */

 
 /* Begin Function SPI1Setup() */
 
 RegBase->SPI1.BR = 0x41;		/* setup for a 2 MHz SPI bus */
 RegBase->SPI1.CR1 = 0x5c;		/* SPE = 1; MSTR = 1; CPOL = 1; CPHA = 1 */
 
}	/* end SPI1Setup */

/*************************************************************************************/

static void SPI0Setup(void)

 {
  
 /* 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 */

/*************************************************************************************/

#ifndef __MWERKS__  /* is already set in 'startx.c' */

static void XGateSetup(void)
 {
  
 /* Variable Declarations */

 uchar x;			/* loop counter */
 uint *XGIFP;			/* used to point to the interrupt flag registers */
 
 /* Begin Function XGateSetup() */
 
 RegBase->XGMCTL = XGDBGM | XGSWEIF;/* make sure interrupts to XGate are disabled, not in debug mode & any errors are cleared */

 while (RegBase->XGCHID != 0)		/* wait until the current thread is finished */
  ;

 XGIFP = (uint *)&RegBase->XGIF0;	/* setup pointer to XGate interrupt flag registers */

 *(uint *)&RegBase->XGVBR2 = 0xb000;	/* place XGate vector table at the bottom of RAM (global address 0xfb000) */

 for (x = 0; x < 8; x++)		/* clear all pending interrupts */
  *XGIFP++ = 0xffff;
 
 RegBase->XGSWT = 0xff00;		/* clear any pending software triggers */
 
 RegBase->XGMCTL = XGE | XGDBGM | XGSWEIF | XGIE;	/* enable the XGate module */

}	/* end XGateSetup */

#endif
/*************************************************************************************/

static void SetInterruptPriority(uchar Channel, uchar Priority)

 {
  
 /* Variable Declarations */

 
 /* Begin Function SetInterruptPriority() */
 
 RegBase->INT_CFADDR = (Channel << 1) & 0xf0;
 RegBase->INT_CFDATA[Channel & 0x07] = Priority;
 
}	/* end SetInterruptPriority */

/*************************************************************************************/

static void InterruptModuleSetup(void)

 {
  
 /* Variable Declarations */

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -