定时器——ARM的Proteus实验
实验原理
ARM的定时器实验,定时改变LED的状态。
Proteus仿真电路图

C语言源程序
#include <LPC21xx.H>菜鸟的ARM学习笔记(第一阶段)
#define LED 0x000001
typedef unsigned int uint32;
typedef unsigned char uint8;
void timer0_ISR (void) __attribute__ ((interrupt));
uint8 timer0Times = 0;
void timer0Init (void) {
T0MR0 = 119999;/*匹配寄存器,120000-1,12000000为1秒*/
T0MCR = 3;/*产生中断,重置TC*/
T0TCR = 1;/*使能定时计数器0*/
VICVectAddr0 = (unsigned long)timer0_ISR;
VICVectCntl0 = 0x20 | 4;/*定时器计数器0为4号中断*/
VICIntEnable = 0x00000010;/*开定时计数器0中断*/
}
void timer0_ISR (void) {
timer0Times++;
uint32 i;
if(timer0Times == 10){
i=IO0SET; //读出当前LED2控制值
if((i&LED)==0){
IO0SET=LED;
}else{
IO0CLR=LED;
}
timer0Times = 0;
}
T0IR = 1;/*清除定时器0中断*/
VICVectAddr = 0;
}
int main(void) {
PINSEL0 = 0;/*设置引脚为GPIO */
IO0DIR = LED;/*将P0.0设置为输出 */
IO0SET = LED;/*将P0.0置1,也就是让led灭 */
timer0Init();
while (1) {
}
}
- LED闪烁——ARM的Proteus实验
- 开关控制LED——ARM的Proteus实验
- LCD——ARM的Proteus实验
- UART——ARM的Proteus实验
- Eint1外部中断——ARM的Proteus实验
- 多个外部中断——ARM的Proteus实验
- 中断结合串口——ARM的Proteus实验
- 定时器——ARM的Proteus实验
- SPI通信——ARM的Proteus实验
- SPI通信(多从设备)——ARM的Proteus实验
- ADC数模转换——ARM的Proteus实验
