Exp.2: LCD interfacing with PIC18F controller
CODE
#include <p18f4550.h>
#define EN LATAbits.LA1
#define RS LATAbits.LA0
#define LCD LATB
void delay(unsigned int time)
{
unsigned int i , j ;
for(i = 0; i < time; i++)
for(j=0;j<1000; j++);
}
void LCDcommand(unsigned char command)
{
RS = 0; // RS low : Instruction
LCD = command;
EN = 1; // EN High
delay(10);
EN = 0; // EN Low
delay(10);
}
void LCDdata(unsigned char data)
{
RS = 1; // RS HIGH : DATA
LCD = data;
EN = 1; // EN High
delay(10);
EN = 0; // EN Low; data sampled at EN falling edge
delay(10);
}
void main(void)
{ ADCON1 = 0x0F;
TRISB = 0x00; //set data port as output
TRISAbits.RA0 = 0; //RS pin
TRISAbits.RA1 = 0; // EN pin
unsigned char *String1 = " Embeddedsystem";
LCDcommand(0x38); //8 bit mode, 2 line,5x7 dots
LCDcommand(0x06); // entry mode
LCDcommand(0x0C); //Display ON cursor OFF
LCDcommand(0x01); //Clear display
LCDcommand(0x80); //set address to 1st line
while(*String1)
{
LCDdata(*String1);
String1++;
}
while(

Comments
Post a Comment