📄 main.c
字号:
/*********************************************************************
** Module Name: EvTimer **
** Author: Cbq **
** Version: 1.0 **
** CreateDate: 2008-05-15 **
** Description: **
** Remark: Huozq **
** Revision History: 2008-11-10 **
** Web: http://www.study-kit.com **
**********************************************************************/
/*********************************************************************
** 实验目的:了解事件管理器的定时器的应用,大家在学习时要结合第四章 **
** 的事件管理器来进行 **
** 实验说明:这里我们只使用了EvaTimer1来控制LED灯的亮灭,你在学习中 **
** 可通过它来了解EV的定时器工作原理,对以后做电机之类的控 **
** 制时可以引用部分函数 **
** 实验结果:可看到板上8个发光二极管产生流水灯的效果 **
**********************************************************************/
#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
unsigned int *Led8 = (unsigned int *)0x4100; //LED 控制寄存器
const Uint16 LedCode[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF};
// Prototype statements for functions found within this file.
interrupt void eva_timer1_isr(void);
interrupt void eva_timer2_isr(void);
interrupt void evb_timer3_isr(void);
interrupt void evb_timer4_isr(void);
// Global counts used in this example
Uint32 EvaTimer1InterruptCount;
Uint32 EvaTimer2InterruptCount;
Uint32 EvbTimer3InterruptCount;
Uint32 EvbTimer4InterruptCount;
Uint16 LedCount = 0;
void main(void)
{
/*初始化系统*/
InitSysCtrl();
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE*/
InitPieCtrl();
/*初始化PIE中断矢量表*/
InitPieVectTable();
/*初始化外设*/
InitPeripherals();
/*初始化GPIO*/
InitGpio();
InitXIntrupt();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.T1PINT = &eva_timer1_isr;
PieVectTable.T2PINT = &eva_timer2_isr;
PieVectTable.T3PINT = &evb_timer3_isr;
PieVectTable.T4PINT = &evb_timer4_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
// Enable PIE group 2 interrupt 4 for T1PINT
PieCtrl.PIEIER2.all = M_INT4;
// Enable PIE group 3 interrupt 1 for T2PINT
PieCtrl.PIEIER3.all = M_INT1;
// Enable PIE group 4 interrupt 4 for T3PINT
PieCtrl.PIEIER4.all = M_INT4;
// Enable PIE group 5 interrupt 1 for T4PINT
PieCtrl.PIEIER5.all = M_INT1;
// Enable CPU INT2 for T1PINT, INT3 for T2PINT, INT4 for T3PINT
// and INT5 for T4PINT:
IER |= (M_INT2 | M_INT3 | M_INT4 | M_INT5);
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// Step 6. IDLE loop. Just sit and loop forever:
for(;;);
}
// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:
// If local ISRs are used, reassign vector addresses in vector table as
// shown in Step 5
/*这里的配置需参照课本第四章的事件管理器的中断寄存器的设置*/
interrupt void eva_timer1_isr(void)
{
EvaTimer1InterruptCount++;///EV中断计数累加
// Enable more interrupts from this timer
EvaRegs.EVAIMRA.bit.T1PINT = 1;////EVA的中断屏蔽寄存器的通用定时器1的周
////期中断位使能
// Note: To be safe, use a mask value to write to the entire
// EVAIFRA register. Writing to one bit will cause a read-modify-write
// operation that may have the result of writing 1's to clear
// bits other then those intended.
EvaRegs.EVAIFRA.all = BIT7;
// Acknowledge interrupt to recieve more interrupts from PIE group 2
PieCtrl.PIEACK.all = PIEACK_GROUP2;////响应中断组
/*下面就是我们写进去的数据给CPLD来控制LED的亮灭*/
*Led8 = LedCode[8-LedCount];
LedCount++;
if (LedCount>8) LedCount = 0;
}
interrupt void eva_timer2_isr(void)
{
EvaTimer2InterruptCount++;
// Enable more interrupts from this timer
EvaRegs.EVAIMRB.bit.T2PINT = 1;
// Note: To be safe, use a mask value to write to the entire
// EVAIFRB register. Writing to one bit will cause a read-modify-write
// operation that may have the result of writing 1's to clear
// bits other then those intended.
EvaRegs.EVAIFRB.all = BIT0;
// Acknowledge interrupt to recieve more interrupts from PIE group 3
PieCtrl.PIEACK.all = PIEACK_GROUP3;
}
interrupt void evb_timer3_isr(void)
{
EvbTimer3InterruptCount++;
// Note: To be safe, use a mask value to write to the entire
// EVBIFRA register. Writing to one bit will cause a read-modify-write
// operation that may have the result of writing 1's to clear
// bits other then those intended.
EvbRegs.EVBIFRA.all = BIT7;
// Acknowledge interrupt to recieve more interrupts from PIE group 4
PieCtrl.PIEACK.all = PIEACK_GROUP4;
}
interrupt void evb_timer4_isr(void)
{
EvbTimer4InterruptCount++;
// Note: To be safe, use a mask value to write to the entire
// EVBIFRB register. Writing to one bit will cause a read-modify-write
// operation that may have the result of writing 1's to clear
// bits other then those intended.
EvbRegs.EVBIFRB.all = BIT0;
// Acknowledge interrupt to recieve more interrupts from PIE group 5
PieCtrl.PIEACK.all = PIEACK_GROUP5;
}
void Delay(Uint16 data)
{
Uint16 i;
for (i=0;i<data;i++) { ; }
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -