CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Library - driver for LCD with PIC18FXXX

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
JEliecer



Joined: 08 Feb 2005
Posts: 17
Location: Bucaramanga - Colombia

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger

Library - driver for LCD with PIC18FXXX
PostPosted: Fri Feb 25, 2005 9:30 am     Reply with quote

////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// LCDPIC18.C //
// DRIVER FOR LCD WITH PIC 18FXXX //
// //
// lcd_init() Debe ser llamada antes que las otras funciones. //
// //
// lcd_putc(c) Visualiza c en la siguiente posición del display. //
// Caracteres especiales de control: //
// \f Borrar display //
// \n Saltar a la segunda linea //
// \b Retroceder una posición. //
// //
// lcd_gotoxy(x,y) Selecciona nueva posición de escritura //
// (la esquina superior izquierda es 1,1) //
// //
// lcd_getc(x,y) Devuelve el caracter de la posición x,y del display.//
// //
// LCD (pin) PIC (pin) //
// 1 GND ----- //
// 2 VCC ----- //
// 3 Contrast ----- //
// 4 RS RA0 //
// 5 RW RA1 //
// 6 ENABLE RA2 //
// 7 D0 RB0 //
// . . . //
// . . . //
// . . . //
// 14 D7 RB7 //
// Si existen: //
// 15 VCC LIGTH //
// 16 GND LIGTH //
// //
//////////////////////////////////////////////////////////////////////////


#bit lcd_enable = 0xF80.2
#bit lcd_rw = 0xF80.1
#bit lcd_rs = 0xF80.0
#byte lcd_a = 0xF80
#byte lcd_b = 0xF81

#define LCD_LINEA2 0x40 // Dirección de memoria para la segunda línea
#define LCD_DATO 1
#define LCD_COMANDO 0

#define LCD_CLEAR 0x01 //Borra el LCD
#define LCD_HOME 0x02 //Envía el cursor a la posición (1,1)

#define LCD_DISPLAY_OFF 0x08 //Apaga el LCD
#define LCD_DISPLAY_ON 0x0C //Enciende el LCD
#define LCD_CURSOR_ON 0x0E //Visualiza el Cursor
#define LCD_CURSOR_BLINK 0x0F //El cursor [spam]íla

#define LCD_CURSOR_SHIFT_RIGHT 0x10 //Para posicionar el cursor
#define LCD_CURSOR_SHIFT_LEFT 0x14 //Para posicionar el cursor
#define LCD_DISPLAY_SHIFT_RIGHT 0x18 //Para posicionar el cursor
#define LCD_DISPLAY_SHIFT_LEFT 0x1C //Para posicionar el cursor

//Rutina para leer los datos del LCD
int lcd_leer()
{
int valor;
set_tris_a(0x18);
set_tris_b(0xFF);
lcd_rw = 1;
delay_cycles(1);
lcd_enable = 1;
delay_cycles(1);
valor = lcd_b;
lcd_enable = 0;
delay_cycles(1);
set_tris_b(0x00);
return valor;
}
//Función para enviar datos al LCD
void lcd_enviar(int dir, int valor)
{
set_tris_a(0x00);
set_tris_b(0x00);
lcd_rs = 0;
while( bit_test(lcd_leer(),7) );
lcd_rs = dir;
delay_cycles(1);
lcd_rw = 0;
delay_cycles(1);
lcd_enable = 0;
lcd_b = valor;
delay_cycles(1);
lcd_enable = 1;
delay_us(2);
lcd_enable = 0;
}
//RUTINA DE INICIO DEL LCD
void lcd_init()
{
int i;
set_tris_a(0x18);
set_tris_b(0x00);
lcd_enable = 0;
lcd_rw = 0;
lcd_rs = 0;
delay_ms(15);
for(i=0; i<3; i++)
{
lcd_enviar(LCD_COMANDO,0x38);
delay_ms(5);
}
lcd_enviar(LCD_COMANDO,LCD_DISPLAY_ON);
lcd_enviar(LCD_COMANDO,0x06);
lcd_enviar(LCD_COMANDO,LCD_CLEAR);
lcd_enviar(LCD_COMANDO,LCD_HOME);
}
//Rutina para enviar datos a una posicion especifica en el LCD
void lcd_gotoxy( byte x, byte y)
{
byte dir;
if(y!=1)
dir=LCD_LINEA2;
else
dir=0;
dir+=x-1;
lcd_enviar(LCD_COMANDO,0x80|dir);
}
//Rutina para enviar caracteres al LCD
void lcd_putc( char c)
{
switch (c)
{
case '\f' : lcd_enviar(LCD_COMANDO,0x01);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2);
break;
case '\b' : lcd_enviar(LCD_COMANDO,0x10);
break;
default : lcd_enviar(LCD_DATO,c);
break;
}
}
char lcd_getc( int x, int y)
{
char valor;
lcd_gotoxy(x,y);
lcd_rs = 1;
valor = lcd_leer();
lcd_rs = 0;
return valor;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
//// LCD448.C ////
//// ////
//// Este programa lee y escribe en un LCD ////
//// Utilizando la libreria LCDPIC18.C ////
//// ////
//// sOLO QUEMALO Y FUNCIONA ////
//// ////
//// Para información contactame en jeliecer_2001@hotmail.com ////
//// ////
////////////////////////////////////////////////////////////////////////////
#include <18f448.h>

#use delay(clock=20000000,RESTART_WDT)

#include <lcdpic18.c>

#use fast_io(A)
#use fast_io(B)

//#byte PORTA = 0xf80
//#byte PORTB = 0xf81
//#byte PORTC = 0xf82


void main(void)
{

lcd_init(); // Comandos de inicialización del LCD.

while(1)
{
restart_wdt();
lcd_enviar(LCD_COMANDO, LCD_CLEAR);
delay_ms(2);
lcd_enviar(LCD_COMANDO, LCD_HOME);
delay_ms(2);
lcd_putc(" SoY Un MaLdItO GeNiO\n"); // con \n salta a la segunda línea
lcd_putc("...Si O No InIs JoSE...");
delay_ms(4000);

restart_wdt();
lcd_enviar(LCD_COMANDO, LCD_CLEAR);
delay_ms(2);
lcd_enviar(LCD_COMANDO, LCD_HOME);
delay_ms(2);
lcd_putc(" PoNgAsE A TrAbAjAr\n");
//lcd_gotoxy(5,2); // Otra forma de saltar a la segunda línea
lcd_putc(" PoRqUe AuN No Ha HeChO");
delay_ms(4000);

restart_wdt();
lcd_enviar(LCD_COMANDO, LCD_CLEAR);
delay_ms(2);
lcd_enviar(LCD_COMANDO, LCD_HOME);
delay_ms(2);
lcd_putc(" Ni UnA PuTa MiErDa Y...\n");
lcd_putc("...EsToy QuE Lo MaTo...");
delay_ms(4000);

restart_wdt();
lcd_enviar(LCD_COMANDO, LCD_CLEAR);
delay_ms(2);
lcd_enviar(LCD_COMANDO, LCD_HOME);
delay_ms(2);
lcd_putc(" PaRa QuE ApReNdA a SeR\n");
lcd_putc(" RESPONSABLE");
delay_ms(4000);
}
}


Si tienes preguntas contactame JELIECER_2001@HOTMAIL.COM
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group