Timers On Explore M3
In this tutorial we are going to discuss the Timer module of Explore M3.
LPC1768 has four 32-bit timers, We will use Timer0 and Timer1 to generate a delay of 100ms and 500ms for blinking the LEDs.
Contents
[hide]Prerequisites
Please check this tutorial for detailed explanation on inbuilt Lpc1768 RTC module.
If you are doing it for the first time, then check the below links to setup the project for generating the .bin file.
Hardware Connection
LEDs are Connected to pin 13 and 14.
Code
Below is the sample code to blink the LED's with 100ms and 500ms delay using timers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdutils.h" | |
#include "gpio.h" | |
#include "timer.h" | |
#define LED1 13 | |
#define LED2 14 | |
void myTimerIsr_0(void) | |
{ | |
GPIO_PinToggle(LED1); /* Toggle the LED1 (13) */ | |
} | |
void myTimerIsr_1(void) | |
{ | |
GPIO_PinToggle(LED2); /* Toggle the LED2 (14) */ | |
} | |
int main (void) | |
{ | |
SystemInit(); | |
GPIO_PinDirection(LED1,OUTPUT); /* Configure the pins as Output to blink the Leds*/ | |
GPIO_PinDirection(LED2,OUTPUT); | |
TIMER_Init(0,100000); /* Configure timer0 to generate 100ms(100000us) delay*/ | |
TIMER_Init(1,500000); /* Configure timer1 to generate 500ms(500000us) delay*/ | |
TIMER_AttachInterrupt(0,myTimerIsr_0); /* myTimerIsr_0 will be called by TIMER0_IRQn */ | |
TIMER_AttachInterrupt(1,myTimerIsr_1); /* myTimerIsr_1 will be called by TIMER1_IRQn */ | |
TIMER_Start(0); /* Start the Timers */ | |
TIMER_Start(1); | |
while(1) | |
{ | |
//do nothing | |
} | |
} |