#INCLUDE <P18F4580.INC>
CONFIG OSC = HS ; Oscillator High Speed
CONFIG WDT = OFF ; WatchDog Timer disable
CONFIG LVP = OFF ; Low-Voltage In-Circuit Serial Programming (ICSP) disable
ORG 0H ; Start at address 0
LCD_CTRL EQU PORTC ; LCD control pins
LCD_DATA EQU PORTD ; LCD data pins RD0-RD7
LD1 EQU 0x01 ; Assign RAM locatation for LD1
LD2 EQU 0x02 ; Assign RAM locatation for LD2
D1 EQU 0x03 ; Assign RAM locatation for D1
D2 EQU 0x04 ; Assign RAM locatation for D2
D3 EQU 0x05 ; Assign RAM locatation for D3
SD1 EQU 0x06 ; Assign RAM locatation for SD1
SD2 EQU 0x07 ; Assign RAM locatation for SD2
MOVLW 0x0E ; WERG = 0E, outer loop count value
MOVWF ADCON1 ; Load 0E into ADCON1 configures the functions of the port pins
CLRF TRISC ; PortC as Output
CLRF TRISD ; PortD as Output
BCF LCD_CTRL, 7 ; (RC7) Enable = 0
CALL L_DELAY
MOVLW 0X38 ; Hex 38 = 2 line, matrix 5x7
CALL COMN_WRT ; Call command subroutine
CALL L_DELAY ; Initialization hold
MOVLW 0X0E ; Cursor blinking E/F
CALL COMN_WRT ; Call command subroutine
CALL DELAY ; Give LCD sometime
MOVLW 0X06 ; Shift cursor to the RIGHT
CALL COMN_WRT
CALL DELAY
AGAIN MOVLW 0X01 ; CLEAR Display screen
CALL COMN_WRT
CALL DELAY
;--------- Write 'LAB' to 1st Line ----------
MOVLW 0X80 ; Force cursor to the beginning of 1st Line
CALL COMN_WRT
CALL DELAY
MOVLW A'L'
CALL DATA_WRT ; Call display subroutine
CALL DELAY ; Give LCD sometime
MOVLW A'A'
CALL DATA_WRT
CALL DELAY
MOVLW A'B'
CALL DATA_WRT
CALL DELAY
;--------- Write 'OK' to 2nd Line ----------
MOVLW 0XC0 ; Force cursor to the beginning of 2nd Line
CALL COMN_WRT
CALL DELAY
MOVLW A'O'
CALL DATA_WRT
CALL DELAY
MOVLW A'K'
CALL DATA_WRT
CALL DELAY
BTG LCD_CTRL, 5 ; (RC5) RS (?)
BRA AGAIN
COMN_WRT ; send command to LCD
MOVWF LCD_DATA ; copy WERG to LCD DATA pin
BCF LCD_CTRL, 5 ; RS = 0 for Write Data
BCF LCD_CTRL, 6 ; R/W = 0 for write
BSF LCD_CTRL, 7 ; E = 1 for high pulse
CALL S_DELAY ; make a wide En pulse
BCF LCD_CTRL, 7 ; E = 0 for H to L pulse
RETURN ; Return to caller
DATA_WRT ; write data to LCD
MOVWF LCD_DATA ; copy WERG to LCD DATA pin
BSF LCD_CTRL, 5 ; RS = 1 for Write Data
BCF LCD_CTRL, 6 ; R/W = 0 for write
BSF LCD_CTRL, 7 ; E = 1 for high pulse
CALL S_DELAY ; make a wide En pulse
BCF LCD_CTRL, 7 ; E = 0 for H to L pulse
RETURN ; Return to caller
L_DELAY ; Long delay
MOVLW D'100' ; WERG = 10, outer loop count value
MOVWF LD1 ; Load 100 into location 1H
L1 MOVLW D'250' ; WERG = 250, inner loop count value
MOVWF LD2 ; Load 250 into location 2H
L2 DECF LD2 ; Dec file register location 2 (inner loop)
BNZ L2 ; Repeat it 250 times
DECF LD1 ; Dec file register location 1 (outer loop)
BNZ L1 ; Repeat it 100 times
RETURN ; Return to caller
DELAY ; Delay
MOVLW D'10' ; WERG = 10, outer loop count value
MOVWF D1 ; Load 10 into location 3H
L3 MOVLW D'200' ; WERG = 200, inner loop count value
MOVWF D2 ; Load 200 into location 4H
L4 MOVLW D'200' ; WERG = 200, inner loop count value
MOVWF D3 ; Load 200 into location 5H
L5 DECF D3 ; Dec file register location 5 (inner loop)
BNZ L5 ; Repeat it 200 times
DECF D2 ; Dec file register location 4 (inner loop)
BNZ L4 ; Repeat it 200 times
DECF D1 ; Dec file register location 3 (outer loop)
BNZ L3 ; Repeat it 10 times
RETURN ; Return to caller
S_DELAY ; Short delay
MOVLW D'10' ; WERG = 10, outer loop count value
MOVWF SD1 ; Load 10 into location 6H
L6 MOVLW D'250' ; WERG = 250, inner loop count value
MOVWF SD2 ; Load 250 into location 7H
L7 DECF SD2 ; Dec file register location 7 (inner loop)
BNZ L7 ; Repeat it 250 times
DECF SD1 ; Dec file register location 6 (outer loop)
BNZ L6 ; Repeat it 10 times
RETURN ; Return to caller
END ; End of asm source file
; Other command for LCD you can change anything you want
; MOVLW 0X38 ; Hex 38 = 2 line, matrix 5x7
; MOVLW 0X0E ; Cursor blinking E/F
; MOVLW 0X06 ; Shift cursor to the RIGHT
; MOVLW 0X01 ; CLEAR Display screen
; MOVLW 0X80 ; Force cursor to the beginning of 1st Line
; MOVLW 0XC0 ; Force cursor to the beginning of 2st Line
; MOVLW 0X1C ; Shift the entire display to the RIGHT
; MOVLW 0X18 ; Shift the entire display to the LEFT
CONFIG OSC = HS ; Oscillator High Speed
CONFIG WDT = OFF ; WatchDog Timer disable
CONFIG LVP = OFF ; Low-Voltage In-Circuit Serial Programming (ICSP) disable
ORG 0H ; Start at address 0
LCD_CTRL EQU PORTC ; LCD control pins
LCD_DATA EQU PORTD ; LCD data pins RD0-RD7
LD1 EQU 0x01 ; Assign RAM locatation for LD1
LD2 EQU 0x02 ; Assign RAM locatation for LD2
D1 EQU 0x03 ; Assign RAM locatation for D1
D2 EQU 0x04 ; Assign RAM locatation for D2
D3 EQU 0x05 ; Assign RAM locatation for D3
SD1 EQU 0x06 ; Assign RAM locatation for SD1
SD2 EQU 0x07 ; Assign RAM locatation for SD2
MOVLW 0x0E ; WERG = 0E, outer loop count value
MOVWF ADCON1 ; Load 0E into ADCON1 configures the functions of the port pins
CLRF TRISC ; PortC as Output
CLRF TRISD ; PortD as Output
BCF LCD_CTRL, 7 ; (RC7) Enable = 0
CALL L_DELAY
MOVLW 0X38 ; Hex 38 = 2 line, matrix 5x7
CALL COMN_WRT ; Call command subroutine
CALL L_DELAY ; Initialization hold
MOVLW 0X0E ; Cursor blinking E/F
CALL COMN_WRT ; Call command subroutine
CALL DELAY ; Give LCD sometime
MOVLW 0X06 ; Shift cursor to the RIGHT
CALL COMN_WRT
CALL DELAY
AGAIN MOVLW 0X01 ; CLEAR Display screen
CALL COMN_WRT
CALL DELAY
;--------- Write 'LAB' to 1st Line ----------
MOVLW 0X80 ; Force cursor to the beginning of 1st Line
CALL COMN_WRT
CALL DELAY
MOVLW A'L'
CALL DATA_WRT ; Call display subroutine
CALL DELAY ; Give LCD sometime
MOVLW A'A'
CALL DATA_WRT
CALL DELAY
MOVLW A'B'
CALL DATA_WRT
CALL DELAY
;--------- Write 'OK' to 2nd Line ----------
MOVLW 0XC0 ; Force cursor to the beginning of 2nd Line
CALL COMN_WRT
CALL DELAY
MOVLW A'O'
CALL DATA_WRT
CALL DELAY
MOVLW A'K'
CALL DATA_WRT
CALL DELAY
BTG LCD_CTRL, 5 ; (RC5) RS (?)
BRA AGAIN
COMN_WRT ; send command to LCD
MOVWF LCD_DATA ; copy WERG to LCD DATA pin
BCF LCD_CTRL, 5 ; RS = 0 for Write Data
BCF LCD_CTRL, 6 ; R/W = 0 for write
BSF LCD_CTRL, 7 ; E = 1 for high pulse
CALL S_DELAY ; make a wide En pulse
BCF LCD_CTRL, 7 ; E = 0 for H to L pulse
RETURN ; Return to caller
DATA_WRT ; write data to LCD
MOVWF LCD_DATA ; copy WERG to LCD DATA pin
BSF LCD_CTRL, 5 ; RS = 1 for Write Data
BCF LCD_CTRL, 6 ; R/W = 0 for write
BSF LCD_CTRL, 7 ; E = 1 for high pulse
CALL S_DELAY ; make a wide En pulse
BCF LCD_CTRL, 7 ; E = 0 for H to L pulse
RETURN ; Return to caller
L_DELAY ; Long delay
MOVLW D'100' ; WERG = 10, outer loop count value
MOVWF LD1 ; Load 100 into location 1H
L1 MOVLW D'250' ; WERG = 250, inner loop count value
MOVWF LD2 ; Load 250 into location 2H
L2 DECF LD2 ; Dec file register location 2 (inner loop)
BNZ L2 ; Repeat it 250 times
DECF LD1 ; Dec file register location 1 (outer loop)
BNZ L1 ; Repeat it 100 times
RETURN ; Return to caller
DELAY ; Delay
MOVLW D'10' ; WERG = 10, outer loop count value
MOVWF D1 ; Load 10 into location 3H
L3 MOVLW D'200' ; WERG = 200, inner loop count value
MOVWF D2 ; Load 200 into location 4H
L4 MOVLW D'200' ; WERG = 200, inner loop count value
MOVWF D3 ; Load 200 into location 5H
L5 DECF D3 ; Dec file register location 5 (inner loop)
BNZ L5 ; Repeat it 200 times
DECF D2 ; Dec file register location 4 (inner loop)
BNZ L4 ; Repeat it 200 times
DECF D1 ; Dec file register location 3 (outer loop)
BNZ L3 ; Repeat it 10 times
RETURN ; Return to caller
S_DELAY ; Short delay
MOVLW D'10' ; WERG = 10, outer loop count value
MOVWF SD1 ; Load 10 into location 6H
L6 MOVLW D'250' ; WERG = 250, inner loop count value
MOVWF SD2 ; Load 250 into location 7H
L7 DECF SD2 ; Dec file register location 7 (inner loop)
BNZ L7 ; Repeat it 250 times
DECF SD1 ; Dec file register location 6 (outer loop)
BNZ L6 ; Repeat it 10 times
RETURN ; Return to caller
END ; End of asm source file
; Other command for LCD you can change anything you want
; MOVLW 0X38 ; Hex 38 = 2 line, matrix 5x7
; MOVLW 0X0E ; Cursor blinking E/F
; MOVLW 0X06 ; Shift cursor to the RIGHT
; MOVLW 0X01 ; CLEAR Display screen
; MOVLW 0X80 ; Force cursor to the beginning of 1st Line
; MOVLW 0XC0 ; Force cursor to the beginning of 2st Line
; MOVLW 0X1C ; Shift the entire display to the RIGHT
; MOVLW 0X18 ; Shift the entire display to the LEFT