#include<18f452.h>
#include<stdio.h>
#include<htc.h>
#define LCD_RS RA0;
#define LCD_E RA1;
#define LCD_Data PORTD;
__CONFIG(1,HS);
__CONFIG(2,BORDIS & WDTDIS);
//__CONFIG(3,PBDIGITAL);
__CONFIG(4,DEBUGDIS & LVPDIS & STVRDIS);
__CONFIG(5,UNPROTECT);
void delay (int i)
{
int x;
for(x=0;x<i;x++);
}
void enable()
{
RA1 = 1; //e=1;
delay(500);
RA1 = 0;//e=0;
delay(500);
}
void write(char data, int add)
{
//address locate
RA0=0; //rs=0
PORTD=add;
enable();
//write data to LCD
RA0=1; //rs=1
PORTD=data;
enable();
}
void init()
{
//LCD 16*2
delay(20000);
RA0=0;
PORTD=0x38;
enable();
//clear
RA0=0;
PORTD=0x01;
enable();
//cursor shift right
RA0=0;
PORTD=0x06;
enable();
//Display LCD
RA0=0;
PORTD=0x0c;
}
void main()
{
TRISA = 0b00000000;
TRISB = 0b11111111;
TRISC = 0b00000000;
TRISD = 0b00000000;
init();
while(1)
{
write('M',0x80);
write('A',0x81);
write('D',0x82);
write('-',0x83);
write(' ',0x84);
write('3',0x85);
write('f',0x86);
write('4',0x87);
write('M',0x89);
write('M',0x8A);
while(1);
}
}