LCD DISPLAY
NUR FIKRIYAH BINTI HASHIM 01DNS15F1034
NUR ARINA AMANI BINTI MOHD OTHMAN 01DNS15F1038
SHRMILA A/P JAYAGOBI 01DNS15F1031
Introduction
The character of LCD offers display numerical information,
text message and also special symbol. We can control a LCD using either 8 pins
or 4 pins, depending on the I/O pins that we have. Before using the LCD for
display purpose, LCD has to be initialized either by the internal reset circuit
or sending the commands to initialize the LCD.
List of Hardware, Software
& Components
Hardware
2.
PIC16F877A
Software
1.
MPLAB IDE v8.83
2.
Hi-Tech C
Compiler v2.3
Circuit Diagram
The Coding
#include<htc.h>
//--------------
CONFIGURATION -----------------------------------------
__CONFIG (0x3F3A);
//-------------- DEFINE THE
I/O PIN ------------------------------------
#define RS RA2 //RS pin of
the LCD display
#define E RA3 //E pin of the
LCD display
#define b_light RA1
#define lcd_data PORTD
#define d0 RD0
#define d1 RD1
#define d2 RD2
#define d3 RD3
#define d4 RD4
#define d5 RD5
#define d6 RD6
#define d7 RD7
#define SW1 RB0
#define SW2 RB1
//-------------- DEFINE
VARIABLE DEFINITION --------------------------
//-------------- FUNCTION
PROTOTYPE ----------------------------------
void delay(unsigned long
data);
voide_pulse(void);
voidlcd_clr(void);
voidlcd_goto(unsigned char
data);
voidsend_char(unsigned char
data);
voidsend_config(unsigned char
data);
voidsend_string(const char
*s);
//-------------- MAIN
FUNCTION (WRITE YOUR PROGRAM HERE) ---------------
void main()
{ //set I/O input output
TRISA=0b00000000; //Configure
PORTA I/O direction
TRISB=0b00000111; //Configure
PORTB I/O direction
TRISD=0b00000000; //Configure
PORTD I/O direction
TRISE=0b00000000;
PORTA=0;
PORTB=0;
PORTC=0;
PORTD=0;
PORTE=0;
//setup ADC
ADCON1=0b00000110;
//set RA2, RA3 as digital and
rest remain as analog I/O.
//Ensure pin share with
analog is being configured to digital correctly
//Configure the LCD
send_config(0b00000001);
//clear the LCD.
send_config(0b00000010);
//Return cursor to home.
send_config(0b00000110);
//Entry mode, cursor increase 1.
send_config(0b00001100);
//Display on,cursor off and cursor blink off.
send_config(0b00111000);
//Function set.
lcd_clr(); //Clear the LCD.
lcd_goto(2); //Put cursor on
position 0.
send_string("HI WE ARE
DNS4A:"); //Send string "HI WE ARE DNS4A".
lcd_goto(20); //Put cursor on
position 11.
send_string("PUO");
//Send string "PUO".
lcd_goto(25); //Put cursor on
position 20.
send_string("&");
//Send string "&".
lcd_goto(27); //Put cursor on
position 26.
send_string("FROM JTMK
PUO"); //Send string "FROM JTMK PUO".
b_light=1;
while(1)
{
if(SW1==0)
{
while(SW1==0);
lcd_clr();
lcd_goto(0);
send_string("DIS
16");
lcd_goto(20);
send_string("MY NAME IS
NUR FIKRIYAH ");
}
else if(SW2==0)
{
while(SW2==0);
lcd_clr();
lcd_goto(0);
send_string("MY NAME IS
ARINA ");
lcd_goto(22);
send_string("MY NAME IS
SHRMILA");
}
}}
//Delay function. The delay
time depends on the given value.
void delay(unsigned long
data)
{
for(;data>0;data-=1);
}
voide_pulse(void) //Send a
pulse to the E pin of the LCD.
{
E=1;
delay(50);
E=0;
delay(50);
}
//Send the configuration to
the LCD.
voidsend_config(unsigned char
data)
{
unsigned char test;
unsigned char i;
RS=0; //Clear RS pin for
config mode.
for(i=0;i<8;i++) //Loop
for 8 times.
{t
est=(data>>i)&0b00000001;
//Shift data to right.
switch(i) //Detect a byte of
data one bit by one bit.
{
case 0:
if(test==1) d0=1;
else d0=0;
case 1:
if(test==1) d1=1;
else d1=0;
case 2:
if(test==1) d2=1;
else d2=0;
case 3:
if(test==1) d3=1;
else d3=0;
case 4:
if(test==1) d4=1;
else d4=0;
case 5:
if(test==1) d5=1;
else d5=0;
case 6:
if(test==1) d6=1;
else d6=0;
case 7:
if(test==1) d7=1;
else d7=0;
}
}d
elay(50);
e_pulse();
}
//Clear the LCD
voidlcd_clr(void)
{
send_config(0x01);
delay(600);
}
//Set the location of the LCD
cursor.
//If the given value is
(0-15) the cursor will be at the upper line.
//If the given value is
(20-35) the cursor will be at the lower line.
//Location of the lcd cursor
(2x16):
//
-----------------------------------------------------------
//
||00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15||
//
||20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35||
voidlcd_goto(unsigned char
data)
{
if(data<16)
{s
end_config(0x80+data);
}
else
{d
ata=data-20;
send_config(0xC0+data);
}d
elay(200);
}
//Send a character to the
LCD.
voidsend_char(unsigned char
data)
{
unsigned char test;
unsigned char i;
RS=1;
//Set RS for data mode.
for(i=0;i<8;i++) //Loop
for 8 times.
{
test=(data>>i)&0b00000001;
//Shift data to right.
switch(i) //Detect data one
bit by one bit.
{
case 0:
if(test==1) d0=1;
else d0=0;
case 1:
if(test==1) d1=1;
else d1=0;
case 2:
if(test==1) d2=1;
else d2=0;
case 3:
if(test==1) d3=1;
else d3=0;
case 4:
if(test==1) d4=1;
else d4=0;
case 5:
if(test==1) d5=1;
else d5=0;
case 6:
if(test==1) d6=1;
else d6=0;
case 7:
if(test==1) d7=1;
else d7=0;
}
}d
elay(50);
e_pulse();
}
//Send a string to the LCD.
voidsend_string(const char
*s)
{
unsigned char i=0;
while(s&&*s)
send_char(*s++);
delay(1000);
}
CONCLUSION
This project enable us to
gain experience in electronic circuit and designing. It also enabled to
understand properly on how the different circuit element works. However, a lot of
difficulties were encountered in the process of realizing the project work like
putting the components correctly in the board.
No comments:
Post a Comment