LIST NOLIST ;En deze commando`s kun je gebruiken: ;LCD_CLEAR ;LCD_CURSOR_HOME ;LCD_CURSOR_LEFT ;LCD_CURSOR_RIGHT ;LCD_MOVE_ALL_L ;LCD_MOVE_ALL_RIGHT ;LCD_LINE1 ;LCD_LINE2 ;LCD_DELAY ;LCD_SCROLL_L ;LCD_SCROLL_R ;LCD_INIT ;LCD_CURSOR_OFF ;LCD_CHAR ; LCD control lines #define LCD_RS 0 ; 0 = Command, 1 = Data #define LCD_RW 1 ; 0 = Write, 1 = Read #define LCD_E 2 ; 1 to send data #define LCD_D4 3 ; 4 data lines #define LCD_D5 4 #define LCD_D6 5 #define LCD_D7 6 ; Registers we will be using #define R_DEL1 0x20 ; Delay register #define R_DEL2 0x21 ; Delay register #define R_WDATA_TMP1 0x22 #define R_WDATA_TMP2 0x23 #define R_SEND_W_TMP 0x24 #define R_WTMP 0x27 ; W storage #define R_STMP 0x28 ; STATUS storage #define R_STMP1 0x2E ; Send temp register #define R_PSEC 0x2F CBLOCK 20H D1 D2 SCROL1 SCROL2 ENDC ;org 00H ;START LCD_INIT MACRO CALL INIT LCD_CLEAR ENDM LCD_CHAR MACRO CHAR MOVLW CHAR CALL send_w ENDM LCD_CLEAR MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'00000001' ; CLEAR LCD call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_CURSOR_HOME MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'00000010' ; CURSOR HOME call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_CURSOR_LEFT MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'00000100' ; MOVE THE CURSOR TO THE LEFT call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_CURSOR_RIGHT MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'00000110' ; MOVE THE CURSOR TO THE RIGHT call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_MOVE_ALL_L MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'00011000' ; MOVE TEXT TO LEFT call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_MOVE_ALL_R MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'00011100' ; MOVE TEXT TO RIGHT call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_LINE1 MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'10000000' ; LINE 1 call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_LINE2 MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'11000000' ; LINE2 call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_CURSOR_OFF MACRO bcf LCD_PORT, LCD_RS ; Command mode movlw b'00001100' ; DISPLAY ON, CURSOR & BLINK OFF call send_w bsf LCD_PORT, LCD_RS ; Data mode call delay_1ms ; Takes a couple of ms ENDM LCD_DELAY MACRO CALL LCD_DELAY1 ENDM LCD_SCROLL_R MACRO CALL LCD_SCROLL_R1 ENDM LCD_SCROLL_L MACRO CALL LCD_SCROLL_L1 ENDM org 4 movwf R_WTMP ; Save W & STATUS swapf STATUS, W movwf R_STMP bcf STATUS, RP0 int_cleanup: movlw b'11111000' ; Clear interrupt bits andwf INTCON, F swapf R_STMP, W ; Restore W & STATUS movwf STATUS swapf R_WTMP, F swapf R_WTMP, W retfie ; Init sets all I/O lines as outputs and selects PORTA as ; I/O lines by turning the comparators off. INIT clrf LCD_PORT movlw 0x07 bsf STATUS, RP0 ; Select bank 1 movlw b'00000000' ; Select PORTB as outputs movwf LCD_TRIS bcf STATUS, RP0 ; Select bank 0 ; Begin the LCD initialisation ; Power up timer should give delay, but do it anyway movlw 0x14 call delay ; Send the command to select 4-bit mode first bcf LCD_PORT, LCD_RS bcf LCD_PORT, LCD_RW movlw 0x02 ; Still in 8-bit, so appears as 0x20 to LCD call w_to_data call pulse_e ; Should now be in 4-bit mode - send init movlw b'00101000' call send_w movlw b'00001110' call send_w movlw b'00000110' call send_w ; ---------------------- send_w movwf R_SEND_W_TMP swapf R_SEND_W_TMP, F movlw 0x0F andwf R_SEND_W_TMP, W call w_to_data call pulse_e swapf R_SEND_W_TMP, F movlw 0x0F andwf R_SEND_W_TMP, W call w_to_data call pulse_e RETURN w_to_data movwf R_WDATA_TMP1 movf LCD_PORT, W movwf R_WDATA_TMP2 bcf R_WDATA_TMP2, LCD_D4 bcf R_WDATA_TMP2, LCD_D5 bcf R_WDATA_TMP2, LCD_D6 bcf R_WDATA_TMP2, LCD_D7 btfsc R_WDATA_TMP1, 0 bsf R_WDATA_TMP2, LCD_D4 btfsc R_WDATA_TMP1, 1 bsf R_WDATA_TMP2, LCD_D5 btfsc R_WDATA_TMP1, 2 bsf R_WDATA_TMP2, LCD_D6 btfsc R_WDATA_TMP1, 3 bsf R_WDATA_TMP2, LCD_D7 movf R_WDATA_TMP2, W movwf LCD_PORT return pulse_e bsf LCD_PORT, LCD_E nop nop nop nop bcf LCD_PORT, LCD_E call delay_1ms call delay_1ms return ; Calls the delay_1ms routine the number of times specified by ; the W register. delay movwf R_DEL2 delay_loop call delay_1ms decfsz R_DEL2, F goto delay_loop return ; When called gives a delay of about 1000 cycles, or 1ms at 4Mhz ; before the next instruction is executed. delay_1ms movlw d'248' movwf R_DEL1 delay_1ms_loop nop decfsz R_DEL1, F goto delay_1ms_loop return LCD_DELAY1 MOVLW D'255' MOVWF D2 LUS1 MOVLW D'255' MOVWF D1 LUS DECFSZ D1,F GOTO LUS DECFSZ D2,F GOTO LUS1 RETURN LCD_SCROLL_R1 MOVLW D'16' MOVWF SCROL2 LOOP1 LCD_MOVE_ALL_R LCD_DELAY DECFSZ SCROL2,F GOTO LOOP1 RETURN LCD_SCROLL_L1 MOVLW D'16' MOVWF SCROL1 LOOP2 LCD_MOVE_ALL_L LCD_DELAY DECFSZ SCROL1,F GOTO LOOP2 RETURN LIST