Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

Interfacciamento [PIC18F2550] con LCD 16x2

Tipologie, strumenti di sviluppo, hardware e progetti

Moderatore: Foto UtentePaolino

0
voti

[11] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteOrionis » 19 set 2015, 17:13

Questi display di dubbia provenienza hanno la caratteristica di essere tutti diversi uno dall'altro, pur condividendo lo stesso controller, e di guastarsi con relativa facilità pur dando segni di vita.

Ho parecchi esemplari con differenti formati, dal 16x2 al 40x4 e ho sempre scritto i driver e librerie per conto mio. Non ti dico quanti moccoli quando dovevo di provare un nuovo modello, ma poi con prove comparative e aggiustamenti ne sono sempre uscito.

Senza leggere il tuo codice (perché sono pigro) che sara' sicuramente corretto, posso solo suggerirti di procurarti un altro display e compararli.
Una prova che puoi fare, se hai pin liberi sul PIC, è di provarlo prima a 8 bit: il sw è più semplice (init e scrittura) e il debug pure.
auguri
Nemmeno gli Dei possono nulla contro la stupidità umana ?
Avatar utente
Foto UtenteOrionis
2.083 1 6 13
Expert
Expert
 
Messaggi: 103
Iscritto il: 16 mag 2015, 10:33
Località: Bergamo

0
voti

[12] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteIlGuru » 19 set 2015, 23:41

A volte la piedinatura non corrisponde a quella del datasheet che hai perché il cinese che ha fatto il display ci ha messo del suo.
Capita di trovare la serigrafia che numera i pin da 1 a 16, poi devi studiarti le piste sul PCB e provare col tester per capire seanodo e catodo della retroilluminazione sono l'1 e il 2 o il 15 e il . La prima volta mi sono fidato del datasheet allegato ed ho visto uscire il fumo da sotto il display e cone immaginerete non ne ha più voluto sapere di andare, però la riga nera c'era.
\Gamma\nu\tilde{\omega}\theta\i\ \sigma\epsilon\alpha\upsilon\tau\acute{o}\nu
Avatar utente
Foto UtenteIlGuru
5.482 2 10 13
G.Master EY
G.Master EY
 
Messaggi: 1924
Iscritto il: 31 lug 2015, 23:32

1
voti

[13] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteWALTERmwp » 21 set 2015, 21:50

Ciao Foto UtenteCarloD, prima di approfondire l'aspetto delle tempistiche e dell'ordine di invio delle istruzioni mi potresti spiegare per quale motivo quel ciclo for iniziale invece di limitarlo a tre esecuzioni lo hai impostato per quattro ?

Saluti
W - U.H.F.
Avatar utente
Foto UtenteWALTERmwp
30,2k 4 8 13
G.Master EY
G.Master EY
 
Messaggi: 8982
Iscritto il: 17 lug 2010, 18:42
Località: le 4 del mattino

0
voti

[14] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteCarloD » 23 set 2015, 22:21

Il ciclo iniziale per l'init del display ero certo che scrivendo s<=3 lo eseguisse 3 volte; errore mio, ho corretto il ciclo for con:
for (s=0; s<=2; s++)
Inoltre ho provato a portare il delay tra un nibble e l'altro da 10us a 50 us ma nulla; poi ho provato a inserire anche il delay di 10us tra l'impostazione di un pin e l'altro come suggeriva IlGuru, ma nulla da fare.
Avatar utente
Foto UtenteCarloD
10 3
 
Messaggi: 16
Iscritto il: 5 set 2015, 14:55

0
voti

[15] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteWALTERmwp » 24 set 2015, 2:18

Foto UtenteCarloD, proviamo a fare un passo avanti.
Parto dal presupposto che lo LCD sia integro e funzionante, così come considero corretti i collegamenti.
Faccio dunque riferimento al codice che hai inserito nel primo Post.
Dunque, il loop iniziale è sistemato quindi, quell'errore che avrebbe pregiudicato qualunque altra azione, non c'è più.
Ti chiedo, se vuoi, di eseguire ora due correzioni, ma non contemporaneamente.
Prima modifichi l'invio della istruzione "Display on/off control D=0 - B=0 C=0" nel seguente modo:
Codice: Seleziona tutto
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse();
    __delay_ms(10);
    LCD_D7 = 1;
    LCD_D6 = 1;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse();
    __delay_ms(10);
e provi.
Provvedi poi a invertire l'ordine di questa istruzione, appena modificata, con quella di "Clear Display" cioè esegui prima la "Clear Display" e dopo la "Display on/off control D=0 - B=0 C=0", e provi.
Intanto questo, grazie.

Saluti
W - U.H.F.
Avatar utente
Foto UtenteWALTERmwp
30,2k 4 8 13
G.Master EY
G.Master EY
 
Messaggi: 8982
Iscritto il: 17 lug 2010, 18:42
Località: le 4 del mattino

0
voti

[16] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteCarloD » 25 set 2015, 0:34

