#include "lcd.h"
void LCD_init()
{
LCD_cmd(0x20); // 4 bit
LCD_cmd(0x28); // display shift
LCD_cmd(0x6); // character mode
LCD_cmd(0xc); // display on / off and cursor
LCD_clr(); // clear display
}
void LCD_goto(char line, char column) // combines line and lineW
{
unsigned char data = 0x80; // default to 1
if(line == 2)data = 0xc0; // change to 2
data += column; // add in column
LCD_cmd(data);
}
void LCD_clr()
{
LCD_cmd(1); // Clr screen
}
void LCD_cur(char on)
{
unsigned char cur = 0xc; // cursor off
if(on) cur = 0xd; // cursor on
LCD_cmd(cur);
}
void LCD_cmd(unsigned char ch)
{
LCD_PORT = ch & 0xf0; // write high nibble
LCD_RS = 0;
pulse_E();
LCD_PORT = ch <<4 & 0xf0; // write low nibble
LCD_RS = 0;
pulse_E();
Delay5MS();
}
void LCD_char(unsigned char ch)
{
LCD_PORT = ch & 0xf0; // write high nibble
LCD_RS = 1;
pulse_E();
LCD_PORT = ch <<4 & 0xf0; // write low nibble
LCD_RS = 1;
pulse_E();
Delay5MS();
}
void LCD_charD(unsigned char ch)
{
ch+=0x30;
LCD_char(ch); // convert to ascii
}
void pulse_E()
{
LCD_E = 1;
Delay1US();
LCD_E = 0;
}
void string(const char *q,const int satir)
{
int sayac=0;
while (*q) {
LCD_goto(satir,sayac);
LCD_char(*q++);
sayac++;
}
}