;************************************************************************ ;* ECRIRE DANS LCD Raspino V1.0 * ;* Logiciel a charger dans un * ;* Pic16F84 ou Pic16F876. * ;* cependant qq mod a prevoir si 16f84 * ;************************************************************************ LIST P=16F876 #include __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_ON & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC RESET_V EQU 0x0000 ; Address of RESET Vector ISR_V EQU 0x0004 ; Address of Interrupt Vector LCD_DATA EQU PORTB ; LCD data lines interface LCD_DATA_TRIS EQU TRISB LCD_CTRL EQU PORTA ; LCD control lines interface ; PORTA bits LCD_E EQU 0 ; LCD Enable control line LCD_RW EQU 1 ; LCD Read/Write control line LCD_RS EQU 2 ; LCD Register-Select control line ; PORTB bits DB7 EQU 0 ; LCD dataline 7 (MSB) DB6 EQU 1 ; LCD dataline 6 DB5 EQU 2 ; LCD dataline 5 DB4 EQU 3 ; LCD dataline 4 DB3 EQU 4 ; LCD dataline 3 DB2 EQU 5 ; LCD dataline 2 DB1 EQU 6 ; LCD dataline 1 DB0 EQU 7 ; LCD dataline 0 (LSB) ; misc. LCD_TEMP EQU 0x020 ; LCD subroutines internal use TABLE_INDEX EQU 0x021 ; Index to table strings COUNT EQU 0x022 ; A counter DELAY equ 0x023 ; Used in DELAYxxx routines X_DELAY equ 0x024 ; Used in X_DELAYxxx routines CBLOCK 0x20 Time : 1 Count : 1 valeur : 1 pointeur : 1 RESULTAT : 1 ENDC ;***************************************************************************** ; GO !!!!!!!!!!!!!!!!!! ;***************************************************************************** ORG 0x0000 RESET GOTO START ;***************************************************************************** ; Initialise ;***************************************************************************** START ; POWER_ON Reset (Beginning of program) CLRF STATUS ; Do initialization, Select bank 0 CLRF INTCON ; Clear int-flags, Disable interrupts CLRF PCLATH ; Keep in lower 2KByte CLRF PORTA ; ALL PORT output should output Low. CLRF PORTB BSF STATUS, RP0 ; Select bank 1 MOVLW 0X06 MOVWF ADCON1 MOVLW 0x0f8 ; RA2-0 outputs, RA4-3 inputs;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MOVWF TRISA MOVLW 0x000 ; RB7-0 outputs MOVWF TRISB BSF OPTION_REG, NOT_RBPU ; Disable PORTB pull-ups BCF STATUS, RP0 ; Select bank 0 CALL LCDINIT ; Initialize LCDisplay debut movlw 0x00 movwf Count movwf pointeur Boucle1 movf pointeur,w CALL LCDSDDA call DELAY500 Suite movf Count,w call LireEprom movwf valeur xorlw 0xff btfsc STATUS,Z goto debut movf valeur,w call LCDPUTCHAR call LCDGADDR movf RESULTAT,w xorlw 0x10 btfsc STATUS,Z goto DECAL incf Count,f goto Suite DECAL movlw 0x00 movwf pointeur movlw 0x0e subwf Count,f call TEMPO goto Boucle1 ;********************************************** ;* FONCTION LIRE EN EEPROM ADRESSE DANS W * ;* RESULTAT EEDATA dans W en retour ! * ;********************************************** LireEprom bcf STATUS,RP0 bsf STATUS,RP1 movwf EEADR bsf STATUS,RP0 bcf EECON1,EEPGD bsf EECON1,RD bcf STATUS,RP0 movf EEDATA,w bcf STATUS,RP1 return ;***************************************************************************** ; LCD ;***************************************************************************** ; ;============================================================================= ; LCDINIT ;============================================================================= LCDINIT ; Busy-flag is not yet valid CLRF LCD_CTRL ; ALL PORT output should output Low. ; power-up delay MOVLW 0x01E CALL X_DELAY500 ; 30 * 0.5mS = 15mS MOVLW 0x01E CALL X_DELAY500 ; Busy Flag should be valid from here MOVLW 0x01E CALL X_DELAY500 MOVLW 0x01E CALL X_DELAY500 MOVLW 0x01E CALL X_DELAY500 MOVLW 0x038 ; 8-bit-interface, 2-lines CALL LCDPUTCMD MOVLW 0x000 ; disp.off, curs.off, no-blink CALL LCDDMODE CALL LCDCLEAR MOVLW 0x004 ; disp.on, curs.OFF CALL LCDDMODE MOVLW 0x002 ; auto-inc (shift-cursor) CALL LCDEMODE RETURN ;============================================================================= ; LCD_ENABLE ;============================================================================= LCD_ENABLE BSF LCD_CTRL, LCD_E ; LCD E-line High BCF LCD_CTRL, LCD_E ; LCD E-line Low RETURN ;============================================================================= ; LCDBUSY ;============================================================================= LCDBUSY BSF STATUS,RP0 ; Select Register page 1 MOVLW 0x0FF ; Set PORTB for input MOVWF LCD_DATA_TRIS BCF STATUS, RP0 ; Select Register page 0 BCF LCD_CTRL, LCD_RS; Set LCD for command mode BSF LCD_CTRL, LCD_RW; Setup to read busy flag BSF LCD_CTRL, LCD_E ; LCD E-line High MOVF LCD_DATA, W ; Read busy flag + DDram address BCF LCD_CTRL, LCD_E ; LCD E-line Low ANDLW 0x80 ; Check Busy flag, High = Busy BTFSS STATUS, Z GOTO LCDBUSY LCDNOTBUSY BCF LCD_CTRL, LCD_RW BSF STATUS, RP0 ; Select Register page 1 MOVLW 0x000 MOVWF LCD_DATA_TRIS ; Set PORTB for output BCF STATUS, RP0 ; Select Register page 0 RETURN ;============================================================================= ; LCDCLEAR ;============================================================================= LCDCLEAR MOVLW 0x001 CALL LCDPUTCMD RETURN ;============================================================================= ; LCDHOME ;============================================================================= LCDHOME MOVLW 0x002 CALL LCDPUTCMD RETURN ;============================================================================= ; LCDEMODE ; Sets entry mode of display. ; Required entry mode must be set in W ; b0 : 0 = no display shift 1 = display shift ; b1 : 0 = auto-decrement 1 = auto-increment ; b2-7 : don't care ; OK ;============================================================================= LCDEMODE ANDLW 0x003 ; Strip upper bits IORLW 0x004 ; Function set CALL LCDPUTCMD RETURN ;============================================================================= ; LCDDMODE ; Sets display control. ; Required display mode must be set in W ; b0 : 0 = cursor blink off 1 = cursor blink on ; b1 : 0 = cursor off 1 = cursor on ; b2 : 0 = display off 1 = display on (display data remains in DDRAM) ; b3-7 : don't care ; OK ;============================================================================= LCDDMODE ANDLW 0x007 ; Strip upper bits IORLW 0x008 ; Function set CALL LCDPUTCMD RETURN ;============================================================================= ; LCDSCGA ; Sets Character-Generator-RAM address. CGRAM is read/written after ; this setting. ; Required CGRAM address must be set in W ; b0-5 : required CGRAM address ; b6-7 : don't care ; ;============================================================================= LCDSCGA ANDLW 0x03F ; Strip upper bits IORLW 0x040 ; Function set CALL LCDPUTCMD RETURN ;============================================================================= ; LCDSDDA ; Sets the Display-Data-RAM address. DDRAM data is read/written after ; this setting. ; Required DDRAM address must be set in W ; b0-6 : required DDRAM address ; b7 : don't care ; OK ;============================================================================= LCDSDDA IORLW 0x080 ; Function set CALL LCDPUTCMD RETURN ;============================================================================= ; LCDGADDR ; Returns address counter contents, used for both DDRAM and CGRAM. ; RAM address is returned in W ; ;============================================================================= LCDGADDR BSF STATUS,RP0 ; Select Register page 1 MOVLW 0x0FF ; Set PORTB for input MOVWF LCD_DATA_TRIS BCF STATUS, RP0 ; Select Register page 0 BCF LCD_CTRL, LCD_RS; Set LCD for command mode BSF LCD_CTRL, LCD_RW; Setup to read busy flag BSF LCD_CTRL, LCD_E ; LCD E-line High MOVF LCD_DATA, W ; Read busy flag + RAM address BCF LCD_CTRL, LCD_E ; LCD E-line Low ANDLW 0x07F ; Strip upper bit movwf RESULTAT BCF LCD_CTRL, LCD_RW BSF STATUS, RP0 ; Select Register page 1 MOVLW 0x000 MOVWF LCD_DATA_TRIS ; Set PORTB for output BCF STATUS, RP0 ; Select Register page 0 RETURN ;============================================================================= ; LCDPUTCHAR ; Sends character to LCD ; Required character must be in W ; OK ;============================================================================= LCDPUTCHAR MOVWF LCD_TEMP ; Character to be sent is in W CALL LCDBUSY ; Wait for LCD to be ready BCF LCD_CTRL, LCD_RW; Set LCD in read mode BSF LCD_CTRL, LCD_RS; Set LCD in data mode BSF LCD_CTRL, LCD_E ; LCD E-line High MOVF LCD_TEMP, W MOVWF LCD_DATA ; Send data to LCD BCF LCD_CTRL, LCD_E ; LCD E-line Low RETURN ;============================================================================= ; LCDPUTCMD ; Sends command to LCD ; Required command must be in W ; OK ;============================================================================= LCDPUTCMD MOVWF LCD_TEMP ; Command to be sent is in W CALL LCDBUSY ; Wait for LCD to be ready BCF LCD_CTRL, LCD_RW; Set LCD in read mode BCF LCD_CTRL, LCD_RS; Set LCD in command mode BSF LCD_CTRL, LCD_E ; LCD E-line High MOVF LCD_TEMP, W MOVWF LCD_DATA ; Send data to LCD call DELAY500 BCF LCD_CTRL, LCD_E ; LCD E-line Low RETURN ;***************************************************************************** DELAY500 MOVLW D'165' ; +1 1 cycle MOVWF DELAY ; +2 1 cycle DELAY500_LOOP DECFSZ DELAY, F ; step 1 1 cycle GOTO DELAY500_LOOP ; step 2 2 cycles DELAY500_END RETURN ; +3 2 cycles ; ; X_DELAY500 MOVWF X_DELAY ; +1 1 cycle X_DELAY500_LOOP CALL DELAY500 ; step1 wait 500uSec CALL DELAY500 CALL DELAY500 CALL DELAY500 CALL DELAY500 DECFSZ X_DELAY, F ; step2 1 cycle GOTO X_DELAY500_LOOP ; step3 2 cycles X_DELAY500_END RETURN ; +2 2 cycles ; ; TEMPO movlw 0x07 movwf Time Boucle call X_DELAY500 decfsz Time,f goto Boucle return ORG 2100 DE 'L','e','a','k','y',' ','S','t','i','r','l','i','n','g',' ','M','a','i','t','r','i','s','e' DE 'b','i','e','n',' ','l','e','s',' ','E','c','r','a','n','s',' ','L','C','D' DE ' ','!','!','!',' ',' ','B','i','e','n',' ','u','n',' ','p','e','u',' ','q','u','a','n','d',' ','m','e','m','e','.','.','.',' ',' ',' ',0xFF END ; Fin du programme Leaky 2005