TQ2440裸板---pwm时钟(详细注释)
2013-11-25 19:25
417 查看
#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); }
相关文章推荐
- 安卓客户端解析json
- java 在控制台上输入密码时,密码不显示在控制台上
- 可执行文件信息查看工具代码示例
- java 成绩处理
- Curl盗取京东图片
- Win 32 多线程程序设计学习笔记之三:*WaitFor*Object函数
- IKVM简介
- 算法导论 第8章 线性时间排序-计数排序的原址排序
- 黑马程序员--Java基础之IO流(2)
- uva 10369(最小生成树)
- 交换机基本原理和转发流程总结
- Qt实现截屏
- MFC 处理双击事件时屏蔽掉单击事件
- 关于使用图片轮播插件无法实现效果的问题
- 智能终端应用程序测试内容
- 分析成绩单
- 关于使用图片轮播插件无法实现效果的问题
- 数字滤波
- TQ2440裸板---lcd液晶显示(详细注释)
- Java 输入