Ho ritrovato un LCD 16x2 che avevo acquistato tempo fa e ne ho dedotto che monti a bordo un HD44780, dopo aver letto il data sheet e dato un’occhiata in alcuni forum ho provato a farlo funzionare.
Ho usato una scheda general purpose che monta un PIC18F2550 con un quarzo da 12MHz, sulla porta RA4 c’è collegato un LED.
il Display è alimentato con 5Vcc tra i pin 1 e 2 (rispettivamente + e -) e un trimmer da 10K per regolare il contrasto sul pin 3.
I collegamenti tra micro e display sono :
RB0-->DB4 (pin 11)
RB1-->DB5 (pin 12)
RB2-->DB6 (pin 13)
RB3-->DB7 (pin14)
RC0-->RS (pin 4)
RC2-->E (pin 6)
(il comando R/W -pin 5 display - l’ho collegato direttamente a GND).
Al momento ho inserito anche una resistenza di pull-down (15K) sulle porte RB0-RB1-RB2-RB3-RC0-RC2.
Dopo aver scritto il codice seguente con XC8:
- Codice: Seleziona tutto
/** 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(void) {
__delay_us(500);
E_PIN = 1;
__delay_us(500);
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<=3; s++)
{
LCD_D4 = 1;
LCD_D5 = 1;
LCD_D6 = 0;
LCD_D7 = 0;
E_Pulse();
__delay_ms(10);
}
LCD_D7 = 0;
LCD_D6 = 0;
LCD_D5 = 1;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
//****************************************************************************
// Functions Set 2 lines and 5x8 dot matrix
//00101000
LCD_D7 = 0;
LCD_D6 = 0;
LCD_D5 = 1;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
LCD_D7 = 1;
LCD_D6 = 0;
LCD_D5 = 0;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
//****************************************************************************
//Display on/off control D=0 - B=0 C=0
LCD_D7 = 0;
LCD_D6 = 0;
LCD_D5 = 0;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
LCD_D7 = 1;
LCD_D6 = 0;
LCD_D5 = 0;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
//****************************************************************************
//Clear Displaye
LCD_D7 = 0;
LCD_D6 = 0;
LCD_D5 = 0;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
LCD_D7 = 0;
LCD_D6 = 0;
LCD_D5 = 0;
LCD_D4 = 1;
E_Pulse();
__delay_ms(10);
//**************************************************************************
//Entry mode set I/D=1 and S=0
LCD_D7 = 0;
LCD_D6 = 0;
LCD_D5 = 0;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
LCD_D7 = 0;
LCD_D6 = 1;
LCD_D5 = 1;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
//***********************Inizialization Ends********************************
//****************************************************************************
//Display on/off control D=1 - B=0 C=0
//Display ON
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);
//Imposto il pin RS a 1 per scrivere un dato
RS_PIN = 1;
__delay_ms(10);
//****************************************************************************
// scrivo carattere H = 01001000
LCD_D7 = 0;
LCD_D6 = 1;
LCD_D5 = 0;
LCD_D4 = 0;
E_Pulse();
__delay_ms(10);
LCD_D7 = 1;
LCD_D6 = 0;
LCD_D5 = 0;
LCD_D4 = 0;
E_Pulse();
__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;
}
}
sembra che il display non voglia nemmeno sapere di inizializzarsi.
Le foto fanno vedere il display nel caso potesse servire (i pin 15 e 16 sono l'alimentazione della retroillumnazione)
Potreste darmi qualche suggerimento per favore?
Grazie
Carlo

Elettrotecnica e non solo (admin)
Un gatto tra gli elettroni (IsidoroKZ)
Esperienza e simulazioni (g.schgor)
Moleskine di un idraulico (RenzoDF)
Il Blog di ElectroYou (webmaster)
Idee microcontrollate (TardoFreak)
PICcoli grandi PICMicro (Paolino)
Il blog elettrico di carloc (carloc)
DirtEYblooog (dirtydeeds)
Di tutto... un po' (jordan20)
AK47 (lillo)
Esperienze elettroniche (marco438)
Telecomunicazioni musicali (clavicordo)
Automazione ed Elettronica (gustavo)
Direttive per la sicurezza (ErnestoCappelletti)
EYnfo dall'Alaska (mir)
Apriamo il quadro! (attilio)
H7-25 (asdf)
Passione Elettrica (massimob)
Elettroni a spasso (guidob)
Bloguerra (guerra)





