AtomSoft
Well-Known Member
futz hope you dont mind i modded your code to replace my busted RA1 pin to the RB0 pin works 100% :
Code:
list p=18F1320
include <p18F1320.inc>
CONFIG OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF
cblock 0x00
d1,d2,d3,count,count2,dataout,temp,dec1,dec2
endc
org 0x0000
init bsf OSCCON,IRCF2 ;set to 8MHz clock
bsf OSCCON,IRCF1
bsf OSCCON,IRCF0
clrf TRISA
clrf TRISB
clrf LATA
clrf LATB
setf ADCON1 ;make PORTA all digital
clrf count
call dl_40ms ;allow lcd to settle before init
call lcdinit ;initialize lcd
goto main
table1 db "Junebug LCD Demo",0x00
main movlw HIGH table1 ;display table1
movwf TBLPTRH
movlw LOW table1
movwf TBLPTRL
mnloop tblrd *+
movf TABLAT,W
xorlw 0x00 ;zero?
btfsc STATUS,Z
goto next ;yes, done
movwf dataout ;no, go again
call lcdchar
call dl_50us ;wait 50us
goto mnloop
next call lcd_line2
call dl_50us
nbs movlw d'100' ;count down from 100 on second line
movwf count2
nubs decfsz count2
goto numbs
goto dood
numbs movf count2,W
call fix
movf dec1,W
movwf dataout
call lcdchar
call dl_50us
movf dec2,w
movwf dataout
call lcdchar
call Delay
call lcd_line2
goto nubs
dood goto nbs
;*************************************************************
; fix - subroutine takes byte passed in W - splits it into two
; ascii bytes in dec1 and dec2, representing decimal digits.
fix: movwf dec2 ;put number in dec2
clrf count ;count = 0
movlw 0x0a ;W = 10
tens: subwf dec2,F ;subtract 10 from number
btfsc STATUS,C ;result <10?
goto again ;no, go again
movf count,W ;yes, put count in W
addlw 0x30 ;add $30 to make it an ASCII number
movwf dec1 ;and store it in dec1
movf dec2,W ;get remainder (2nd digit)
addlw 0x0a ;put the last subtract back
addlw 0x30 ;add $30 to make it ASCII
movwf dec2 ;store it back in dec2
return ;and return
again: incf count,F ;increment count
goto tens ;go again
lcd_line1
movlw 0x80
movwf dataout
call lcdcmd
call dl_50us
return
lcd_line2
movlw 0xc0
movwf dataout
call lcdcmd
call dl_50us
return
lcdinit movlw 0x06 ;send 03 nybble
movwf PORTA
BSF PORTB, 0
call e_togg
call dl_05ms ;wait 5ms
movlw 0x06 ;send 3 second time
movwf PORTA
BSF PORTB, 0
call e_togg
call dl_160us ;wait 160us
movlw 0x06 ;send 3 third time
movwf PORTA
BSF PORTB, 0
call e_togg
call dl_160us ;wait 160us
movlw 0x04 ;enable 4-bit mode
movwf PORTA
BCF PORTB, 0
call e_togg
call dl_50us ;wait 50us
movlw 0x28 ;set 4-bit mode and 2-lines
movwf dataout
call lcdcmd
call dl_50us ;wait 50us
movlw 0x10 ;cursor move & shift left
movwf dataout
call lcdcmd
call dl_50us ;wait 50us
movlw 0x06 ;entry mode = increment
movwf dataout
call lcdcmd
call dl_50us ;wait 50us
movlw 0x0d ;display on, cursor on, blink on
movwf dataout
call lcdcmd
call dl_50us ;wait 50us
movlw 0x01 ;clear display
movwf dataout
call lcdcmd
call dl_05ms ;wait 5ms
return
lcdcmd swapf dataout,W ;swap nybbles and transfer to w
andlw 0x0f ;mask out high nybble
movwf temp ;rotate left one bit for A1-A4
rlncf temp,F
movff temp,LATA ;stuff result in PORTA [b]
BTFSC temp, 1 ;RA1 to RB0 Fix
bra $+6
BCF LATB, 0
bra $+4 ;end of fix[/b]
BSF LATB, 0
bcf LATB,1 ;set RS low
call e_togg ;latch the data
movf dataout,W ;get byte in w again
andlw 0x0f ;and mask out high nybble
movwf temp
rlncf temp,F
movff temp,PORTA ;Stuff [b]
BTFSC temp, 1 ;RA1 to RB0 Fix
bra $+6
BCF LATB, 0
bra $+4 ;end of fix[/b]
BSF LATB, 0
bcf LATB,1 ;set RS low
call e_togg ;latch the data
goto bleh ;3 cycles - 600ns delay
bleh nop
nop
return
lcdchar swapf dataout,W ;swap nybbles and transfer to w
andlw 0x0f ;mask out high nybble
movwf temp ;rotate left one bit for A1-A4
rlncf temp,F
movff temp,LATA ;stuff result in PORTA [b]
BTFSC temp, 1 ;RA1 to RB0 Fix
bra $+6
BCF LATB, 0
bra $+4 ;end of fix[/b]
BSF LATB, 0
bsf LATB,1 ;set RS high
call e_togg ;latch the data
movf dataout,w ;get byte in w again
andlw 0x0f ;and mask out high nybble
movwf temp
rlncf temp,F
movff temp,LATA ;stuff [b]
BTFSC temp, 1 ;RA1 to RB0 Fix
bra $+6
BCF LATB, 0
bra $+4 ;end of fix[/b]
BSF LATB, 0
bsf LATB,1 ;set RS high
bsf LATB,1 ;RS high
call e_togg ;latch the data
goto bleh2 ;3 cycles - 600ns delay
bleh2 nop
nop
return
e_togg bsf LATB,4 ;toggle E to latch data
nop ;delay 450ns minimum
nop
nop
bcf LATB,4
return
dl_40ms movlw 0x7e ;40ms delay
movwf d1
movlw 0x3f
movwf d2
dl40_0 decfsz d1,F
goto $+6
decfsz d2,F
goto dl40_0
nop
return
dl_05ms movlw 0xce ;5ms delay
movwf d1
movlw 0x08
movwf d2
dl05_0 decfsz d1,F
goto $+6
decfsz d2,F
goto dl05_0
return
dl_160us ;160us delay
movlw 0x69
movwf d1
dl160_0 decfsz d1,F
goto dl160_0
return
dl_50us movlw 0x1f ;50us delay
movwf d1
dl50_0 decfsz d1,F
goto dl50_0
return
Delay movlw 0x0c ;.75 second delay
movwf d1
movlw 0x46
movwf d2
movlw 0x04
movwf d3
Delay_0 decfsz d1,F
goto $+6
decfsz d2,F
goto $+6
decfsz d3,F
goto Delay_0
return
end