#define output IOSET0
#define output_not IOCLR0
#define LCD_D4_H output|=(1<<3)
#define LCD_D4_L IOCLR0|=(1<<3)
#define LCD_D5_H output|=(1<<4)
#define LCD_D5_L IOCLR0|=(1<<4)
#define LCD_D6_H output|=(1<<5)
#define LCD_D6_L IOCLR0|=(1<<5)
#define LCD_D7_H output|=(1<<6)
#define LCD_D7_L IOCLR0|=(1<<6)
#define ctrl IOSET0
#define rs_H ctrl|=(1<<0)
#define rs_L IOCLR0|=(1<<0)
#define rw_H ctrl|=(1<<1)
#define rw_L IOCLR0|=(1<<1)
#define en_H ctrl|=(1<<2)
#define en_L IOCLR0|=(1<<2)
void _delay_ms(int z)
{
int x;
while (z--)
for (x=0;x<50000;x++);
}
void output_data(unsigned char xdata)
{
if(xdata&0x80) {LCD_D7_H;}else{LCD_D7_L;};
if(xdata&0x40) {LCD_D6_H;}else{LCD_D6_L;};
if(xdata&0x20) {LCD_D5_H;}else{LCD_D5_L;};
if(xdata&0x10) {LCD_D4_H;}else{LCD_D4_L;};
}
void LCD_cmd(unsigned char cmd)
{
output_data(cmd);
rs_L;rw_L;en_H; //RS AND RW =0, EN=1
_delay_ms(1);
rs_L;rw_L;en_L; //RS, RW AND EN =0
_delay_ms(1);
return;
}
void lcd_cmd(char cmd_value)
{
char cmd_value1;
cmd_value1=cmd_value&0xf0;
LCD_cmd(cmd_value1);
cmd_value1=((cmd_value<<4)&0xf0);
LCD_cmd(cmd_value1);
}
void init_lcd()
{
lcd_cmd(0x02); //4 bit mode
lcd_cmd(0x28); //2 line, 5x7 dots, 4bit mode
lcd_cmd(0x0c);
lcd_cmd(0x06);
lcd_cmd(0x80); //koordinat
lcd_cmd(0x0E); // cursor ON
return;
}
void lcd_write(unsigned char data)
{
output_data(data);
rs_H;rw_L;en_H; //RS=1 RW=0 EN=1
_delay_ms(1);
rs_H;rw_L;en_L; //RS=1 RW=0 EN=0
_delay_ms(1);
return;
}
void lcd_putc(char data_value)
{
char data_value1;
data_value1=data_value&0xf0;
lcd_write(data_value1);
data_value1=((data_value<<4)&0xf0);
lcd_write(data_value1);
}
void lcd_puts(unsigned char *str)
{
int i=0;
while(str[i]!='\0')
{
lcd_putc(str[i]);
i++;
}
return;
}
void lcd_gotoxy(unsigned char x, unsigned char y)
{
if(!x){lcd_cmd(0x80+y);}
else
{lcd_cmd(0xc0+y);};
_delay_ms(1);
return;
}
void lcd_clr()
{
lcd_cmd(0x01);
rs_L;
}