Practica lcd, mostrar palabras en pantalla
Enviado por mad alva • 23 de Febrero de 2020 • Práctica o problema • 686 Palabras (3 Páginas) • 198 Visitas
sbit Soft_I2C_Sda at RC4_bit ;
sbit Soft_I2C_Scl at RC3_bit;
sbit Soft_I2C_Sda_Direction at TRISC4_bit;
sbit Soft_I2C_Scl_Direction at TRISC3_bit;
// PINES USADOS EN EL PCF8574
// P7, P6, P5, P4 = Data, P3=Backlight (BL), P2=E, P1=RW, P0=RS
#define LCD_ADDR 0x4E //direccion del i2c A2A1A0 1
//#define LCD_ADDR 0x7E //direccion del i2c 0b0100 A2A1A0 0
#define LCD_BL 0x08
#define LCD_EN 0x04
#define LCD_RS 0x01
//funcion que escribe en el PCF8574
I2C_PCF8574_Write(unsigned char Adr,unsigned char value)
{
I2C1_Start();
I2C1_Wr( Adr );
I2C1_Wr(value);
I2C1_Stop();
}
void I2C_LCD_Cmd(char out_char)
{
unsigned char lcddata;
//Coloca 4 bit alto
lcddata = (out_char & 0xF0)|LCD_BL;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
// RE=0
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
// Coloca los 4 bits bajo
lcddata = ((out_char << 4) & 0xF0)|LCD_BL;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
// ESCRIBE PULSO DE RE
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
}
void I2C_LCD_init()
{
unsigned char lcddata;
Soft_I2C_Init();
Delay_ms(20); //retardo de inicializacion
// INICIA PROCESO DE INICIALIZACION
lcddata=0x30;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN); //envia comando de inicializacion
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(5);
lcddata=0x30;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN); //envia comando de inicializacion
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(5);
lcddata=0x30;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN); //envia comando de inicializacion
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(5);
//modo a 4 bits
lcddata=0x20;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
//modo a 4 lineas
lcddata=0x20;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
lcddata=0x80;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(5);
//Apaga el LCD
lcddata=0x00;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
lcddata=0x80;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
//Prende el LCD
lcddata=0x00;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
lcddata=0xC0;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
//Ajusta desplazamiento del cursor
lcddata=0x00;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
lcddata=0x20 | LCD_BL;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
I2C_PCF8574_Write(LCD_ADDR,lcddata & ~LCD_EN);
Delay_ms(1);
//Borra la pantalla
lcddata=0x00;
I2C_PCF8574_Write(LCD_ADDR,lcddata | LCD_EN);
Delay_ms(1);
...