/////////////// RUTINA PARA LCD SIN R/W
#define LCD_D4 PIN_A5 // <<<<<< aqui se reemplazan los pines uno por uno
#define LCD_D5 PIN_A3
#define LCD_D6 PIN_A2
#define LCD_D7 PIN_A1
#define LCD_EN PIN_C4
#define LCD_RS PIN_C5
#define LCD_RW PIN_C6
// agregar esta linea en caso de que este cableado RW
#define FIRST_LINE 0x00
#define SECOND_LINE 0x40
#define CLEAR_DISP 0x01
#define CURS_ON 0x0e
#define CURS_OFF 0x0c
// deifinicion de procesos
void LCD_Init ( void );
void LCD_SetPosition ( unsigned int cX );
void LCD_PutChar ( unsigned int cX );
void LCD_PutCmd ( unsigned int cX );
void LCD_PulseEnable ( void );
void LCD_SetData ( unsigned int cX );
// rutinas para incializacio del display
void LCD_Init ( void )
{
set_tris_c ( 0x80 ); // <<<< AQUI DEBES CAMBIAR LOS DATOS DEL SET_TRIS POR LOS QUE TE QUEDAN
LCD_SetData ( 0x00 ); // limpia la variable de datos
output_low ( LCD_RS ); // selecciona el registro de control para datos
output_low ( LCD_RW ); // agregar esta linea en caso de que este cableado RW
LCD_SetData ( 0x03 ); // selecciona el display para 4 bits ( recuerde que arranca en 8 bits )
LCD_PulseEnable(); // llama a la rutina de habilitacion
LCD_PulseEnable(); // llama a la rutina de habilitacion
LCD_PulseEnable(); // llama a la rutina de habilitacion
LCD_SetData ( 0x02 ); // seleciona el dislpay para 4 bits de nuevo
LCD_PulseEnable(); // llama a la rutina de habilitacion
LCD_PutCmd ( 0x2C ); // seleciona funcion (2 lineas, caracteres 5x7 )
LCD_PutCmd ( 0x0c ); // display ON, cursor off, no blink
LCD_PutCmd ( 0x01 ); // limpiar display
LCD_PutCmd ( 0x06 ); // modo de presentacion , incrementar de izquierda a derecha
}
// rutina para el envio de comando de posicion
void LCD_SetPosition ( unsigned int cX )
{
LCD_SetData ( swap ( cX ) | 0x08 );
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
}
// rutina para el el cnvio de carateres
void LCD_PutChar ( unsigned int cX )
{
output_high ( LCD_RS );
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
output_low ( LCD_RS );
}
// rutina para el envio de comandos
void LCD_PutCmd ( unsigned int cX )
{
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
LCD_SetData ( swap ( cX ) );
LCD_PulseEnable();
}
// rutina de habilitacion NO modificar en caso de error o que no funcione
// agragar mas tiempo en Milisegundos
void LCD_PulseEnable ( void )
{
output_high ( LCD_EN );
delay_us ( 10 );
output_low ( LCD_EN );
delay_ms ( 5 );
}
// rutina para el envio de datos a 4 bits
void LCD_SetData ( unsigned int cX )
{
output_bit ( LCD_D4, cX & 0x01 );
output_bit ( LCD_D5, cX & 0x02 );
output_bit ( LCD_D6, cX & 0x04 );
output_bit ( LCD_D7, cX & 0x08 );
}