S3C2440定时器的使用
#include "mytimer.h"
#include "lhg_def.h"
#include "uart.h"
#include "lhg_def.h"
#include "2440addr.h"
//Timer input clock Frequency = PCLK / {prescaler value+1} / {divider value}
//PCLK=50Mhz
//prescaler : 0~255
#define prescaler234 99
//divider : 1/2,1/4,1/8,1/16 选择为(0,1,2,3)
#define divider4 2
//定时器设置为62500HZ
void __irq timer4ISP(void) //中断函数
{
rSRCPND |= rSRCPND|(0x1<<14);
rINTPND |= rINTPND|(0x1<<14);
Uart_Printf("now in timer4 interrupt~~ ");
}
void mytimer_init(void)//初始化定时器
{
Uart_Printf("timer4 init/r/n");
//设置中断入口
pISR_TIMER4 = (U32)timer4ISP;
rTCFG0 &=~(0xff<<8);
rTCFG0 |= prescaler234<<8;
rTCFG1 &=~(0xf<<16);
rTCFG1 |= divider4<<16;
rTCNTB4 = 62500;//16位的 count buffer register
//rTCNTO4 = //16位的 count observation value for Time 4
rTCON |= (1<<22)|(1<<21)|(1<<20);//自动装载,启动定时器
rTCON &= ~0x200000 ; //定时器4开始工作
//关于中断
rSRCPND |= rSRCPND|(0x1<<14);
rINTPND |= rINTPND|(0x1<<14);
rINTMSK &= ~(0x1<<14);
}