0% found this document useful (0 votes)
24 views5 pages

LPC 2148 Timer Programs only

The document outlines two embedded C programs for the LPC 2148 controller: one for generating a 1 ms delay using a timer without interrupts, and another for toggling a GPIO pin every 1 second using interrupts. It includes calculations for clock frequency and count values, as well as detailed program code for both applications. The results confirm successful execution and verification of the programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

LPC 2148 Timer Programs only

The document outlines two embedded C programs for the LPC 2148 controller: one for generating a 1 ms delay using a timer without interrupts, and another for toggling a GPIO pin every 1 second using interrupts. It includes calculations for clock frequency and count values, as well as detailed program code for both applications. The results confirm successful execution and verification of the programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

APPLICATION PROGRAM USING TIMERS

AIM:

To write an embedded C program to produce a repeated delay for a period of 1 ms using


timer module of LPC 2148 controller without interrupt.

CALCULATION:
Pclk = CCLK/4 = 60 MHz / 4 = 15 MHz
Clock Frequency = 15 MHz / (2+1) = 5 MHz

Clock Period = 1 / (5 MHz) = 200 ns


Count = required delay/clock period = (1 ms) / (200 ns) = 5000d = 1388h

PROGRAM:

#include"LPC214X.h"
int main()
{
PINSEL0=0x00000080; //Enable pin corresponding to timer0
T0PR=0x000003e7; //32-bit Pre-scalar register (PR) can be used to divide the
// Processor clk by PR+1 before applied to counter
T0MCR=0x00000003; // Used to reset the count register (TMR) after every match
// for subsequent cycles
T0EMR=0x00000030; // select the type of change in the respective match output
// pin that indicates the occurrence of match

T0MR0=0x00003a98; // Select one of the four MRn and Load it with maximum count.
// TxMRn = Processor clk / Required output frequency.
// where, x = 0 or 1 and n=0 to 3.

T0TCR=0x01;
return(0);
}

SAMPLE OUTPUT:

1
APPLICATION PROGRAM WITH INTERRUPTS

AIM:

To write an embedded C program to toggle a GPIO pin for every 1 s using IRQ of VIC
modulein LPC 2148 controller.

ALGORITHM:

1. Configure the required interrupt as IRQ using VICIntSelect register.


2. Fix the required priority level by writing the selected interrupt number in the corresponding
control register (VICVectCntln) where, n=0 to 15 (0 – Highest priority, 15 – Lowest priority) and
enable the IRQ slot .
3. Load the respective vector address register (VICVectAddrn) with the starting address of the
corresponding ISR.
4. Set the corresponding bit in the VICIntEnable register to enable the selected interrupt. In case of
peripheral interrupt, also enable the corresponding interrupt bit of the selected peripheral
device in the respective control register of the peripheral.
5. In case of External interrupt, use the PINSEL register to select the interrupt functionality
in the respective GPIO pin.
6. Write the desired functionality in ISR function. (In case of ‘C’ code mark it asIRQ).
7. Finally, Write logic1 to the respective peripheral interrupt request flag bit to clear the
interrupt request flag and acknowledge the interrupt by clearing the contents of
VICVectAddr register before exiting the ISR.

CALCULATION:

Pclk = 60 MHz / 4 = 15 MHz

Clock Frequency = 15 MHz / (2+1) = 5 MHz

Clock Period = 1 / (5 MHz) = 200 ns

Count = required delay/clock period = (1 s)/(200 ns) = 5000000d = 4c4b40h

2
PROGRAM:

#include <LPC214x.h>

void timer(void)__irq

IO1PIN=0X00002A80;

IO1PIN ^= 0X00010000; //toggling of the port pin when interrupt occurs

T0IR=0X01; //Writing one to clear the interrupt

VICVectAddr=0;

int main()

inti;

VICVectAddr0 =(unsigned long) timer;

VICVectCntl0=0x00000024; // 4th slot :TIMER and enabling the interrupt

VICIntEnable=0x00000010; //making the 4th bit to one

IO1DIR =0X00010000; //configuring direction as output

T0PR=0X00000002; // prescalar value

T0MCR=0X0003; //Match Register0: INT and RESET

T0MR0=0X004c4b40; //match register value

T0TCR=0X00000001; // turn on the timer

while(1)

3
i++;

return(0);

SAMPLE OUTPUT:

4
RESULT:

The embedded C program to toggle a GPIO pin for every 1 s using IRQ of VIC module
in LPC 2148 controller has been written, executed and verified.

You might also like