Download Lesson 14 System Tick Timer (Systick Timer)
Transcript
/*---------------------------------------------------------------------------Lesson 13: using c and Systick timer interrupt
*---------------------------------------------------------------------------*/
#include "LPC17xx.h"
// Device header
void SysTick_Handler(void); // Systick handler declaration
// Define pointers to registers
volatile unsigned int* STCTRL_ptr
= (unsigned int *) 0xE000E010;
volatile unsigned int* STRELOAD_ptr = (unsigned int *) 0xE000E014;
volatile unsigned int* STCURR_ptr
= (unsigned int *) 0xE000E018;
/*---------------------------------------------------------------------------Main: Initialize
*---------------------------------------------------------------------------*/
int main (void) {
/*Initialize Systick Timer
*(STCTRL_ptr)
= 0x0;
*(STRELOAD_ptr) = 99999;
*(STCURR_ptr)
= 0x0;
*(STCTRL_ptr)
= 0x7;
*/
//
//
//
//
while (1){}
// main loop
Disable timer
100,000 cycles = 1ms (100 MHz)
Write anything to this register to clear
ENABLE = 1, TICKINT = 1, CLKSOURCE = 1
}
/*---------------------------------------------------------------------------Systick Timer ISR
*---------------------------------------------------------------------------*/
void SysTick_Handler(void){
/* Processing */
// do nothing;
}
/* clear the flag */
*(STCTRL_ptr);
// Read STCTRL to clear
Exercise: Write a C program to for the example above. Use the simulator to verify 1ms interrupts.
4.
References
[1].
[2].
[3].
[4].
[5].
Joseph Yiu, The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors, Elsevier, 3rd ed, 2014.
Jonathan Valvano, Introduction to ARM Cortex-M Microcontroller, 4nd ed, 2013.
ARMv7-M Architecture Reference Manual, ARM Limited, 2010.
LPC17xx User manual, NXP Semiconductors, 2010.
Cortex-M3 Technical Reference Manual, ARM Limited, 2010.
5