首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

s3c2440定时器中断的应用(2)

s3c2440定时器中断的应用(2)

#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)


{



;



}

}
继承事业,薪火相传
返回列表