ARM7入门1,跑马灯实验
扫描二维码
随时随地手机看文章
用keil uvision3和proteus做的程序。
主程序:
/******************************************************************************/
/* This file is part of the uVision/ARM development tools */
/* Copyright KEIL ELEKTRONIK GmbH 2002-2004 */
/******************************************************************************/
/* */
/* BLINKY.C: LED Flasher */
/* */
/******************************************************************************/
#include
#include "Timer.h"
extern long volatile timeval;
/*******************************************************************************
**Name: wait()
**Descriptions: Delay
********************************************************************************/
void wait (void) { /* wait function */
unsigned long i;
i = timeval;
while ((i + 10) != timeval); /* wait 100ms */
}
/*******************************************************************************
**Name: main()
**Descriptions: Blink
********************************************************************************/
int main (void) {
unsigned int j; /* LED var */
IO0DIR = 0x0000FF; /*P0.0..P0.7defined as Outputs */
init_timer();
IO0SET=0x0000FF;
while (1) { /* Loop forever */
for (j = 0x000001; j < 0x000080; j <<= 1) { /* Blink LED 0,1,2,3,4,5,6 */
IO0CLR = j; /* Turn on LED */
wait (); /* call wait function */
IO0SET = j; /* Turn off LED */
}
for (j = 0x000080; j > 0x000001; j >>=1 ) { /* Blink LED 7,6,5,4,3,2,1 */
IO0CLR = j; /* Turn on LED */
wait (); /* call wait function */
IO0SET = j; /* Turn off LED */
}
}
}
定时程序:
/******************************************************************************/
/* This file is part of the uVision/ARM development tools */
/* Copyright KEIL ELEKTRONIK GmbH 2002-2004 */
/******************************************************************************/
/* */
/* TIME.C: Time Functions for 100Hz Clock Tick */
/* */
/******************************************************************************/
#include
#include "Timer.h"
long timeval;
void tc0 (void) __attribute__ ((interrupt)); // Generate Interrupt
/* Setup the Timer Counter 0 Interrupt */
void init_timer (void) {
T0MR0 = 149999; // 10mSec = 150.000-1 counts
T0MCR = 3; // Interrupt and Reset on MR0
T0TCR = 1; // Timer0 Enable
VICVectAddr0 = (unsigned long)tc0; // set interrupt vector in 0
VICVectCntl0 = 0x20 | 4; // use it for Timer 0 Interrupt
VICIntEnable = 0x00000010; // Enable Timer0 Interrupt
}
/* Timer Counter 0 Interrupt executes each 10ms @ 60 MHz CPU Clock */
void tc0 (void) {
timeval++;
T0IR = 1; // Clear interrupt flag
VICVectAddr = 0; // Acknowledge Interrupt
}
头文件:
extern void init_timer(void);
Q:请教寄存器VICVectAddr 和VICVectAddr0~15 的使用区别,看文档没有明白,谢谢!
A:VICVectAddr 在发生中断时,存放有服务程序的地址(来自VICDefVectAddr 或
VICVectAddr0~15);而VICVectAddr0~15 是存放各个向量中断服务程序地址的寄存器,
当发生向量中断时,相应的地址会自动装载到VICVectAddr 中.