用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 的使用區(qū)別,看文檔沒有明白,謝謝!
A:VICVectAddr 在發(fā)生中斷時,存放有服務程序的地址(來自VICDefVectAddr 或
VICVectAddr0~15);而VICVectAddr0~15 是存放各個向量中斷服務程序地址的寄存器,
當發(fā)生向量中斷時,相應的地址會自動裝載到VICVectAddr 中.