Autor Tema: Inicializacion LCD WH 1602 Winstar y PIC18F4431  (Leído 1668 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado delbarco

  • PIC10
  • *
  • Mensajes: 2
Inicializacion LCD WH 1602 Winstar y PIC18F4431
« en: 10 de Noviembre de 2013, 21:04:12 »
Buenas, soy nuevo en el foro.

Estoy tratando de inicializar un display con un PIC18F4431 sin resultados hasta ahora, mas que los cuadraditos negros.

Uso 8 bits y RS, RW y E, el ajuste de contraste está conectado y al parecer funcionando bien. Supuestamente el display tiene incluido el controlador ST7066U, por lo menos es lo que me confirmaron de fábrica por mail.

El codigo es el siguiente:
Código: [Seleccionar]
#include <p18f4431.h>

#include <delays.h>
#include "confbits.h"

//************
//XTAL 10MHz HSPLL=OFF
//***************


#define write_RW   LATDbits.LATD2   //   RW PIN21
#define TRIS_RW    DDRDbits.RD2    // TRIS  RW
#define write_RS   LATDbits.LATD3   //   RS PIN 22
#define TRIS_RS    DDRDbits.RD3    // TRIS  RS
#define write_E    LATCbits.LATC4   // E  PIN 23
#define TRIS_E     DDRCbits.RC4    // TRIS  E 


#define LED       LATDbits.LATD1      // PIN 20
#define LED_tris  DDRDbits.RD1   


#define DATA_PORT      LATB
#define TRIS_DATA_PORT TRISB
#define READ_PORT      PORTB

long i,b,busy;

void Delay30TCY(void){  // delay 30TCY mas de 37us
Delay10TCYx(3);
}
void Delay50ms(void){    //delay  de 50ms
Delay1KTCYx(125);
}
void Delay2ms(void){
Delay1KTCYx(5);           // delay  de 2ms
}

void isbusy(void){               // busy?

    TRIS_DATA_PORT=0b11111111;     //Puerto como ENTRADA
        write_RS=0;           //rs=0
        write_RW=1;           //rw=1
        write_E=1;            //e=1
        while(busy==0)
          { 
            if(READ_PORT&0b10000000)
               busy=1;
           }     
        write_E=0;            //e=0   
         
}




void main(void){         //*************COMIENZO PROGRAMA

busy=0;
LED_tris = 0;  //salida
LED=1;           //led encendido

TRIS_DATA_PORT=0;     //Puerto como SALIDA
DATA_PORT=0;

TRIS_RW=0;
TRIS_RS=0;
TRIS_E=0;
 

//*******Inicializacion LCD WH1602A -YYH-STK       

        Delay50ms;                        // pide delay de mas de 40ms

//***************1**********************
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=1;            //e=1
        DATA_PORT=0b00111000;  //Function Set 8 BIT, 2 lineas 5x8
        write_E=0;            //e=0
        Delay30TCY;           //delay de mas de 37us

//***************2**********************
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=1;            //e=1
        DATA_PORT=0b00111000;  //Function Set 8 BIT, 2 lineas 5x8
        write_E=0;            //e=0
        Delay30TCY;           //delay de mas de 37us

//***************3**********************
//a partir de ahora se puede verificar BUSY
           
        isbusy;       
        TRIS_DATA_PORT=0b00000000;     //Puerto como SALIDA 
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=1;            //e=1
        DATA_PORT=0b00001111;  //DISPLAY ON/OFF CONTROL
        write_E=0;            //e=0
        Delay30TCY;           //delay de mas de 37us

//***************4**********************
        isbusy;       
        TRIS_DATA_PORT=0b00000000;     //Puerto como SALIDA 
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=1;            //e=1
        DATA_PORT=0b00000001;  //DISPLAY CLEAR
        write_E=0;            //e=0
        Delay2ms;           //delay de 2ms

//***************5**********************
        isbusy;       
        TRIS_DATA_PORT=0b00000000;     //Puerto como SALIDA 
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=1;            //e=1
        DATA_PORT=0b00000101;  //ENTRY MODE SET
        write_E=0;            //e=0
        Delay2ms;           //delay de 2ms

//*****FINAL INICIALIZACION


//******SET DDRAM ADDRESS

 
        isbusy;
        TRIS_DATA_PORT=0b00000000;  //Puerto como SALIDA 
        write_RS=0;                 //rs=0
        write_RW=0;                 //rw=0
        write_E=1;                  //e=1
        DATA_PORT=0b10000100;       // address "03"
        write_E=0;                  //e=0
        Delay2ms;                   //delay de 2ms

        isbusy;
        TRIS_DATA_PORT=0b00000000;  //Puerto como SALIDA 
        write_RS=1;                 //rs=1
        write_RW=0;                 //rw=0
        write_E=1;                  //e=1
        DATA_PORT=65;               //ASCII para "A"
        write_E=0;                  //e=0
        Delay2ms;                   //delay de 2ms
     


while(1) 
 {                                 //LED toggle
 

for(i=0;i<700000;i++)
     {_asm nop _endasm
      }         

if (LED==1)
      LED=0;
     else
        LED=1;





}



}

Los bits de configuracion se encuentran por separado en un archivo .h distinto

Código: [Seleccionar]
#ifndef CONF_BITS_H
#define CONF_BITS_H

//#define WRITE_PROTECT


#pragma config T1OSCMX  = ON
#pragma config OSC   = HS//PLL // el PLL esta seteado por hardware en la programacion
#pragma config BOREN   = ON // si cae la tension se resetea
#pragma config PWRTEN  = ON // para que espere un toque antes de encender
#pragma config WDTEN   = OFF // no quiero al perrito
#pragma config STVREN  = ON // si hay overflow de stack se resetea
#pragma config LVP   = OFF // si este esta en ON no anda!!!!!!!
#pragma config DEBUG = ON // para poder usar el ICD2


#ifdef WRITE_PROTECT

#pragma config CP0    = ON //read code protect
#pragma config CP1    = ON
#pragma config CP2    = ON
#pragma config CP3    = ON
#pragma config CPB    = ON
#pragma config CPD    = ON

#pragma config WRT0  = ON //write code protect
#pragma config WRT1  = ON
#pragma config WRT2  = ON
#pragma config WRT3  = ON
#pragma config WRTC  = ON
#pragma config WRTB  = ON
#pragma config WRTD  = ON

#pragma config EBTR0 = ON
#pragma config EBTR1 = ON
#pragma config EBTR2 = ON
#pragma config EBTR3 = ON
#pragma config EBTRB = ON

#else

#pragma config CP0    = OFF //read code protect
#pragma config CP1    = OFF
#pragma config CP2    = OFF
#pragma config CP3    = OFF
#pragma config CPB    = OFF
#pragma config CPD    = OFF

#pragma config WRT0  = OFF //write code protect
#pragma config WRT1  = OFF
#pragma config WRT2  = OFF
#pragma config WRT3  = OFF
#pragma config WRTC  = OFF
#pragma config WRTB  = OFF
#pragma config WRTD  = OFF

#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTR2 = OFF
#pragma config EBTR3 = OFF
#pragma config EBTRB = OFF
#endif  //WRITE_PROTECT

#endif //CONF_BITS_H

Trate de cambiar los delays y el codigo varias veces pero sin llegar a nada, no creo que el display este roto ya que es nuevo (a menos que lo haya podido quemar durante las pruebas).

Cualquier ayuda será bien recibida.

Saludos,

Tito

Desconectado delbarco

  • PIC10
  • *
  • Mensajes: 2
Re: Inicializacion LCD WH 1602 Winstar y PIC18F4431
« Respuesta #1 en: 13 de Noviembre de 2013, 17:19:23 »

Finalmente pude inicializar el display y escribir en el mismo. Tuve ayuda de otro foro, pero como siempre entré para ver aca para ver algunas cosas posteo el codigo que hice.
Sobre todo porque es muy dificil encontrar algo de codigo de inicializacion para el WH 1602 de Winstar.

Código: [Seleccionar]
#include <p18f4431.h>

#include <delays.h>
#include "confbits.h"

//************
//XTAL 10MHz HSPLL=OFF
//***************


#define write_RW   LATDbits.LATD2   //   RW PIN21
#define TRIS_RW    DDRDbits.RD2    // TRIS  RW
#define write_RS   LATDbits.LATD3   //   RS PIN 22
#define TRIS_RS    DDRDbits.RD3    // TRIS  RS
#define write_E    LATCbits.LATC4   // E  PIN 23
#define TRIS_E     DDRCbits.RC4    // TRIS  E 


#define LED       LATDbits.LATD1      // PIN 20
#define LED_tris  DDRDbits.RD1   


#define DATA_PORT      LATB
#define TRIS_DATA_PORT TRISB
#define READ_PORT      PORTB

long i,b,busy;


void Delay30TCY(void){  // delay 30TCY mas de 37us
Delay10TCYx(3);
}

void Delay10(void){  // delay 10TCY
Delay10TCYx(1);
}
void Delay50ms(void){    //delay  de 50ms
Delay1KTCYx(125);
}
void Delay2ms(void){
Delay1KTCYx(5);           // delay  de 2ms
}



void escribircaracter(const rom near char *buffer)
{
        while(*buffer)                  // Write data to LCD up to null
        {
               Delay2ms; Delay2ms();      // Wait while LCD is busy
         
       
        TRIS_DATA_PORT=0b00000000;  //Puerto como SALIDA 
        write_RS=1;                 //rs=1
        write_RW=0;                 //rw=0
        write_E=0;            //e=0
        Delay10();          //short pause
        write_E=1;            //e=1
        Delay10();          //short pause
        DATA_PORT=*buffer;               //ASCII para "G"
        Delay10();          //short pause
        write_E=0;                  //e=0
        Delay2ms();                   //delay de 2ms


                buffer++;               // Increment buffer
        }
        return;
}

void direccion(char dir)
{
        Delay2ms(); Delay2ms();
        TRIS_DATA_PORT=0b00000000;  //Puerto como SALIDA 
        write_RS=0;                 //rs=0
        write_RW=0;                 //rw=0
        write_E=0;            //e=0
        Delay10();          //short pause
        write_E=1;            //e=1
        Delay10();          //short pause
        DATA_PORT=dir | 0b10000000;       // address "00"
        Delay10();          //short pause
        write_E=0;                  //e=0
        Delay2ms();                   //delay de 2ms
        return;
}


//*******************************************************
void main(void){         //*************COMIENZO PROGRAMA



busy=0;
LED_tris = 0;  //salida
LED=1;           //led encendido

TRIS_DATA_PORT=0;     //Puerto como SALIDA
DATA_PORT=0;

TRIS_RW=0;
TRIS_RS=0;
TRIS_E=0;
 

//*******Inicializacion LCD WH1602A -YYH-STK       

        Delay50ms();                        // pide delay de mas de 40ms

//***************1**********************
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=0;            //e=0
        Delay10();          //short pause
        write_E=1;            //e=1
        Delay10();          //short pause
        DATA_PORT=0b00111000;  //Function Set 8 BIT, 2 lineas 5x8
        Delay10();          //short pause
        write_E=0;            //e=0
        Delay30TCY();           //delay de mas de 37us

//***************2**********************
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=0;            //e=0
        Delay10();          //short pause
        write_E=1;            //e=1
        Delay10();          //short pause
        DATA_PORT=0b00111000;  //Function Set 8 BIT, 2 lineas 5x8
        Delay10();          //short pause
        write_E=0;            //e=0
        Delay30TCY();           //delay de mas de 37us

//***************3**********************
//a partir de ahora se puede verificar BUSY
           
        //isbusy();       
        TRIS_DATA_PORT=0b00000000;     //Puerto como SALIDA 
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=0;            //e=0
        Delay10();          //short pause
        write_E=1;            //e=1
        Delay10();          //short pause
        DATA_PORT=0b00001100;  //DISPLAY ON/OFF CONTROL
        Delay10();          //short pause
        write_E=0;            //e=0
        Delay30TCY();           //delay de mas de 37us

//***************4**********************
        //isbusy;   
   Delay2ms(); Delay2ms();   
        TRIS_DATA_PORT=0b00000000;     //Puerto como SALIDA 
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=0;            //e=0
        Delay10();          //short pause
        write_E=1;            //e=1
        Delay10();          //short pause
        DATA_PORT=0b00000001;  //DISPLAY CLEAR
        Delay10();          //short pause
        write_E=0;            //e=0
        Delay2ms();           //delay de 2ms

//***************5**********************
        //isbusy();     
   Delay2ms(); Delay2ms();   
        TRIS_DATA_PORT=0b00000000;     //Puerto como SALIDA 
        write_RS=0;           //rs=0
        write_RW=0;           //rw=0
        write_E=0;            //e=0
        Delay10();          //short pause
        write_E=1;            //e=1
        Delay10();          //short pause
        DATA_PORT=0b00000110;  //ENTRY MODE SET
        Delay10();          //short pause
        write_E=0;            //e=0
        Delay2ms();           //delay de 2ms

//*****FINAL INICIALIZACION


//******SET DDRAM ADDRESS

  direccion(0b00000000);

 escribircaracter("Prueba");

direccion(0b01000110);

 escribircaracter("LCD");

while(1) 
 {                                 //LED toggle
 

for(i=0;i<700000;i++)
     {_asm nop _endasm
      }         

if (LED==1)
      LED=0;
     else
        LED=1;





}



}

Algunas aclaraciones:

no uso ver si el display esta ocupado o no (busy) ya que tadavia no lo escribi, uso unos delays.
al final del codigo hay un led que enciende y apaga simplemente para mostrar que llega al final del programa.

Saludos y espero que a alguien le sea útil.

Tito