2440定时器可以实现输出方波和定时中断,本列子使用到定时中断。1s亮灭led。
使用pclk50mhz 预分频的0.5mhz,16分频的3125mhz,每0.5s触发一次中断需给TCNTB0送15625
开中断,禁中断和按键中断类似。
1, interrupt.c:
#include "s3c24xx.h"
void EINT_Handle()
{
unsigned long oft = INTOFFSET;
if(INTOFFSET == 10)
{
GPBDAT = ~(GPBDAT & (0xf << 5));
}
SRCPND = 1 << INTOFFSET;
INTPND = INTPND;
}
2,init.c:
#include "s3c24xx.h"
#define GPB5_out (1<<(5*2))
#define GPB6_out (1<<(6*2))
#define GPB7_out (1<<(7*2))
#define GPB8_out (1<<(8*2))
void disable_watch_dog(void)
{
WTCON = 0;
}
void delay()
{
int i;
for(i=0;i<0xf0000;i++);
}
void led_init(void)
{
GPBCON = GPB5_out | GPB6_out | GPB7_out | GPB8_out ;
}
void timer0_init(void)
{
TCFG0 = 99;
TCFG1 = 0x03;
TCNTB0 = 31250;
TCON |= (1<<1);
TCON = 0x09;
INTMSK &= (~(1<<10));
}
5_timer0_interrupt.zip
阅读(974) | 评论(0) | 转发(2) |