list p=16f628a
#include <P16F628A.inc> ;Tell the assembler to generate code for this device
errorlevel -302
__config _XT_OSC & _PWRTE_ON & _WDT_OFF & _CP_OFF & _BODEN_ON & _LVP_OFF & _MCLRE_OFF
counter_reg equ 0x20
short_delay equ 0x21
long_delay equ 0x22
movlw 0x07
movwf CMCON ;make all pins i/0
goto start
start clrf counter_reg ;Clear register (Counter Register)
clrf short_delay ;Clear register (Short Delay Register)
clrf long_delay ;Clear register (Long Delay Register)
clrf PORTA ;PORT A (Register 05) Set all outputs to logic 0
clrf PORTB ;PORT B (Register 06) Set all outputs to logic 0
setports BSF STATUS,RP0
movlw 0xF8 ;PORT A bits 0,1,2 as outputs (E,RS,RW)
MOVWF TRISA
movlw 0X00 ;Port B all bits as outputs (DO - D7)
MOVWF TRISB ;06
BCF STATUS,RP0
longdelay
clrf long_delay
ldelay call SDELAY ;Delay while LCD initialises
decfsz long_delay,f
goto ldelay
functionset bcf PORTA,2 ;RS line to 0 (Port A, bit2)
bcf PORTA,1 ;R/W line to 0 (Port A, bit 1)
movlw 38 ;Function set command (00111000 - 8 bit transfer, 2 line mode, 5x10 dot format)
movwf PORTB ;Put this code on the data lines Port B
call pulse_E ;Call the routine to pulse the E line (Port A bit 0)
call SDELAY ;Give it time to get it
displayon bcf PORTA,2 ;RS line to 0 (Port A, bit2)
bcf PORTA,1 ;R/W line to 0 (Port A, bit 1)
movlw 0F ;Display on/off & curosr (00001111 - Display on, Cursor Underline, Cursor Blink)
movwf PORTB ;Put this code on the data lines Port B
call pulse_E ;Call the routine to pulse the E line (Port A bit 0)
call SDELAY ;Give it time to get it
clrf counter_reg ;Set counter register to zero
getchar movf counter_reg,w ;Put the counter value in the W register (now we can use it)
call text ;Get a character from te text table below
bsf PORTA,2 ;RS line to 1 (Port A, bit2)
bcf PORTA,1 ;R/W line to 0 (Port A, bit 1)
movwf PORTB ;Put the character fetched from the table on Port B
call pulse_E ;Call the routine to pulse the E line (Port A bit 0)
call SDELAY ;Give it time to get it
incf counter_reg,w ;Try incrementing the counter register
xorlw 05 ;Is the counter register at 5?
btfsc STATUS,2 ;Set the zero flag in the status register
goto stop ;Stop if all characters displayed
incf counter_reg,f ;Increment the counter register
goto getchar ;Go back and get the next character
stop goto stop ;Stop the program
;Here are the subroutines
pulse_E bsf PORTA,0 ;Set the E line High
nop ;wait for a clock cycle
bcf PORTA,0 ;Set the E line low again
retlw 0
SDELAY
clrf short_delay
shortdelay decfsz short_delay,f ;Delay while the LCD is busy
goto shortdelay
retlw 0
text addwf 02,f
retlw 'H'
retlw 'E'
retlw 'L'
retlw 'L'
retlw 'O'
end