一、CPU定时器初始化
/*************************************************************************/
/* Name : InitCpuTimers */
/* */
/* Init CPU Timers */
/* */
/* In : none */
/* Out : none */
/* Return: none */
/*************************************************************************/
void InitCpuTimers(void)
{
// CPU Timer 0 not used
// CPU Timer 1 为系统提供时基 执行测速程序
// Initialize address pointers to respective timer registers:
CpuTimer1.RegsAddr = &CpuTimer1Regs;
// Initialize timer period
CpuTimer1Regs.PRD.all = CPUTIME1_PRD; //90M/8K
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
CpuTimer1Regs.TPR.all = 0;
CpuTimer1Regs.TPRH.all = 0;
// Make sure timers are stopped:
CpuTimer1Regs.TCR.bit.TSS = 1;
// Reload all counter register with period value:
CpuTimer1Regs.TCR.bit.TRB = 1;
// CPU-Timer Emulation Mode --Free run
CpuTimer1Regs.TCR.bit.FREE = 0x3;
// CPU-Timer Interrupt Enable
CpuTimer1Regs.TCR.bit.TIE = 1;
CpuTimer1Regs.TCR.bit.TSS = 0;
// Reset interrupt counters:
CpuTimer1.InterruptCount = 0;
// CPU Timer 2 提供1ms时基
CpuTimer2.RegsAddr = &CpuTimer2Regs;
CpuTimer2Regs.PRD.all = CPUTIME2_PRD; //90M/1K
CpuTimer2Regs.TPR.all = 0;
CpuTimer2Regs.TPRH.all = 0;
CpuTimer2Regs.TCR.bit.TSS = 1;
CpuTimer2Regs.TCR.bit.TRB = 1;
CpuTimer2Regs.TCR.bit.FREE = 0x3;
CpuTimer2Regs.TCR.bit.TIE = 1;
CpuTimer2Regs.TCR.bit.TSS = 0;
CpuTimer2.InterruptCount = 0;
}
- 仅初始化定时器1和定时器2,若使用定时器0,类似;
- 定时器1提供125us/8k时基,定时器2提供1ms/1k时基;
- 装载值分别为
//定时器频率
#define CPUTIME1_FRE 8000 //定时器1 频率 8K
#define CPUTIME1_PRD SYS_FRE/CPUTIME1_FRE
#define CPUTIME2_FRE 1000 //定时器1 频率 1K
#define CPUTIME2_PRD SYS_FRE/CPUTIME2_FRE
二、ADC初始化
/*************************************************************************/
/* Name : Init Adc */
/* */
/* Init ADC */
/* */
/* In : none */
/* Out : none */
/* Return: none */
/*************************************************************************/
void InitAdc(void)
{
//extern voi