TQ2440裸板---pwm时钟(详细注释)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值