/* 
 * File:   LCD.h
 * Author: patrik
 *
 * Created on 25 June 2015, 19:02
 */

#ifndef LCD_H
#define	LCD_H
#define byte unsigned char

#ifdef	__cplusplus
extern "C" {
#endif
void delay(int varakozasIdo)
{
  for (int counter = 0; counter < varakozasIdo; counter++)
  {
      ;
  }
}
void lcdParancs(byte adat)
{
RC1 = 0; //RS
RC0 = 0; //R/W (utasítást írunk)
if (adat & 0x80) PORTA |= 0x20; else PORTA &=~0x20; //D7(RA5)
if (adat & 0x40) PORTA |= 0x10; else PORTA &=~0x10; //D6(RA4)
if (adat & 0x20) PORTC |= 0x40; else PORTC &=~0x40; //D5(RC6)
if (adat & 0x10) PORTC |= 0x20; else PORTC &=~0x20; //D4(RC5)
if (adat & 0x08) PORTC |= 0x10; else PORTC &=~0x10; //D3(RC4)
if (adat & 0x04) PORTC |= 0x08; else PORTC &=~0x08; //D2(RC3)
if (adat & 0x02) PORTA |= 0x01; else PORTA &=~0x01; //D1(RA0)
if (adat & 0x01) PORTA |= 0x02; else PORTA &=~0x02; //D0(RA1)

delay(1); // Data setup time min. 195 ns
RA2 = 1;
delay(1); // E pulse width min. 450 ns
RA2 = 0;
delay(7); // 50 us // Address, Data hold time, Cicle time, execution time
}
void lcdAdat(byte adat)
{
RC1 = 1; //RS
RC0 = 0; //R/W (adatot írunk)
if (adat & 0x80) PORTA |= 0x20; else PORTA &=~0x20; //D7
if (adat & 0x40) PORTA |= 0x10; else PORTA &=~0x10; //D6
if (adat & 0x20) PORTC |= 0x40; else PORTC &=~0x40; //D5
if (adat & 0x10) PORTC |= 0x20; else PORTC &=~0x20; //D4
if (adat & 0x08) PORTC |= 0x10; else PORTC &=~0x10; //D3
if (adat & 0x04) PORTC |= 0x08; else PORTC &=~0x08; //D2
if (adat & 0x02) PORTA |= 0x01; else PORTA &=~0x01; //D1
if (adat & 0x01) PORTA |= 0x02; else PORTA &=~0x02; //D0

delay(1); // Data setup time min. 195 ns
RA2 = 1;
delay(1); // E pulse width min. 450 ns
RA2 = 0;
delay(7); // 50 us
}
void lcdInit()
{
    ANSEL = ANSELH = 0;
    TRISC = TRISA = 0;
    delay(5000);
    lcdParancs(0b00111000); //funkció beállítás
    delay(3);
    lcdParancs(0b00111000); //funkció beállítás
    delay(3);
    lcdParancs(0b00001100); //kijelzõ beállítás
    delay(3);
    lcdParancs(0b00000001); //kijelzõ törlés
    delay(100);
    lcdParancs(0b00000110); //entry mód beállítás
    delay(100);
}
void lcdSzoveg(unsigned char *s)
{
    while(*s)
    {
        lcdAdat(*s);//send character pointed to by c
        s++;//increase pointer location to the next character
    }
}



#ifdef	__cplusplus
}
#endif

#endif	/* LCD_H */