Ciao WALTERmwp,
ho appena finito proprio ora di fare le due prove che hai citato, prima una e poi l'altra, ma purtroppo devo dirti che danno esito negativo.
Grazie
Carlo
Avatar utente
Foto UtenteCarloD
10 3
 
Messaggi: 16
Iscritto il: 5 set 2015, 14:55

0
voti

[17] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteWALTERmwp » 25 set 2015, 1:53

CarloD ha scritto:(...) danno esito negativo (...)
ma non abbiamo finito, c'è altro da provare.
Dovresti dichiarare queste due funzioni,
Codice: Seleziona tutto
void E_Pulse_H(void)
{
    E_PIN = 1;
    __delay_us(200);
}

void E_Pulse_L(void)
{
   __delay_us(200);
    E_PIN = 0;
}
che andremmo ad utilizzare per l'invio di ogni nibble eliminando "E_Pulse()", così:
Codice: Seleziona tutto
    for (s=0; s<=2; s++)
    {
        E_Pulse_H();
        LCD_D4 = 1;
        LCD_D5 = 1;
        LCD_D6 = 0;
        LCD_D7 = 0;
        E_Pulse_L();
        __delay_ms(10);
    }
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 1;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);

    ...
    ...
    ...
... sino e per la funzione "Entry mode ..." compresa.

Elimini quindi l'ultima ripetizione della istruzione "Display on/off ..." (quella posizionata subito dopo il commento "Inizialization Ends").

Poi aggiungi un'altra istruzione, per il "Return Home", così:
Codice: Seleziona tutto
    //Return H.
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 1;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);

Quindi, dopo l'istruzione che mette a 1 il pin RS, modifichi nel seguente modo (come già fatto per le altre) l'istruzione che invia il carattere:
Codice: Seleziona tutto
    // scrivo carattere H = 01001000
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 1;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
    E_Pulse_H();
    LCD_D7 = 1;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);

Ci proviamo ?

Saluti
W - U.H.F.
Avatar utente
Foto UtenteWALTERmwp
30,2k 4 8 13
G.Master EY
G.Master EY
 
Messaggi: 8982
Iscritto il: 17 lug 2010, 18:42
Località: le 4 del mattino

0
voti

[18] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteCarloD » 25 set 2015, 23:08

Buona serata, ringrazio tutti coloro che finora hanno risposto.
Questo è il codice che ho provato dopo le ultime modifiche di WALTERmwp:
Codice: Seleziona tutto
/*LCDMain versione 1.1.0

Elenco Modifiche revisione 1.1.0

Sostituito funzione:
   void E_Pulse(void) {
   __delay_us(500);
        E_PIN = 1;
      __delay_us(500);
      E_PIN = 0;
con funzioni
   void E_Pulse_H(void)
   {
       E_PIN = 1;
       __delay_us(200);
   }
   void E_Pulse_L(void)
   {
      __delay_us(200);
       E_PIN = 0;
   }

Eliminata istruzione Display on/off dopo iniitialization ends
e sostituita con istruzione Return Home

Comandi per configurazione dispaly
0011 init 4bit display 16x2
0011
0011
0010

0010 1000 Display off no cursor no blink
0000 0001 Clear display
0000 1100 Display on no cursor no blink
0000 0110 Entry mode set increment no shift
0000 0010 Return home
*/

/** C O N F I G U R A T I O N      B I T S**********************************/

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1L
#pragma config PLLDIV = 1       // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1       // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)

// CONFIG1H
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator (HS))
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRT = OFF       // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON         // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3         // Brown-out Reset Voltage bits (Minimum setting)
#pragma config VREGEN = OFF     // USB Voltage Regulator Enable bit (USB voltage regulator disabled)

// CONFIG2H
#pragma config WDT = OFF        // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = ON      // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF     // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF    // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON       // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF        // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF        // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF        // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF       // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF       // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF       // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)

/** I N C L U D E S*********************************************************/
#include "xc.h"
#include "delays.h"

/** V A R I A B L E S*******************************************************/
int i;
int s;
/** D E C L A R A T I O N S*************************************************/
#define _XTAL_FREQ 12000000

#define RS_PIN   LATCbits.LATC0      /* PORT for RS */
#define TRIS_RS  TRISCbits.TRISC0       /* TRIS for RS */

#define E_PIN   LATCbits.LATC2     /* PORT for E  */
#define TRIS_E   TRISCbits.TRISC2       /* TRIS for E  */

#define LED    LATAbits.LATA4     /* PORT for LED  */
#define TRIS_LED   TRISAbits.TRISA4       /* TRIS for LED  */

#define LCD_D7  LATBbits.LATB3 /* PORT for D7 LCD */
#define TRIS_D7 TRISBbits.TRISB3    /* TRIS for D7 LCD */

#define LCD_D6  LATBbits.LATB2 /* PORT for D6 LCD */
#define TRIS_D6 TRISBbits.TRISB2 /* TRIS for D6 LCD */

#define LCD_D5  LATBbits.LATB1 /* PORT for D5 LCD */
#define TRIS_D5 TRISBbits.TRISB1    /* TRIS for D5 LCD */

