sbit LCD_RS at RE0_bit;
sbit LCD_EN at RE2_bit;
sbit LCD_D0 at RD0_bit;
sbit LCD_D1 at RD1_bit;
sbit LCD_D2 at RD2_bit;
sbit LCD_D3 at RD3_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;
// Pin direction
sbit LCD_RS_Direction at TRISE0_bit;
sbit LCD_EN_Direction at TRISE2_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D3_Direction at TRISD3_bit;
sbit LCD_D2_Direction at TRISD2_bit;
sbit LCD_D1_Direction at TRISD1_bit;
sbit LCD_D0_Direction at TRISD0_bit;
void ibusy()
{
TRISD=0xFF;
LATE2_bit=1;
LATE0_bit=0;
LATE1_bit=1;
while(LCD_D7)
{
LATE2_bit=0;
//Delay_ms(50);
LATE2_bit=1;
}
TRISD=0x00;
}
void lcmd(char xy)
{ ibusy();
LATD=xy;
LATE0_bit=0;
LATE1_bit=0;
LATE2_bit=1;
Delay_ms(20);
LATE2_bit=0;
Delay_ms(40);
// Delay_ms(100);
}
void ldata(char xy)
{ ibusy();
LATD=xy;
LATE0_bit=1;
LATE1_bit=0;
LATE2_bit=1;
Delay_ms(20);
LATE2_bit=0;
Delay_ms(40);
// Delay_ms(100);
}
void lcdinit()
{ Delay_ms(10000);
lcmd(0x38); //
Delay_ms(1000);
lcmd (0x0C); //
Delay_ms(1000);
lcmd(0x01); //
Delay_ms(1000);
lcmd(0x06); //
Delay_ms(1000);
lcmd(0x80); //
Delay_ms(1000);
}
void icmd(char xy)
{ //ibusy();
LATD=xy;
LATE0_bit=0;
LATE1_bit=0;
LATE2_bit=1;
Delay_ms(20);
LATE2_bit=0;
Delay_ms(40);
// Delay_ms(100);
}
void init()
{ Delay_ms(10000);
icmd(0x38); //
Delay_ms(1000);
icmd(0x38); //
Delay_ms(1000);
icmd(0x38); //
Delay_ms(1000);
lcmd (0x08); //
Delay_ms(1000);
lcmd(0x01); //
Delay_ms(1000);
lcmd(0x06); //
Delay_ms(1000);
lcmd(0x80); //
Delay_ms(1000);
}
void main() {
TRISD=0x00;
LATD=0x00;
TRISE=0x00; LATE=0x00;
init();
lcmd (0x0F); // Delay_ms(1000);
ldata('E');
}