void enable();
void init_lcd();
void data_map(char);
void command_write(unsigned char);
void data_write(unsigned char);
void swap(char );
void delay(unsigned int);
void delay_us(unsigned int del);
#define rs PORTCbits.RC0
#define rw PORTCbits.RC1
#define E PORTCbits.RC2
void init_lcd()
{
delay(15);
command_write(0x03);
delay(5);
command_write(0x03);
delay(5);
command_write(0x03);
delay(5);
command_write(0x02);
delay(5);
command_write(0x28);
delay(5);
command_write(0x01);
delay(5);
command_write(0x0c);
delay(5);
}
void data_map(unsigned char ds)
{
unsigned char ab;
ab=ds;
PORTC = PORTC & 0x0f;
ab=ab&0xf0;
PORTC =ab | PORTC;
}
void command_write(unsigned char c_dt)
{
rs = 0;
rw = 0;
data_map(c_dt);
enable();
c_dt=c_dt<<4;
data_map(c_dt);
enable();
}
void data_write( char d_dt)
{
rs = 1;
rw = 0;
data_map(d_dt);
enable();
d_dt=d_dt<<4;
data_map(d_dt);
enable();
}
void delay(unsigned int val)
{
unsigned int n,m;
for(n=0;n<val;n++)
for(m=0;m<=120;m++);
}
void enable()
{
E = 1;
delay_us(10);
E = 0;
}
void print(unsigned char *ptr,unsigned char addr)
{
command_write(addr);
while(!(*ptr=='\0'))
{
data_write(*ptr++);
delay(2);
}
}
void delay_us(unsigned int del)
{
for(;del>0;del--);
}