#define GLOBAL_CLK 1
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
static void __irq timer0_interrupt(void)
{
static unsigned int count=0;
rSRCPND |= (1<<10);
rINTPND |= (1<<10);
count++;
if(count%4 == 1)
{
rGPBDAT &= ~(1<<5);
rGPBDAT |= (1<<6)|(1<<7)|(1<<8);
}
if(count%4 == 2)
{
rGPBDAT &= ~(1<<6);
rGPBDAT |= (1<<5)|(1<<7)|(1<<8);
}
if(count%4 == 3)
{
rGPBDAT &= ~(1<<7);
rGPBDAT |= (1<<5)|(1<<6)|(1<<8);
}
if(count%4 == 0)
{
rGPBDAT &= ~(1<<8);
rGPBDAT |= (1<<5)|(1<<6)|(1<<7);
}
}
void init_timer0(void)
{
rGPBCON = (1<<16)|(1<<14)|(1<<12)|(1<<10)|(2<<0);
rGPBDAT = 0x1e0; //111100000
rGPBUP =0x7ff;
rSRCPND |= (1<<10);
rINTPND |= (1<<10);
rINTMSK &= ~(1<<10);
/*
设置预分频 249 ,公式: 预分频
Timer input clock Frequency = PCLK / {prescaler value + 1} / {divider value}
{prescaler value} = 0~255
{divider value} = 2, 4, 8, 16
*/
rTCFG0 |= 0xf9;
// 4 分 之 1 分频
rTCFG1 |= 0x1;
//设置缓冲计数寄存器
rTCNTB0 = 25000;
//设置计数比较器
rTCMPB0 = 25000>>1;
//设置启动为 0定时器
rTCON |= 0xf;
//NOTE: The bit has to be cleared at next writing. 在下一次写操作之前,必须要被清除,所以要置0
rTCON &= ~(1<<1);
}
void Main(void)
{
pISR_TIMER0 = (U32)timer0_interrupt;
init_timer0();
while(1);
}
TQ2440裸板---pwm时钟(详细注释)
最新推荐文章于 2023-05-23 19:43:40 发布