GROUP:
SOFIA FATINAH BINTI SALIM
NURUL NABILLA BINTI PUNGUT
TENG WEI FEI
INTRODUCTION
This is about PIC16F877A embedded system project. The purpose of our project is to display feeling using LCD. It can displays when we sad or happy feeling.
LIST OF HARDWARE AND SOFTWARE
HARDWARE
-lcd 16x2
-PIC16F877A
SOFTWARE
-MPlab version 8.3
-Hi-Tech C compiler version 2.3
THE CIRCUIT DIAGRAM
#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 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);
void e_pulse(void);
void lcd_clr(void);
void lcd_goto(unsigned char data);
void send_char(unsigned char data);
void send_config(unsigned char data);
void send_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("HOW DO"); //Send string "HOW DO".
lcd_goto(20); //Put cursor on position 11.
send_string; //Send string
lcd_goto(25); //Put cursor on position 20.
send_string("YOU FEEL ?"); //Send string "YOU FEEL?".
lcd_goto(27); //Put cursor on position 26.
send_string; //Send string
if(SW1==0)
{
while(SW1==0);
lcd_clr();
lcd_goto(0);
send_string("I'M");
lcd_goto(20);
send_string("HAPPY");
}
else if(SW2==0)
{
while(SW2==0);
lcd_clr();
lcd_goto(0);
send_string("I'M");
lcd_goto(22);
send_string("SAD");
}
}
//Delay function. The delay time depends on the given value.
void delay(unsigned long data)
{
for(;data>0;data-=1);
}
void e_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.
void send_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.
{
test=(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;
}
}
delay(50);
e_pulse();
}
//Clear the LCD
void lcd_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||
void lcd_goto(unsigned char data)
{
if(data<16)
{
send_config(0x80+data);
}
else
{
data=data-20;
send_config(0xC0+data);
}
delay(200);
}
//Send a character to the LCD.
void send_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;
}
}
delay(50);
e_pulse();
}
//Send a string to the LCD.
void send_string(const char *s)
{
unsigned char i=0;
while(s&&*s)
send_char(*s++);
delay(1000);
}
VIDEO
THIS VIDEO SHOW HOW TO MAKE THE CIRCUIT.
CONCLUSION
This layout has been designed that when we press switch 1, LCD will display "I'm Sad". When we press switch 2, LCD will display "I'm Happy". But sometimes this project didn't function well because of some difficulties in lab. However, our lecturer gives us advice to try finish the project and this is what we finally get in the end. Thank you.
No comments:
Post a Comment