#define LCD_D4  LATBbits.LATB0 /* PORT for D4 LCD */
#define TRIS_D4 TRISBbits.TRISB0 /* TRIS for D4 LCD */

// ritardo 500ms
void delay500 (void){
    for (s=0; s<10; s++){
        __delay_ms(50);
    }
   }
// Comando per pin enable E display
void E_Pulse_H(void)
{
    E_PIN = 1;
    __delay_us(200);
}

void E_Pulse_L(void)
{
   __delay_us(200);
    E_PIN = 0;
}
void main( void )
{
    //imposto direzione porte
    TRIS_RS = 0;
    TRIS_E = 0;
    TRIS_D7 = 0;
    TRIS_D6 = 0;
    TRIS_D5 = 0;
    TRIS_D4 = 0;
    ADCON1 = 0x0f;
//LED per "debug" e ritardo 1s per assicurare power on
    TRIS_LED = 0;
    LED = 1;
    delay500();
    LED = 0;
//Imposto pin RS display per comandi
    RS_PIN = 0;
    delay500();
// ***************************INIT********************************************
// Set 4 bit operation
    //0011
    //0011
    //0011
    //0010
//*****************************************************************************
    for (s=0; s<=2; s++)  /*Mod101 corretto s<=3 in s<=2*/
    {
        E_Pulse_H();
   LCD_D4 = 1;
        LCD_D5 = 1;
        LCD_D6 = 0;
        LCD_D7 = 0;
        E_Pulse_L();
        __delay_ms(10);
        }
        E_Pulse_H();
   LCD_D7 = 0;
        LCD_D6 = 0;
        LCD_D5 = 1;
        LCD_D4 = 0;
        E_Pulse_L();
        __delay_ms(10);
//****************************************************************************
// Functions Set 2 lines and 5x8 dot matrix
//00101000
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 1;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
    E_Pulse_H();
    LCD_D7 = 1;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
//****************************************************************************
//Mod102 scambiato operazione Display on/off control con Clear Display
//Clear Display
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 1;
    E_Pulse_L();
    __delay_ms(10);
//****************************************************************************
//Display on/off control D=0 - B=0 C=0
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
    E_Pulse_H();
    LCD_D7 = 1;
    LCD_D6 = 1;   /*Mod101 corretto LCD_D6=0 in LCD_D6=1*/
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
//**************************************************************************
    //Entry mode set I/D=1 and S=0
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 1;
    LCD_D5 = 1;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
//***********************Inizialization Ends********************************
//Return home
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 0;
    LCD_D5 = 1;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
//Imposto il pin RS a 1 per scrivere un dato
    RS_PIN = 1;
    __delay_ms(10);
//****************************************************************************
// scrivo carattere H = 01001000
    E_Pulse_H();
    LCD_D7 = 0;
    LCD_D6 = 1;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
    E_Pulse_H();
    LCD_D7 = 1;
    LCD_D6 = 0;
    LCD_D5 = 0;
    LCD_D4 = 0;
    E_Pulse_L();
    __delay_ms(10);
//******************************* FINE ************************************
//Aggiungo loop infinito per far lampeggiare il LED come "debug" per
//verificare se il codice giunge al termine.
    while (1)
    {
        delay500();
        LED = ~LED;
        delay500();
        LED = ~LED;
    }
}

... nulla da fare...
il display non vuole saperne.. :(
Avatar utente
Foto UtenteCarloD
10 3
 
Messaggi: 16
Iscritto il: 5 set 2015, 14:55

0
voti

[19] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteWALTERmwp » 26 set 2015, 21:49

CarloD ha scritto:il display non vuole saperne.. :(
ma non gettiamo la spugna.
Puoi sostituire la funzione
Codice: Seleziona tutto
__delay_ms(10);
con
Codice: Seleziona tutto
__delay_us(200);
e provare ?

Saluti
W - U.H.F.
Avatar utente
Foto UtenteWALTERmwp
30,2k 4 8 13
G.Master EY
G.Master EY
 
Messaggi: 8982
Iscritto il: 17 lug 2010, 18:42
Località: le 4 del mattino

0
voti

[20] Re: Interfacciamento [PIC18F2550] con LCD 16x2

Messaggioda Foto UtenteCarloD » 30 set 2015, 23:52

Fatto. Sostituito la funzione delay 10ms con delay 200us, purtroppo niente d fare.
Ho verificato on l'oscilloscopio i segnali e allego il file.
il segnale RW ricordo che è collegato a 0V, quindi sempre basso.
Ho notato che i pin del display D0 D1 D2 e D3 che non sono collegati se verifico con la sonda dell'oscilloscopio trovo 5V su tutti.

Grazie
Carlo
Allegati
signals1.pdf
(90.95 KiB) Scaricato 190 volte
Avatar utente
Foto UtenteCarloD
10 3
 
Messaggi: 16
Iscritto il: 5 set 2015, 14:55

PrecedenteProssimo

Torna a Realizzazioni, interfacciamento e nozioni generali.

Chi c’è in linea

Visitano il forum: Nessuno e 8 ospiti