Afficheur lcd 2x16 en mode 8bit pour pic 16xxx

Description

Voici les routines nécessaires pour faire marcher simplement un afficheur LCD en mode 8bit.

Type de pic : PIC16FXXX (ou 16CXXX)
Quartz : 4Mhz (pour utiliser un autre quartz, il suffit de modifier le fichier q4mhz.asm qui contient les routines de temporisation).

Source / Exemple :


;
;			Routines afficheur 2*16 en mode 8 Bits  	V1.0a
;
;									O.R	05/2003
;-----------------------------------------------------------------------------------------
;
;
;	LCD_INIT 		: initialisation de l'afficheur
;	LCD_WRITE_RAM_W 	: envoi un caractere ( contenu dans w ) sur l'afficheur
;	LCD_WRITE_CONTROL_W 	: envoi une commande ( contenue dans w) à l'afficheur
;	LCD_CLEAR_DISPLAY  	: efface l'afficheur
;	LCD_RETURN_HOME 	: renvoi le curseur en haut a gauche
;	LCD_LIGNE1 		: renvoi le curseur au debut de la ligne 1
;	LCD_LIGNE2 		: renvoi le curseur au debut de la ligne 2
;	LCD_ON/LCD_OFF		: allume ou eteint l'affichage
;	LCD_CURSOR_ON/LCD_CURSOR_OFF	: Affichage ou pas du curseur
;	LCD_BLINK_ON/LCD_BLINK_OFF	: Mode BLINK on ou off
;	LCD_DIR_LEFT/LCD_DIR_RIGHT	: Direction de l'écriture
;	LCD_SH_ON/LCD_SH_OFF	:
;
;	constantes a definir dans le programme principal:
;
;	LCD_DATA	; LCD: Port ou est branche le bus de donnee ( bits 0 à 7 )
;	LCD_E		; LCD: Ligne de commande de controle de l'afficheur
;	LCD_RW		; LCD: Ligne de Lecture/Ecriture de l'afficheur
;	LCD_RS		; LCD: Ligne de selection de l'afficheur
;
;	variables a definir dans le programme principal:
;
;       LCD_mode_set, LCD_disp_cont,DATA_TMP,J    		       
;       LCD_curs_disp_shift, LCD_func_set
;

LCD_INIT:			;Initialisation de l'afficheur

	CALL	Tempo_30ms
	movlw	LCD_FUNCTION_SET	;Function set
	movwf	LCD_func_set		;Sauvegarde des paramètres
	call 	LCD_WRITE_CONTROL_W	;Ecriture
	               			;Tempo de 39us

	movlw	LCD_DISPLAY_CONTROL	;Display ON/OFF
	movwf	LCD_disp_cont		;Sauvegarde des paramètres
	call 	LCD_WRITE_CONTROL_W	;Ecriture
					;Tempo de 39us

	call 	LCD_CLEAR_DISPLAY

	movlw	LCD_ENTRY_MODE_SET	;Entry mode set
	movwf	LCD_mode_set		;Sauvegarde des paramètres
	call 	LCD_WRITE_CONTROL_W	;Ecriture
 	CALL	Tempo_43us

	movlw	LCD_CURSOR_DISPLAY_SHIFT
	movwf	LCD_curs_disp_shift	;Sauvegarde des paramètres

	return				;Init end

LCD_WRITE_CONTROL_W:
	bcf	LCD_RW			;Write
	bcf	LCD_RS			;RS a 0
	bsf	LCD_E			;Enable a 1
	movwf	LCD_DATA		;Copie W sur le bus DATA
	bcf	LCD_E			;Enable a 0
 	CALL	Tempo_43us
	return

LCD_WRITE_RAM_W:
	bcf	LCD_RW			;Write
	bsf	LCD_RS			;RS a 1
	bsf	LCD_E			;Enable a 1
	movwf	LCD_DATA		;Copie W sur le bus DATA
	bcf	LCD_E			;Enable a 0
 	CALL	Tempo_43us
	return

LCD_SET_CGRAM_ADD:
	movlw	h'40'
	bcf	LCD_RW			;Write
	bcf	LCD_RS			;RS a 0
	bsf	LCD_E			;Enable a 1
	movwf	LCD_DATA		;Copie W sur le bus DATA
	bcf	LCD_E			;Enable a 0
 	CALL	Tempo_43us
	return

LCD_SET_DDRAM_ADD:
	movlw	h'80'
	bcf	LCD_RW			;Write
	bcf	LCD_RS			;RS a 0
	bsf	LCD_E			;Enable a 1
	movwf	LCD_DATA		;Copie W sur le bus DATA
	bcf	LCD_E			;Enable a 0
 	CALL	Tempo_43us
	return

LCD_LIGNE1:
	movlw	h'80'
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_LIGNE2:
	movlw	h'C0'
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_CLEAR_DISPLAY:
	movlw	h'01'
 	CALL	LCD_WRITE_CONTROL_W
 	CALL	Tempo_1530us
	return

LCD_RETURN_HOME:
	movlw	h'02'
 	CALL	LCD_WRITE_CONTROL_W
 	CALL	Tempo_1530us
	return

LCD_ON:
	bsf  	LCD_disp_cont,2		
	movf	LCD_disp_cont,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_OFF:
	bcf  	LCD_disp_cont,2		
	movf	LCD_disp_cont,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_CURSOR_ON:
	bsf  	LCD_disp_cont,1		
	movf	LCD_disp_cont,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_CURSOR_OFF:
	bcf  	LCD_disp_cont,1		
	movf	LCD_disp_cont,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_BLINK_ON:
	bsf  	LCD_disp_cont,0		
	movf	LCD_disp_cont,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_BLINK_OFF:
	bcf  	LCD_disp_cont,0		
	movf	LCD_disp_cont,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_DIR_LEFT:
	bcf  	LCD_mode_set,1		
	movf	LCD_mode_set,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_DIR_RIGHT:
	bsf  	LCD_mode_set,1		
	movf	LCD_mode_set,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_SH_ON:
	bsf  	LCD_mode_set,2		
	movf	LCD_mode_set,0
 	CALL	LCD_WRITE_CONTROL_W
	return

LCD_SH_OFF:
	bcf  	LCD_mode_set,2		
	movf	LCD_mode_set,0
 	CALL	LCD_WRITE_CONTROL_W
	return

Conclusion :


Première étape indispensable : passer par un call LCD_INIT pour initialiser l'écran.
Ensuite pour écrire un caractère, rien de plus simple :

movlw d'41' (A en ascii)
call LCD_WRITE_RAM_W

et c tout !

le fichier lcd_8b.inc contient toutes les données d'initialisations.

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.