Version:0.9 StartHTML:0000000105 EndHTML:0000012726 StartFragment:0000001215 EndFragment:0000012710 mikroElektonika
/*************************************
librería calculadora LCD + teclado
para un nucleo PIC
PORTB= D7..4 y filas teclado por defecto
RB3 = EN
RB2 = RS
PORTA 0..3=columnas teclado
RW =0; sólo escritura...
**************************************/
#ifndef data_port
    #define data_port PORTB
#endif

#ifndef data_tris
    #define data_tris TRISB
#endif

#ifndef EN
    #define EN PORTB.F3
#endif
#ifndef ENt
    #define ENt TRISB.F3
#endif

#ifndef RS
    #define RS PORTB.F2
#endif
#ifndef RSt
    #define RSt TRISB.F2
#endif

#define Lcd_Pos(F,C) Lcd_comando(0x80+(F)*0x40+(C))
#define Lcd_printf(F,C,Cadena) Lcd_Pos(F,C);Lcd_print(Cadena);
#define Lcd_printfc(F,C,Cadena) Lcd_Pos(F,C);Lcd_printc(Cadena);

char guarda_tris;

void Lcd_escribe(char dato){
    guarda_tris=data_tris;
    data_tris=data_tris & 0x0f;
    data_port=dato & 0xf0 | data_port & 0x0f;
    EN=1;
    EN=0;
    data_tris=guarda_tris;}

void Lcd_envia(char dato){
    Lcd_escribe(dato);
    asm swapf FARG_Lcd_envia,1;
    Lcd_escribe(dato);
    Ret_usx10(2);}

void Lcd_comando(char comando){
    RS=0;
    Lcd_envia(comando);
    if(comando==1)Ret_ms(2);}

void Lcd_caracter(char caracter){
    RS=1;
    Lcd_envia(caracter);}

void Lcd_Inicia(){
    RSt=0;
    ENt=0;
    EN=0;
    RS=0;
    Ret_ms(20);
    Lcd_escribe(0x30);
    Ret_ms(5);
    Lcd_escribe(0x30);
    Ret_usx10(30);
    Lcd_escribe(0x30);
    Ret_usx10(3);
    Lcd_escribe(0x20);
    Lcd_comando(0x28);
    Lcd_comando(LCD_BLINK_CURSOR_ON);
    Lcd_comando(LCD_CLEAR);
    Lcd_comando(LCD_FIRST_ROW);}

void lcd_print(char *cadena){
	while (*cadena!=0)
        Lcd_caracter(*cadena++);}

void lcd_printc(const char *cadena){
    while (*cadena!=0)
        Lcd_caracter(*cadena++);}