Comment initialiser un LCD ?

Toufinet -  
 nams2590 -
Bonjour .

Après 1 mois de recherche, je n'arrive désespéremment pas à initialiser un LCD 16x2.

Voici comment j'ai procédé :
- pic 16F877 à 14.7 MHz
- port B relié aux pins 7 à 14 du LCD
- Enable relié à RD7
- RW relié à RD6
- RS relié à RD5

Voici mon programme :

list P=16F877
#include <p16f877.inc>
#define LCD_ENABLE PORTD,7
#define LCD_RW PORTD,6
#define LCD_RS PORTD,5

__CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC

CBLOCK 0x20

cpt1 : 1
cpt2 : 1
cpt3 : 1

ENDC

org 0x000
goto init;

org 0x005
BANK0 macro ; passe en banque0
bcf STATUS,RP0
bcf STATUS,RP1
endm

BANK1 macro ; passe en banque1
bsf STATUS,RP0
bcf STATUS,RP1
endm

init
BANK1
movlw b'00000000'
movwf TRISB
movlw b'00000000'
movwf TRISD
BANK0
clrf PORTB
clrf PORTD

call tempo_init
call init_LCD;
binfi goto binfi

init_LCD

movlw 0x38
call send_cmd_LCD;
movlw 0x38
call send_cmd_LCD;
movlw 0x38
call send_cmd_LCD;
movlw 0x06
call send_cmd_LCD;
movlw 0x0C
call send_cmd_LCD;
movlw 0x01
call send_cmd_LCD;
call cls_LCD

return

send_cmd_LCD
bcf LCD_RS
bcf LCD_RW
movwf PORTB
call tempo
bsf LCD_ENABLE
call tempo
bcf LCD_ENABLE
call tempo
return

cls_LCD
bcf LCD_RS
bcf LCD_RW
clrf PORTB
bsf PORTB,0
bsf LCD_ENABLE
call tempo
bcf LCD_ENABLE
return

tempo_init
movlw 0x10
movwf cpt3
t1 decfsz cpt3,1
goto t4
return
t4 movlw 0xFF
movwf cpt2
t3 decfsz cpt2,1
goto t0
goto t1
t0 movlw 0xFF
movwf cpt1
t2 decfsz cpt1,1
goto t2
goto t3
return

tempo
movlw 0x20
movwf cpt1
t13 decfsz cpt1,1
goto t13
return

end;

Résultat : le pic n'est pas initialisé. Il a toujours la ligne du haut allumée, et la ligne du bas éteinte.

Je suis en train de craquer, ça fais 1 mois que je n'avance pas à cause de ça, svp aidez moi!

D'avance merci et gros bisous à qui résoudra mon problème !

1 réponse

nams2590
 
Bonjour,

Je pense que ton problème provenait de ta tempo. J'ai tester ton programme en essayant d'envoyer le caractère 'a'. En modifiant légèrement ton programme, celui ci fonctionne. Voici ce que j'ai fait :

list P=16F877
#include <p16f877.inc>
#define LCD_ENABLE PORTD,7
#define LCD_RW PORTD,6
#define LCD_RS PORTD,5

__CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC

CBLOCK 0x20

temps : 1
temps2 : 1

ENDC

org 0x000
goto init;

org 0x005
BANK0 macro ; passe en banque0
bcf STATUS,RP0
bcf STATUS,RP1
endm

BANK1 macro ; passe en banque1
bsf STATUS,RP0
bcf STATUS,RP1
endm

init
BANK1
movlw b'00000000'
movwf TRISB
movlw b'00000000'
movwf TRISD
BANK0
clrf PORTB
clrf PORTD

call init_LCD
movlw 'a'
call send_data_LCD
binfi goto binfi

init_LCD

movlw 0x38
call send_cmd_LCD;
movlw 0x38
call send_cmd_LCD;
movlw 0x38
call send_cmd_LCD;
movlw 0x06
call send_cmd_LCD;
movlw 0x0C
call send_cmd_LCD;
movlw 0x01
call send_cmd_LCD;
call cls_LCD

return

send_cmd_LCD
bcf LCD_RS
bcf LCD_RW
movwf PORTB
call t2ms
bsf LCD_ENABLE
call t2ms
bcf LCD_ENABLE
call t2ms
return

cls_LCD
bcf LCD_RS
bcf LCD_RW
clrf PORTB
bsf PORTB,0
bsf LCD_ENABLE
call t2ms
bcf LCD_ENABLE
return

send_data_LCD
bsf LCD_RS
bcf LCD_RW
movwf PORTB
call t2ms
bsf LCD_ENABLE
call t2ms
bcf LCD_ENABLE
call t2ms
return

t2ms movlw D'10'
movwf temps
movlw D'105'
movwf temps2
retour2 decfsz temps
goto t2ms2
goto fintempo2ms
t2ms2 decfsz temps2
goto t2ms2
movlw D'105'
movwf temps2
goto retour2
fintempo2ms return

end;
0