;############################################################################################# ; AFFICHAGE SUR UN LCD (ici 2*40) ; ;(c)Gilou-F4HLA 2002 ;############################################################################################# LIST P=16F84, R=DEC ; 16F84 a 4 MHz errorlevel 0,-305 INCLUDE "p16f84.inc" ;############################################################################################# ;# RAM ;############################################################################################# ; Register Usage ; LCD CBLOCK 0x00C ; Start Registers at End of the Values Dlay:1 ; 8 Bit Delay Variable Temp:1 ; Temporary Value Used When Sending Out Data NOTemp:1 ; Temporary Value to "NybbleOutput" ENDC ;############################################################################################# ;# CONSTANTES ;############################################################################################# ; LCD #DEFINE Data PORTA,0 #DEFINE Clock PORTA, 1 ; Registres INTERMASK EQU B'00000000' OPTIONVAL EQU B'00000000' MASKPORTB EQU B'11111111' MASKPORTA EQU B'11111100' ;############################################################################################# ;# MACRO ;############################################################################################# ; LCD ClockStrobe MACRO ; Strobe the Data Bit bsf Clock bcf Clock ENDM ;----------------------- EStrobe MACRO ; Strobe the "E" Bit bsf Data bcf Data ENDM ;############################################################################################# ;# CONFIGURATION ;############################################################################################# PAGE __CONFIG _CP_OFF & _XT_OSC & _PWRTE_ON & _WDT_OFF ; CP : Code protect :OFF ; OSC : type d'socillateur : a quartz : XT ; PWRTE : power On reset : delais de 72ms a l'allumage : ON ; WDT : watchdog : OFF ;############################################################################################# ;# CODE PRINCIPAL ;############################################################################################# org 0 ;debut du programme goto Start org 0x04 ;gestion des interruptions retfie ;PAS d'interruption ;o) Start ;vrai programme principal ;----------------------- ;config des registres clrf PORTA bsf STATUS, RP0 movlw MASKPORTA ; mise en place du port A movwf TRISA ^ 0x080 movlw INTERMASK ; configuration des interruption movwf INTCON movlw MASKPORTB movwf TRISB ; mise en place du port B en entree movlw OPTIONVAL ; config des options movwf OPTION_REG bcf STATUS, RP0 ;----------------------- ; INITIALISATION LCD call Dlay5 ; 20ms avant le Reset call Dlay5 call Dlay5 call Dlay5 bcf STATUS, C ; Clear Carry (Instruction Out) movlw 0x03 ; Reset Command call NybbleOut ; Send the Nybble call Dlay5 ; Wait 5 msecs before Sending Again bcf STATUS, C ; Clear Carry (Instruction Out) movlw 0x03 ; Reset Command call NybbleOut ; Send the Nybble call Dlay160 ; Wait 160 usecs before Sending the Third Time bcf STATUS, C ; Clear Carry (Instruction Out) movlw 0x03 ; Reset Command call NybbleOut ; Send the Nybble call Dlay160 ; Wait 160 usecs before Sending the Third Tim bcf STATUS, C movlw 0x02 ; Set 4 Bit Mode call NybbleOut call Dlay160 movlw 0x028 ; Note that it is a 2 Line Display call SendINS movlw 0x008 ; Turn off the Display call SendINS movlw 0x001 ; Clear the Display RAM call SendINS call Dlay5 ; Note, Can take up to 4.1 msecs movlw 0x006 ; Enable Cursor Move Direction call SendINS movlw 0x00C ; Turn the LCD Back On call SendINS ;----------------------- ; message de presentation ; Bienvenue1 clrf FSR ; Output the Message1 OutLoop movf FSR, w ; Get the Offset to Output incf FSR call Bienvenue1 iorlw 0 ; At the End of the Message? btfsc STATUS, Z goto EndOL ; Yes - Equal to Zero call SendCHAR ; Output the ASCII Character goto OutLoop EndOL ;----------------------- ;cls movlw 0x001 ; cls (effacement) call SendINS call Dlay5 ; Note, Can take up to 4.1 msecs ;----------------------- ; message constant ; L1 movlw 0x80 ; goto ligne 1 ;pour ecrire sur la ligne un au carctere offset ecrire : ; movlw 0x80+offset ; ligne1,char offset call SendINS call Dlay160 clrf FSR ; Output the etiquette haute OLC1 movf FSR, w ; Get the Offset to Output incf FSR call Compteur1 iorlw 0 ; At the End of the Message? btfsc STATUS, Z goto EndOLC1 ; Yes - Equal to Zero call SendCHAR ; Output the ASCII Character goto OLC1 EndOLC1 ;----------------------- ; message constant ; L2 movlw 0xC0 ; goto ligne 2 ;pour ecrire sur la ligne un au carctere offset ecrire : ; movlw 0xC0+offset ; ligne2,char offset call SendINS call Dlay160 clrf FSR OLC2 movf FSR, w ; Get the Offset to Output incf FSR call Compteur2 iorlw 0 ; At the End of the Message? btfsc STATUS, Z goto EndStart ; Yes - Equal to Zero call SendCHAR ; Output the ASCII Character goto OLC2 ;fin du demarrage, on va pouvoir commencer a travailler EndStart ;----------------------- ;boucle principale Loop ; boucle infini goto Loop ; on recommence ;############################################################################################# ;# SOUS ROUTINES ;############################################################################################# Bienvenue1 ; premier message de bienvenue (ligne 1) addwf PCL ; permet de faire un saut d'instruction d'un offset de valeur contenue ds w dt "(c)Gilou-F4HLA, 2002", 0 ;renvoie le caractere sur lequel on pointe dans w ;----------------------- Compteur1 ; Message L1 addwf PCL dt "voila", 0 ;----------------------- Compteur2 ; Message L2 addwf PCL dt "vous pouvez ecrire sur le LCD", 0 ;----------------------- AlphabetMin ; message contenant l'alphabet en minuscule et un espace a la fin addwf PCL dt "abcdefghijklmnopqrstuvwxyz ", 0 ;----------------------- ; Routine d'envoie d'un caractere contenu ds w au LCD SendCHAR movwf Temp ; Save the Temporary Value swapf Temp, w ; Send the High Nybble bsf STATUS, C ; RS = 1 call NybbleOut movf Temp, w ; Send the Low Nybble bsf STATUS, C call NybbleOut return ;----------------------- ; Routine d'envoie d'une instruction contenu ds w au LCD SendINS movwf Temp ; Save the Temporary Value swapf Temp, w ; Send the High Nybble bcf STATUS, C ; RS = 0 call NybbleOut movf Temp, w ; Send the Low Nybble bcf STATUS, C call NybbleOut return ;----------------------- ; Routine d'envoie d'un demi octet (Nybble) contenu ds w(0-3) au LCD NybbleOut ; Send a Nybble to the LCD movwf NOTemp ; Save the Nybble to Shift Out swapf NOTemp ; Setup to Output to the High Part of the Byte movlw 6 ; Clear the Shift Register movwf Dlay NOLoop1 ClockStrobe decfsz Dlay goto NOLoop1 bsf Data ; Put out the Gate Bit ClockStrobe bcf Data ; Put out the RS Bit rlf PORTA ClockStrobe movlw 4 ; Now, Shift out the Data movwf Dlay NOLoop2 rlf NOTemp ; Shift Through the Nybble to Output bcf Data ; Clear the Data Bit (which is the Clock) rlf PORTA ; Shift the Carry into the Shift Register ClockStrobe decfsz Dlay goto NOLoop2 EStrobe ; Strobe out the LCD Data return ;----------------------- ; delais de 160us Dlay160 movlw 256 - ( 160 / 4 ) ; Loop Until Carry Set addlw 1 btfss STATUS, C goto $-2 return ;----------------------- ; delais de 5ms Dlay5 ; Delay 5 msecs movlw 4 ; Set up the Delay movwf Dlay movlw 256 - 0x0E8 addlw 1 btfsc STATUS, Z decfsz Dlay goto $-3 return ;----------------------- ; delais de presque 1s Dlay1000 movlw 255 ; Set up the Delay movwf Dlay movlw 255 addlw 1 btfsc STATUS, Z decfsz Dlay goto $-3 return ;----------------------- ; fin end