You are on page 1of 11

Course Code: 19ECE304 Name: N P Ganesh Kumar

Course Title: Microcontrollers and Roll No: CH.EN.U4ECE21016


cascasc Interfacing
Semester: 5th
Course Faculty: Dr. C Ganesh Kumar
Academic Year: 2023-2024

Lab Report – 5

Software Used

&

General Instruction

1. MOV: Moves 16-bit data to the register.


2. AREA: Assigns and instructs the assembler to assemble the code.
3. END: To denote the completion of the program.
4. CODE: To specify whether it is code or data sec􀆟on.
5. READONLY: To make it viewable but not editable.
Objective
Write assembly level program for 7 Segment for displaying alphabets and numbers. And
application of the 7 Segment by using Keil µVision software for the coding part and Flash Magic
software for dumping the code into the trainer kit to display the alphabets and numbers in the 7
Segment.
List Of Experiment

1) Program to display 0-9 numbers in 7 segment display

2) Program to Configure PLL to switch states (ON & OFF) with an interval speed of 1
second

3) Program to configure PLL to switch states (ON & OFF) at 20MHz

4) Program to configure PLL to switch states (ON & OFF) with an interval speed of 3
seconds

5) Program to display alphabets (b, c, d, e, g, h, l, n, o, t, u, and y) in 7 – segment display

Experiment

Program to display 0-9 numbers in 7 segment display

Source Code

#include<lpc21xx.h>
unsigned int i, j;
unsigned int
display[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x98};
void delay()
{
for(j=0;j<100000;j++);
}
int main()
{
PINSEL0=0X00000000;
IO0DIR =0X000000FF;
while(1)
{
for(i=0;i<10;i++)
{
IO0SET =display[i];
delay();
IO0CLR =display[i];
}
}
}

Output

Inference

From the code I infer, the program uses a delay function to give the 7-segment display time
to update its output. This is a common practice when working with 7-segment displays, as they
can take a few milliseconds to update their output. The program uses a for loop to iterate through
the array of numbers, displaying each number in turn. This is a simple and efficient way to loop
through an array. The program uses the IO0SET and IO0CLR registers to control the outputs of
the 7-segment display. These registers are specific to the LPC21xx microcontroller, so the program
would need to be modified if it were to be used with a different microcontroller.
Program to Configure PLL to switch states (ON & OFF) with an interval speed of 1 second

Source Code

#include<lpc214x.h>
#define PLOCK 0x00000400
void led_on()
{
IO1SET=0x00FF0000;
}
void led_off()
{
IO1CLR= 0x00FF0000;
}
void delay(int count)
{
int i;
for(i=0;i<count;i++);
}
int main(void)
{
PLL0CON=0X01;
PLL0CFG=0X24;
PLL0FEED=0XAA;
PLL0FEED=0X55;
while(!(PLL0STAT & PLOCK));
PLL0CON=0x03;
PLL0FEED=0XAA;
PLL0FEED=0X55;
PINSEL1=0x0000000;
IO1DIR=0x00FF0000;
while(1)
{
led_on();
delay(12000000);
led_off();
delay(12000000);
}
}
Output
Inference

From the code I infer: The program uses the PLL to increase the clock speed of the microcontroller.
This is a common practice when working with embedded systems, as it can improve the
performance of the system. The program uses the PINSEL register to configure the pin
multiplexing. This ensures that the pin connected to the LED is configured as an output. The
program uses the IODIR register to set the direction of the pins. This ensures that the pin connected
to the LED is an output. The program uses the delay() function to create a delay between turning
the LED on and off. This ensures that the LED blinks at a consistent rate. The program uses a
while loop to blink the LED indefinitely. This ensures that the LED will continue to blink until the
program is terminated.

Program to configure PLL to switch states (ON & OFF) at 20MHz

Source Code

#include <lpc214x.h>

#define PLOCK 0x00000400

void led_on() {
IO1SET = 0x00FF0000;
}

void led_off() {
IO1CLR = 0x00FF0000;
}

void delay(int count) {


int i;
for (i = 0; i < count; i++);
}

int main(void) {
// Connect a 20MHz crystal oscillator to XTAL1 (P0.1) and XTAL2 (P0.10)
pins

PLL0CFG = 0x22; // Divide by 2, M = 3, P = 2 (Fosc = 4 * M * Fin / P = 4


* 5MHz / 2 = 20MHz)
PLL0CON = 0x01; // Enable PLL
PLL0FEED = 0xAA;
PLL0FEED = 0x55;

while (!(PLL0STAT & PLOCK));


PLL0CON = 0x03; // Connect and enable PLL
PLL0FEED = 0xAA;
PLL0FEED = 0x55;

VPBDIV = 0x01; // PCLK = CCLK = 20MHz

PINSEL1 = 0x00000000; // Set P1.16 to P1.23 as GPIO


IO1DIR = 0x00FF0000; // Set P1.16 to P1.23 as output

while (1) {
led_on();
delay(20000000); // Adjust the delay to control the toggle frequency
(20MHz / 2 / 2 / 600000 = 16.666 Hz)
led_off();
delay(20000000); // Adjust the delay to control the toggle frequency
(20MHz / 2 / 2 / 600000 = 16.666 Hz)
}
}
Output

