; processor 16F88
; include <p16f88.inc>
; __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
; __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF
;
processor 16f84a
include<p16f84a.inc>
__config _RC_OSC & _WDT_OFF & _PWRTE_ON
;
;SPECIFY REGISTER
;
counter_l EQU 20H
counter_s EQU 21H
temp EQU 22H
porta EQU 05h
portb EQU 06h
RS EQU 0h
RW EQU 1h
E EQU 2h
;PROGRAM
org 00h
SETPORT movlw b'00000000' ;
tris porta ;
;RA0,1,2 are RS, RW and E respectively of lcd control
;lines, RA4 is the analog input for AD converter
;
movlw b'00000000' ;
tris portb ;
;all of the 8 pins of portb are configured as outputs.
;Only the higher nibble will be used to send data
;and command to the lcd module
;
bcf porta,E ;
;setting E to high restrics any sort of write operation
;from the mcu to lcd module
;
initio movlw 14h ;
movwf temp ;
loop call delay_1ms ;
decfsz temp,F ;
goto loop ;
;A 20ms delay will give the lcd module enough time to
;stabilize itself on power up
;
bcf porta,RS ;
bcf porta,RW ;
movlw 30h ;
movwf portb ;
call enab_lcd ;
;the above segment sends the command
;RS RW DB7 DB6 DB5 DB4=000011 as required by the module
;ref:HD44780 datasheet 4-bit mode
movlw 05h ;
movwf temp ;
five_ms call delay_1ms ;
decfsz temp,F ;
goto five_ms ;
;5ms delay ref:HD44780 datasheet 4-bit mode
;
; bcf porta,RS ;
; bcf porta,RW ;
movlw 30h ;
movwf portb ;
call enab_lcd ;
;RS RW DB7 DB6 DB5 DB4=000011 as required by the module
;ref:HD44780 datasheet 4-bit mode
;
movlw 46h ;
movwf temp ;
delay_200us decfsz temp,F ;
goto delay_200us ;
;200us delay ref:HD44780 datasheet 4-bit mode
;
; bcf porta,RS ;
; bcf porta,RW ;
movlw 30h ;
movwf portb ;
call enab_lcd ;
;again the same bit sequence is sent as before
;i.e 000011
;
fucntion_set bcf porta,RS ;
bcf porta,RW ;
movlw 20h ;
movwf portb ;
call enab_lcd ;
;DB4 is cleared to select 4-bit mode
;from now on every byte is sent in two nibbles and the
;the higher nibble is sent first
;
; bcf porta,RS ;
; bcf porta,RW ;
movlw 20h ;
movwf portb ;
call enab_lcd ;
movlw 00h ;
movwf portb ;
call enab_lcd ;
;the function set command is sent again. the upper nibble
;being the same as before but the lower nibble specifying
;1-line and 5*7 pixel format i.e N=0 F=0
;ref:HD44780 datasheet
;
movlw 20h ;
movwf portb ;
call enab_lcd ;
movlw 80h ;
movwf portb ;
call enab_lcd ;
;display off command 00001000 ref:HD44780 datasheet
movlw 00h ;
movwf portb ;
call enab_lcd ;
movlw 60h ;
movwf portb ;
call enab_lcd ;
;display on command 00000001 ref:HD44780 datasheet
movlw 00h ;
movwf portb ;
call enab_lcd ;
movlw 0C0h ;
movwf portb ;
call enab_lcd ;
;entry mode set command 00000110. I/D=1 making the cursor
;to shift to the right while S=0 does not permit the
;entire display to shift right or left
;
;END OF INITIALIZATION
;
;*****************DEMO_CODE*****************
;
bsf porta,RS ;
bcf porta,RW ;
movlw 30h ;
movwf portb ;
call enab_lcd ;
movlw 50h ;
movwf portb ;
call enab_lcd ;
;call CURSOR_SHIFT ;
;writes 5 on the lcd screen
movlw 30h ;
movwf portb ;
call enab_lcd ;
movlw 70h ;
movwf portb ;
call enab_lcd ;
;call CURSOR_SHIFT ;
;writes 7 on the lcd screen
movlw 70h ;
movwf portb ;
call enab_lcd ;
movlw 00h ;
movwf portb ;
call enab_lcd ;
;call CURSOR_SHIFT ;
;writes p on the lcd screen
movlw 70h ;
movwf portb ;
call enab_lcd ;
movlw 00h ;
movwf portb ;
call enab_lcd ;
;call CURSOR_SHIFT ;
;writes p on the lcd screen
movlw 60h ;
movwf portb ;
call enab_lcd ;
movlw 20h ;
movwf portb ;
call enab_lcd ;
;call CURSOR_SHIFT ;
FIN goto FIN ;
;writes b on the lcd screen
;CURSOR SHIFT COMMAND SUBROUTINE
CURSOR_SHIFT bcf porta,RW ;
bcf porta,RS ;
movlw 10h ;
movwf portb ;
call enab_lcd ;
movlw 40h ;
movwf portb ;
call enab_lcd ;
return ;
;********************DEMO_CODE_ENDS*************
;SUBROUTINES
;
enab_lcd bsf porta,E ;
nop ;
bcf porta,E ;
nop ;
return ;
;data is transferred when E goes from high to low
;
delay_1ms movlw 0ffh ;
movwf counter_s ;
point nop ;
decfsz counter_s,F ;
goto point ;
return ;
END