jueves, 25 de octubre de 2012

sdcc easypic2 lcd 4 bits

lcd.h
#include <pic16f877a.h>

#define SET    0b00100000
#define CLS    0b00000001
#define HOME   0b00000010
#define MODO   0b00000110
#define SHIFT  0b00011100
#define CurON  0b00001110
#define CurOFF 0b00001100 

#define RS  RD0
#define E   RD1
#define BL  RD2


void enable()
{
  //-- Hay que garantizar un tiempo minimo de 500ns
  //-- A 20Mhz, las instrucciones tardan 200ns.
  //-- Por eso nos curamos en salud y repetimos la instruccion
  //-- tres veces. 
  E=1; E=1; E=1;
  E=0; E=0; E=0;
}

/*--------------------------------*/
void lcd_cmd(unsigned char cmd,unsigned int led){
 unsigned int aux; 
 aux=cmd;
 aux>>=4;
 aux<<=4;
 PORTD=aux;
 RS=0;
 enable();
 aux=cmd;
 aux<<=4;
 PORTD=aux;
 RS=0;
 enable();
 BL=led;
 delay(5); 
}
void lcd_write(unsigned char car,unsigned int led)
{ 
 unsigned int aux; 
 aux=car;
 aux>>=4;
 aux<<=4;
 PORTD=aux;
 BL=led;
 RS=1;
 enable();
 aux=car;
 aux<<=4;
 PORTD=aux;
 BL=led;
 RS=1;
 enable();
 delay(5); 
}

void print_lcd(unsigned char *cad,unsigned int led)
{
  unsigned char i=0;

  while (cad[i]!=0) {
    lcd_write(cad[i],led);
    i++;
  }
}

void print_xy(unsigned int DDRAM,unsigned int led)
{
 unsigned int aux;
 aux = 0b10000000 | DDRAM ;
 lcd_cmd(aux,led);
}

No hay comentarios:

IRC

#freenode->#usljujuy

Seguidores

Eventos n_n

Tira Ecol Nano,Bilo y Luca