Inference

The program uses the PLL to increase the clock speed of the microcontroller. This is a common
practice when working with embedded systems, as it can improve the performance of the system.
The program uses the PINSEL register to configure the pin multiplexing. This ensures that the pins
connected to the LED are configured as outputs. The program uses the IODIR register to set the
direction of the pins. This ensures that the pins connected to the LED are outputs. The program
uses the delay() function to create a delay between turning the LED on and off. This ensures that
the LED blinks at a consistent rate. The program uses a while loop to blink the LED indefinitely.
This ensures that the LED will continue to blink until the program is terminated.

Program to configure PLL to switch states (ON & OFF) with an interval speed of 3 seconds

Source Code

#include<lpc214x.h>
#define PLOCK 0x00000400
void led_on()
{
IO1SET=0x00FF0000;
}
void led_off()
{
IO1CLR= 0x00FF0000;
}
void delay(int count)
{
int i;
for(i=0;i<count;i++);
}
int main(void)
{
PLL0CON=0X01;
PLL0CFG=0X24;
PLL0FEED=0XAA;
PLL0FEED=0X55;
while(!(PLL0STAT & PLOCK));
PLL0CON=0x03;
PLL0FEED=0XAA;
PLL0FEED=0X55;
PINSEL1=0x0000000;
IO1DIR=0x00FF0000;
while(1)
{
led_on();
delay(36000000);
led_off();
delay(36000000);
}}
Output

Inference

From the code, I infer that the above code is a simple program that blinks an LED connected to an
LPC214x microcontroller at a frequency of 0.5Hz. The first line of code includes the lpc214x.h
header file, which contains definitions for the registers and functions used to control the LED. The
next two lines define two functions, led_on() and led_off(), which are used to turn on and off the
LED, respectively. The delay() function is a simple delay function that is used to ensure that the
LED has time to turn on or off. The main() function is the main function of the program. This
function first configures the PLL to run at 60MHz. It then configures the PINSEL1 register to
configure the pin of Port 1 that is connected to the LED as an output. It then sets the IO1DIR
register to configure Port 1 as outputs. The while(1) loop continuously blinks the LED at a
frequency of 0.5Hz. The led_on() function turns on the LED, the delay() function waits for 1.2
seconds, the led_off() function turns off the LED, and the delay() function waits for 1.2 seconds.
Program to display alphabets (b, c, d, e, g, h, l, n, o, t, u, and y) in 7 – segment display

Source Code

#include<lpc21xx.h>
unsigned int i,j;
unsigned int display[12] = {0x7c, 0x58, 0x5e, 0x7b, 0x6f, 0x74, 0x06, 0x54,
0x5c, 0x78, 0x1c, 0x6e};
void delay()
{
for(j=0;j<1000000;j++);
}
int main()
{
PINSEL0=0X00000000;
IO0DIR=0X00FF0000;
while(1)
{
for(i=0;i<10;i++)
{
IO0SET=display[i]<<16;
delay();
IO0CLR=display[i]<<16;
}
}
}

Output

Inference

From the code, The first thing to note is that the code includes the lpc21xx.h header file. This
header file contains definitions for the registers and functions used to control the 7-segment
display. The next thing to note is that the code declares two variables, i and j. The variable i is used
to loop through the display array, and the variable j is used to generate a delay. The display array
is a global variable that holds the binary codes for the letters "b", "c", "d", "e", "g", "h", "l", "n",
"o", "t", "u", and "y". The delay() function is a simple delay function that is used to ensure that the
7-segment display has time to update. The main() function is the main function of the program.
This function first configures the PINSEL0 register to configure the pins of Port 0 that are
connected to the 7-segment display as outputs. It then sets the IO0DIR register to configure Port 0
as outputs. The while(1) loop continuously displays the letters "b", "c", "d", "e", "g", "h", "l", "n",
"o", "t", "u", and "y" on the 7-segment display. For each letter, the display[i]<<16 expression gets
the binary code for the letter i and shifts it 16 bits to the left. This is done because the 7-segment
display is connected to the lower 8 bits of Port 0. The IO0SET =display[i]<<16; statement sets the
appropriate bits in the IO0SET register to display the letter i on the 7-segment display. The delay()
function is called to ensure that the 7-segment display has time to update before the next letter is
displayed.

Cessation Of this Lab

From this lab I learnt about 7 Segment configuration and how to program a code to display
any data on LPC2148 kit (hardware) I learnt about different commands and configuration like
Register select(RS),Enable(EN),Read/write(RW).I have seen about cursor positions various
commands like (0x01) - to clear the display, (0x0E) - to make the display on, cursor on, (0x0C) is
to display on, cursor off., 0x80) to force cursor to beginning of 1st row, (0xC0) to force cursor to
beginning of 2nd row. By using these commands and registers we can code accordingly to alphabets
and numbers in 7 segments display and by using flash magic software we can dump the code into
the trainer kit and observe how its displays the alphabets and numbers in 7 segments display .

You might also like