#include "2440addr.h"
#include "rtc.h"
#include "def.h"
#include "led.h"
#include "uart.h"
volatile int led1status = 1,led2status = 1;
void timer_init(void)
{
//TIMER4配置
rSRCPND |= (0x1<<14); //TIMER4
rINTMOD &= ~(0x1<<14);
rINTMSK &= ~(0x1<<14);
rINTPND |= (0x1<<14);
pISR_TIMER4 = (U32)TIMER4_IRQ;
rTCON &= ~(0x1<<20);//关闭定时器
rTCFG0 |= 0x7c<<8;//125分频 124+1
rTCFG1 |= (0x2<<16);//TIMER4 8分频
rTCNTB4 = 0xc350;//TIMER4 50000
rTCON |= (0x1<<21);//手动更新TIMER4->TCNT4
rTCON &= ~(0x1<<21);//关闭手动更新
//TIMER3配置
rSRCPND |= (0x1<<13); //TIMER3
rINTMOD &= ~(0x1<<13);
rINTMSK &= ~(0x1<<13);
rINTPND |= (0x1<<13);
pISR_TIMER3 = (U32)TIMER3_IRQ;
rTCON &= ~(0x1<<16);//关闭定时器
rTCFG1 |= (0x3<<12);//TIMER3 16分频
rTCFG0 |= 0x7c<<8;//125分频 124+1
rTCNTB3 = 0xc350;//TIMER3 50000
rTCON |= (0x1<<17);//TIMER3->TCNT3
rTCON &= ~(0x1<<17);//关闭手动更新
rTCON |= (0x1<<22|0x1<<20|0x1<<19|0x1<<16);//开启自动更新TCNT4,TCNT3寄存的值启动定时器
}
void __irq TIMER4_IRQ(void)
{
rSRCPND |= 0x1<<14; //TIMER4
rINTPND |= 0x1<<14;
led_set(1,led1status);
led1status = !led1status;
uart_printf("the LED1 status is %d",led1status);
}
void __irq TIMER3_IRQ(void)
{
rSRCPND |= 0x1<<13; //TIMER4
rINTPND |= 0x1<<13;
led_set(2,led2status);
led2status = !led2status;
uart_printf("the LED2 status is %d",led2status);
}
06-30
08-20