Code:
asm
db 0,4,4,1, 7,32,32,7, 7,32,32,7, 3,5,5,2 ;0
db 32,8,7,32, 32,32,7,32, 32,32,7,32, 32,32,7,32 ;1
db 0,4,4,1, 32,32,5,4, 5,4,32,32, 7,5,5,5 ;2
db 2,4,4,1, 32,32,32,7, 32,4,4,7, 1,5,5,2 ;3
db 7,32,32,7, 7,5,5,7,32, 32,32,7, 32,32,32,7 ;4
db 7,4,4,3, 7,5,5,32, 32,32,32,1, 5,5,5,2 ;5
db 0,4,4,1, 7,32,32,32, 7,4,4,1, 3,5,5,2 ;6
db 4,4,4,1, 32,32,32,7, 32,32,7,32, 32,7,32,32 ;7
db 0,4,4,1, 3,5,5,2,0, 32,32,1, 3,5,5,2 ;8
db 0,4,4,1, 3,5,5,7, 32,32,32,7, 32,5,5,2 ;9
db 32,32,32,32, 32,32,32,32, 32,32,32,32, 32,32,32,32 ;blank
endasm
fully defining the font and adding a blank make leading zero suppression/ field justification far easier
Code:
#CONFIG
CONFIG FOSC = INTIO67
CONFIG PLLCFG = ON
CONFIG PRICLKEN = OFF
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRTEN = OFF
CONFIG BOREN = SBORDIS
CONFIG BORV = 190
CONFIG WDTEN = ON
CONFIG WDTPS = 32768
CONFIG CCP2MX = PORTC1
CONFIG PBADEN = OFF
CONFIG CCP3MX = PORTB5
CONFIG HFOFST = ON
CONFIG T3CMX = PORTC0
CONFIG P2BMX = PORTB5
CONFIG MCLRE = EXTMCLR
CONFIG STVREN = ON
CONFIG LVP = OFF
CONFIG XINST = OFF
CONFIG DEBUG = OFF
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CPB = OFF
CONFIG CPD = OFF
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF
CONFIG EBTRB = OFF
#ENDCONFIG
DEFINE OSC 64
OSCCON = %01110000
ANSELb = 0
ANSELA = 0
ANSELC = 0
OSCTUNE.6=1
goto overasm
asm
bigfont ;pic18 only must be in 1st 64k block
db 0,4,4,1, 7,32,32,7, 7,32,32,7, 3,5,5,2 ;0
db 32,8,7,32, 32,32,7,32, 32,32,7,32, 32,32,7,32 ;1
db 0,4,4,1, 32,32,5,4, 5,4,32,32, 7,5,5,5 ;2
db 2,4,4,1, 32,32,32,7, 32,4,4,7, 1,5,5,2 ;3
db 7,32,32,7, 7,5,5,7,32, 32,32,7, 32,32,32,7 ;4
db 7,4,4,3, 7,5,5,32, 32,32,32,1, 5,5,5,2 ;5
db 0,4,4,1, 7,32,32,32, 7,4,4,1, 3,5,5,2 ;6
db 4,4,4,1, 32,32,32,7, 32,32,7,32, 32,7,32,32 ;7
db 0,4,4,1, 3,5,5,2,0, 32,32,1, 3,5,5,2 ;8
db 0,4,4,1, 3,5,5,7, 32,32,32,7, 32,5,5,2 ;9
db 32,32,32,32, 32,32,32,32, 32,32,32,32, 32,32,32,32 ;blank
ft1=_rowbuff ;shortcut to read data into rowbuffer 0:1
ft2=_rowbuff+2 ;shortcut to read data into rowbuffer 2:3
GLetAddress macro Label, Wout
CHK?RP Wout
movlw low Label ; get low byte
movwf Wout
movlw High Label ; get high byte
movwf Wout + 1
BANKSEL 0
endm
endasm
overasm:
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
Define LCD_Bits 4
DEFINE LCD_LINES 4
Define LCD_Commandus 2000
Define LCD_DATAUS 50
ROW VAR BYTE '4 X 20 ROW NUMBER - 0 TO 3
COL VAR BYTE '4 X 20 COLUMN NUMBER - 0 TO 4
slz var bit
rows var byte[4] ;lcd page start addresses
rowbuff var byte[4] ;a row of data for lcd
ctemp var word
ft1 var word ext ;shortcut to read data into rowbuffer 0:1
ft2 var word ext ;shortcut to read data into rowbuffer 2:3
parsedig var byte
NUMBER VAR WORD
TEMP VAR WORD
COL_OFFSET VAR BYTE ' USED TO POSITION font
font var word ;address of data
NUMBER = 0
lcdout 254,$01 ' CLEAR THE DISPLAY
pause 500
arraywrite rows,[128,192,148,212] ;pbp3 for earlier rows[0]=128:rows[0]=192: etc.........
pause 100
@ GLetAddress bigfont ,_font ;get font address
''' FIRST WRITE THE CHARACTER PATTERNS TO LCD RAM FOR A PATTERN DISPLAY
' 0 Left-right UP-ramp (TOP)
lcdout 254,$40,$00,$01,$03,$07,$0F,$1F,$1F,$1F
lcdout 254,rows[0], 0
PAUSE 1
' 1 Right-left DOWN-ramp (TOP)
lcdout 254,$48,$00,$10,$18,$1C,$1E,$1F,$1F,$1F
lcdout 254,rows[0]+2, 1
PAUSE 1
' 2 Left-right UP-ramp. (BOTTOM)
lcdout 254,$50,$1F,$1F,$1F,$1E,$1C,$18,$10,$00
lcdout 254,rows[0]+4, 2
PAUSE 1
' 3 Right-left DOWN-ramp (BOTTOM)
lcdout 254,$58,$1F,$1F,$1F,$0F,$07,$03,$01,$00
lcdout 254,rows[0]+6, 3
pause 1
' 4 UPPER block.
lcdout 254,$60,$1F,$1F,$1F,$1F,$00,$00,$00,$00
lcdout 254,rows[0]+8, 4
PAUSE 1
' 5 LOWER block.
lcdout 254,$68,$00,$00,$00,$00,$1F,$1F,$1F,$1F
lcdout 254,rows[0]+10, 5
PAUSE 1
'6 SMALL UP-RAMP
lcdout 254,$70,$01,$03,$07,$0F,$1F,$00,$00,$00 '6
lcdout 254,rows[0]+12, 6
PAUSE 1
' '7 FULL BLOCK
lcdout 254,$78,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F '7
lcdout 254,rows[0]+14, 7
PAUSE 2000 ' SHORT DELAY TO DISPLAY THE SPECIAL CHARACTERS
lcdout 254,$01 ' CLEAR THE DISPLAY
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
START: ;display 4 digits right justified with noleading zeros
parsedig = 4
slz = 1 ;suppress leading zeros on
col = 0
while parsedig
parsedig = parsedig - 1
TEMP = NUMBER DIG parsedig
if slz then
if temp then ;if temp > 0 then display it and cancel zero suppression
GOSUB DISPLAY
slz = 0 ;suppress zeros cancelled
else
if parsedig then temp = 10;blank suppress all zeros except for dig 0
GOSUB DISPLAY
endif
else
GOSUB DISPLAY
endif
col = col + 1
wend
pause 10
NUMBER = number + 1
if number>9999 then number=0
GOTO START
;pic18 only font must be in 1st 64k block for readcode to function
DISPLAY: ;disp big digit in TEMP var @ column COL digits 0-9 and blank
COL_OFFSET = (col*5)
ctemp = font + (temp*16); 16 bytes per chr
for row = 0 to 3 ;read data as words to reduce code and more speed
readcode ctemp,ft1 ;shortcut to read data into rowbuffer 0:1
ctemp = ctemp + 2 ;next word
readcode ctemp,ft2 ;shortcut to read data into rowbuffer 2:3
ctemp = ctemp + 2 ;next row
lcdout 254,(COL_OFFSET + rows[row]),str rowbuff\4;for early versions pbp might need rowbuff[0],rowbuff[1],rowbuff[2],rowbuff[3]
next
RETURN
END
Bookmarks