- UID
- 1029342
- 性别
- 男
|
#define _ISR_STARTADDRESS 0x33ffff00
#define U32 unsigned int
#define pISR_TIMER4
(*(unsigned *)(_ISR_STARTADDRESS+0x58))
#define rSRCPND
(*(volatile unsigned *)0x4a000000)
//Interrupt request status
#define rINTMSK
(*(volatile unsigned *)0x4a000008)
//Interrupt mask control
#define rINTPND
(*(volatile unsigned *)0x4a000010)
//Interrupt request status
#define rGPBCON
(*(volatile unsigned *)0x56000010)
//Port B control
#define rGPBDAT
(*(volatile unsigned *)0x56000014)
//Port B data
#define rGPBUP
(*(volatile unsigned *)0x56000018)
//Pull-up control B
#define rTCFG0
(*(volatile unsigned *)0x51000000)
//Timer 0 configuration
#define rTCFG1
(*(volatile unsigned *)0x51000004)
//Timer 1 configuration
#define rTCON
(*(volatile unsigned *)0x51000008)
//Timer control
#define rTCNTB4 (*(volatile unsigned *)0x5100003c)
//Timer count buffer 4
void __irq Timer4_ISR(void)
{
static int count;
count ++;
rSRCPND = rSRCPND | (0x1<<14);
rINTPND = rINTPND | (0x1<<14);
//每隔2秒蜂鸣器响一次,持续时间为0.5秒,并伴随着LED亮
if (count % 4 ==0)
rGPBDAT = ~0x1e0;
//蜂鸣器响,LED亮
else if (count % 4 ==1)
rGPBDAT = 0x1e0;
//蜂鸣器不响,LED灭
}
void Main(void)
{
rGPBCON = 0x155555;
//B0输出,给蜂鸣器;B5~B8输出,给LED
rGPBUP
= 0x7ff;
rGPBDAT = 0x1e0;
//蜂鸣器不响,LED灭
rSRCPND = rSRCPND | (0x1<<14);
rINTPND = rINTPND | (0x1<<14);
rINTMSK = ~(0x1<<14);
//打开定时器4中断
rTCFG0 &= 0xFF00FF;
rTCFG0 |= 0xf900;
// prescaler等于249
rTCFG1 &= ~0xF0000;
rTCFG1 |= 0x20000;
//divider等于8,则设置定时器4的时钟频率为25kHz
rTCNTB4 = 12500;
//让定时器4每隔0.5秒中断一次
rTCON &= ~0xF00000;
rTCON |= 0x700000;
rTCON &= ~0x200000 ;
//定时器4开始工作
pISR_TIMER4 = (U32)Timer4_ISR;
while(1)
{
;
}
} |
|