Professional Documents
Culture Documents
Lab Report – 4
Software Used
&
General Instruction
Write assembly level program for LCD display (Liquid Crystal Display) for displaying /
printing text in the first line, displaying text in the first as well as the second line of the
LCD display, scrolling word from left to right in the LCD display by using Keil µVision
software for the coding part and Flash Magic software for dumping the code into the trainer
kit to display the text in the LCD display.
Library used
lpc21xx.h
The header file typically contains a set of macros, register definitions, and
function prototypes specific to the LPC21xx series, making it easier to interact with the micro
controller's hardware. The "lpc21xx.h" header file may define register addresses and bit fields for
the various peripherals (GPIO, UART, SPI, I2C, etc.), making it more convenient for developers
to access and configure these peripherals without directly dealing with raw memory addresses.
Commands
1. PINSEL0 controls PORT0 pins P0.0 to P0.15
2. PINSEL1 controls PORT0 pins P0.16 to P0.31
3. PINSEL2 controls PORT1 pins P1.16 to P1.31
4. IOxSET (Input Output Set Register):
Bits are checked to force a high level for that port bit during output.
5. IOxCLR (Input Output Clear Register):
Bits are checked to force a low level for that port bit during output.
List Of Experiment
Source Code
#include<lpc214x.h>
#define RS 0x02000000
#define EN 0x01000000
unsigned char msg[]="WELCOME";
void lcd_delay()
{
int i;
for(i=0;i<100000;i++);
}
void lcd_cmd(unsigned char cmd)
{
IO1CLR = 0x03FF0000;
IO1SET = cmd<<16;
IO1CLR=RS;
IO1SET=EN;
lcd_delay();
IO1CLR=EN;
lcd_delay();
}
void lcd_init()
{
PINSEL2 = 0x00000000;
IO1DIR = 0x03FF0000;
lcd_cmd(0x01);
lcd_cmd(0x38);
lcd_cmd(0x06);
lcd_cmd(0x0E);
lcd_cmd(0x80);
}
void lcd_data(unsigned char data)
{
IO1CLR = 0x03FF0000;
IO1SET = data<<16;
IO1SET=RS;
IO1SET=EN;
lcd_delay();
IO1CLR=EN;
lcd_delay();
}
int main()
{
int i;
lcd_init();
for(i=0;msg[i]!='\0';i++)
lcd_data(msg[i]);
}
Output
Inference
The code here is a program that uses the LCD display on the LPC2148 microcontroller.
Here are some of the things I inferred from the code: The code uses macros to define the data
and enable pins on the LCD display. This makes the code more readable and easier to maintain.
The code uses a delay function to give the LCD display time to execute commands. This is
important because the LCD display can only process commands at a certain speed. The code uses
a series of commands to initialize the LCD display. This includes setting the display mode, the
number of lines, and the cursor position. The code loops through the message array, sending each
character to the LCD display. This is how the message "WELCOME" is displayed on the LCD
display.
To display “WELCOME” in the first line and “AMRITA” in the second line of the LCD.
Source Code
#include<lpc214x.h>
#define RS 0x02000000
#define EN 0x01000000
unsigned char msg[]="WELCOME";
unsigned char msg1[]=“AMRITA";
void lcd_delay()
{
int i;
for(i=0;i<100000;i++);
}
void lcd_cmd(unsigned char cmd)
{
IO1CLR = 0x03FF0000;
IO1SET = cmd<<16;
IO1CLR=RS;
IO1SET=EN;
lcd_delay();
IO1CLR=EN;
lcd_delay();
}
void lcd_init()
{
PINSEL1 = 0x00000000;
IO1DIR = 0x03FF0000;
lcd_cmd(0x01);
lcd_cmd(0x38);
lcd_cmd(0x06);
lcd_cmd(0x0E);
lcd_cmd(0x80);
}
void lcd_data(unsigned char data)
{
IO1CLR = 0x03FF0000;
IO1SET = data<<16;
IO1SET=RS;
IO1SET=EN;
lcd_delay();
IO1CLR=EN;
lcd_delay();
}
int main()
{
int i;
lcd_init();
for(i=0;msg[i]!='\0';i++)
lcd_data(msg[i]);
lcd_cmd(0xC0);
for(i=0;msg1[i]!='\0';i++)
lcd_data(msg1[i]);
}
Output
Inference
Here are some of the things I inferred from the code: The code uses the same macros to
define the data and enable pins on the LCD display. This makes the code more readable and
easier to maintain. The code uses the same delay function to give the LCD display time to
execute commands. This is important because the LCD display can only process commands at a
certain speed. The code uses a series of commands to initialize the LCD display. This includes
setting the display mode, the number of lines, and the cursor position. The code now loops
through two message arrays, sending each character to the LCD display. This is how the two
messages are displayed on the LCD display.
Displaying “AMRITA” from C5 to CA Source Code
Source Code
#include<lpc214x.h>
#define RS 0x02000000
#define EN 0x01000000
unsigned char msg[]="Amrita";
void lcd_delay()
{
int i;
for(i=0;i<100000;i++);
}
void lcd_cmd(unsigned char cmd)
{
IO1CLR = 0x03FF0000;
IO1SET = cmd<<16;
IO1CLR=RS;
IO1SET=EN;
lcd_delay();
IO1CLR=EN;
lcd_delay();
}
void lcd_init()
{
PINSEL2 = 0x00000000;
IO1DIR = 0x03FF0000;
lcd_cmd(0x01);
lcd_cmd(0x38);
lcd_cmd(0x06);
lcd_cmd(0x0E);
lcd_cmd(0x80+0x04);
}
void lcd_data(unsigned char data)
{
IO1CLR = 0x03FF0000;
IO1SET = data<<16;
IO1SET=RS;
IO1SET=EN;
lcd_delay();
IO1CLR=EN;
lcd_delay();
}
int main()
{
int i;
lcd_init();
for(i=0;msg[i]!='\0';i++)
lcd_data(msg[i]);
}
Output
Inference
The code here is a program LPC214x microcontroller and displays the message "AMRITA"
on the LCD screen. It initializes the LCD with specific commands and settings to set up the
display properly. The code utilizes specific pins on Port 1 of the LPC214x to control the LCD's
data and commands, and it introduces appropriate delays for proper operation of the LCD. Upon
execution, the LCD will show the message "AMRITA" on its screen, demonstrating successful
interfacing and communication between the LPC214x microcontroller and the LCD.
Write a program to scroll the “AMRITA” word from left to right in the first row of the
LCD display.
Source Code
#include<lpc21xx.h>
#define RS 0X02000000
#define EN 0x01000000
void lcd_delay(){
int i;
for(i=0; i<=0x100000; i++);
}
void delay(){
int i;
for(i=0; i<0x1000; i++);
}
void lcd_init()
{
PINSEL2 = 0X00000000;
IO1DIR = 0X03FF0000;
lcd_cmd(0X01);
lcd_cmd(0x38);
lcd_cmd(0x06);
lcd_cmd(0x0C);
lcd_cmd(0x80);
}
IO1SET = EN;
delay();
IO1CLR = EN;
delay();
}
int main()
{
int i, j;
while(1)
{
lcd_init();
lcd_cmd(0x1C);
lcd_delay();
}
}
}
Output
Inference
From the code I inferred that: The code uses two macros, RS and EN, to select the data
and enable pins on the LCD display. This makes the code more readable and easier to maintain.
The code uses a delay function to give the LCD display time to execute commands. This ensures
that the commands are executed correctly. The code uses a loop to scroll the message on the
LCD display. This makes the code more efficient and easier to understand. The code includes a
main() function that tests the functionality of the functions. This ensures that the code works as
expected and that there are no bugs.
From this lab I learnt about LCD 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
display text in the LCD display and by using flash magic software we can dump the code into the
trainer kit and observe how its displays the text in the LCD display.