Assignment 2
Assignment 2
Write a C program for displaying your BITS ID on 1st Row and voltage difference
between the terminals of the potentiometer on 2 nd row of LCD Display present in the
LPC2378 kit. The Potentiometer is connected to AD0.0 pin of LPC2378. This program is to be
done using remote lab and Keil uV4 . Capture the screenshot of the LCD display showing
your BITS ID and voltage value. Give suitable screen shots of the KEIL IDE-in debug mode to
demonstrate the desired outputs. Ensure that the screenshot captures system time & day.
Ans : 1
C program for displaying the requested information on the LCD display of LPC2378 kit:
#include <LPC23xx.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
int main() {
// Initialize ADC
PINSEL1 |= (1 << 14); // Select AD0.0 pin
AD0CR = (1 << 0) | // Select channel 0
(1 << 21) | // Enable ADC
(10 << 8); // Set ADC clock to 4.5 MHz
// Initialize LCD
lcd_init();
// Display first name on first row
lcd_gotoxy(0, 0);
lcd_puts("Rahul (2022HT80055)");
// Read voltage difference from potentiometer and display on second row
while (1) {
AD0CR |= (1 << 24); // Start conversion
while (!(AD0GDR & (1 << 31))); // Wait for conversion to finish
unsigned int value = (AD0GDR >> 6) & 0x3FF; // Get 10-bit ADC value
float voltage = (float)value * 3.3 / 1023.0; // Convert to voltage
char str[16];
sprintf(str, "Voltage=%.2fV", voltage);
lcd_gotoxy(0, 1);
lcd_puts(str);
}
}
c) Give the steps to program timer for 2 second delay generation with calculation. Assume
CCLK=48MHz.
Ans : To program the timer for a 2 second delay generation with CLK=48MHz, we need to
calculate the timer interval using the following formula:
Timer interval = (Delay time / Clock period) - 1
where Delay time is the desired delay in seconds, and
Clock period is the period of the system clock, which is 1/CCLK.
Substituting the values, we get:
Timer interval =2/(1/48,000,000)−1=95,999,999
The maximum value that can be loaded into the timer register is 2^32-1, which is greater
than the calculated value. Therefore, we can use any timer in LPC2378 to generate a 2
second delay by loading the calculated value into its match register and configuring it to
generate an interrupt when the timer value matches the match register value.
Explanation:
To generate a 2 second delay using a timer in LPC2378, we need to calculate the value that
needs to be loaded into the timer register using a simple formula that takes into account the
system clock frequency and the desired delay time. Once we have the timer value, we can
configure the timer to generate an interrupt when it reaches the match value, which will
signal that the 2 second delay has elapsed.