LPC1769 Interrupt Program
LPC1769 Interrupt Program
1. Interrupt-Whenever any device needs its service, the device notifies the
microcontroller by sending it an interrupt signal. Upon receiving an
interrupt signal, the microcontroller interrupts whatever it is doing and
serves the device. The program which is associated with the interrupt is
called the interrupt service routine (ISR) or interrupt handler
2. Polling- The microcontroller continuously monitors the status of a
given device. When the conditions met, it performs the service. After
that, it moves on to monitor the next device until every one is serviced
Your code is setting the clock division for the watch dog timer. The timer0
position is at bits 3-2 (div << 2).
The default for timer 0 is CCLK/4 so you need to write "01" to bits 3-2 (0x01
<< 2) for 100MHz. So the two
lines above don't make any sense.
Number of counts per interrupt = .01 sec / 100nsec per count = 1000000
counts. MR0 = 1000000.
Example 1) – Simple Blinky Example using Timer & GPIO
Now lets write a C/C++ blinky program which flashes a LED every half a second. Since 0.5 second =
500 millisecond we will invoke timer delay function ‘delayMS’ as delayMS(500). The LED is
connected to Pin P0.22.
#include <lpc17xx.h>
int main(void)
{
//SystemInit(); //called by Startup Code before main(), hence no need to
call again.
initTimer0(); //Initialize Timer0
LPC_GPIO0->FIODIR = (1<<22); //Configure P0.22 as output
while(1)
{
LPC_GPIO0->FIOSET = (1<<22); //Turn ON LED
delayMS(500); //0.5 Second(s) Delay
LPC_GPIO0->FIOCLR = (1<<22); //Turn LED OFF
delayMS(500);
}
void initTimer0(void)
{
/*Assuming that PLL0 has been setup with CCLK = 100Mhz and PCLK = 25Mhz.*/
LPC_SC->PCONP |= (1<<1); //Power up TIM0. By default TIM0 and TIM1 are
enabled.
LPC_SC->PCLKSEL0 &= ~(0x3<<3); //Set PCLK for timer = CCLK/4 = 100/4
(default)
LPC_TIM0->CTCR = 0x0;
LPC_TIM0->PR = PRESCALE; //Increment LPC_TIM0->TC at every 24999+1 clock
cycles
//25000 clock cycles @25Mhz = 1 mS
#include <lpc17xx.h>
void initTimer0(void);
initTimer0();
while(1)
{
//Idle loop
}
//return 0; //normally this won't execute
}
void initTimer0(void)
{
/*Assuming that PLL0 has been setup with CCLK = 100Mhz and PCLK =
25Mhz.*/
LPC_SC->PCONP |= (1<<1); //Power up TIM0. By default TIM0 and TIM1 are
enabled.
LPC_SC->PCLKSEL0 &= ~(0x3<<3); //Set PCLK for timer = CCLK/4 = 100/4
(default)
LPC_TIM0->CTCR = 0x0;
LPC_TIM0->PR = PRESCALE; //Increment LPC_TIM0->TC at every 24999+1 clock
cycles
//25000 clock cycles @25Mhz = 1 mS
#include <lpc17xx.h>
void initTimer0();
int main(void)
{
//SystemInit(); //called by Startup Code before main(), hence no need to
call again.
LPC_GPIO1->FIODIR |= (1<<29); //set P1.29 as output
initTimer0();
while(1)
{
//Idle loop
}
//return 0; //normally this won't execute
}
void initTimer0(void)
{
/*Assuming that PLL0 has been setup with CCLK = 100Mhz and PCLK = 25Mhz.*/
LPC_SC->PCONP |= (1<<1); //Power up TIM0. By default TIM0 and TIM1 are
enabled.
LPC_SC->PCLKSEL0 &= ~(0x3<<3); //Set PCLK for timer = CCLK/4 = 100/4
(default)
LPC_TIM0->CTCR = 0x0;
LPC_TIM0->PR = PRESCALE; //Increment LPC_TIM0->TC at every 24999+1 clock
cycles
//25000 clock cycles @25Mhz = 1 mS