Code:
'****************************************************************
'* Name : BigDigitTimer.BAS *
'* Author : Shawn Newswanger *
'* Notice : Copyright (c) 2012 *
'* : All Rights Reserved *
'* Date : 1/8/2012 *
'* Version : 1.0 *
'* Notes : PIC18F2221 with internal OSC *
'****************************************************************
OSCCON=110000 'SET TO 8 MHZ
define OSC 08 '8MHz oscilator
define LCD_COMMANDUS 1500 'set command delay in us
define LCD_DATAUS 50 'set data delay in us
define LCD_DREG PORTC 'set LCD data port
define LCD_DBIT 4 'set LCD starting data bit
define LCD_RSREG PORTC 'define RS port
define LCD_RSBIT 2 'define RS bit
define LCD_EREG PORTC 'set LCD ENABLE port
define LCD_EBIT 3 'set LCD ENABLE bit
define LCD_BITS 4 'set LCD bits 4 or 8
define LCD_LINES 2 'set # of LCD rows 2 or 4
clear
ADCON1 = 15 'all digital
CMCON = 7 'turns off comparators
trisc=0
trisb=0
trisa=0
nPos var byte
nDig var byte
'CONFIGURE DISPLAY
pause 100
ln1 con $80
ln2 con $C0
CS con 1
pause 500
LCDOUT $FE,1
'Set up the digits (http://www.darreltaylor.com/files/CustChar.htm)
LCDOUT $FE,$40,$1F,$1F,$1F,$00,$00,$1F,$1F,$1F ' Cust Char #0
LCDOUT $FE,$48,$1F,$1F,$1F,$00,$00,$00,$00,$00 ' Cust Char #1
LCDOUT $FE,$50,$00,$00,$00,$00,$00,$1F,$1F,$1F ' Cust Char #2
LCDOUT $FE,$58,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F ' Cust Char #3
LCDOUT $FE,$60,$00,$0E,$0A,$0E,$00,$00,$00,$00 ' Cust Char #4
LCDOUT $FE,$68,$00,$00,$0E,$0A,$0A,$0E,$00,$00 ' Cust Char #5
LCDOUT $FE,$70,$00,$00,$04,$0A,$0A,$04,$00,$00 ' Cust Char #6
LCDOUT $FE,$78,$00,$00,$00,$00,$00,$00,$00,$00 ' Cust Char #7
'ELAPSED TIMER
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
INCLUDE "Elapsed_INT-18.bas" ; Elapsed Timer Routines
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer
lcdout $fe, CS ' Clear screen
MAIN: 'Display time
IF secondsChanged = 1 THEN
secondsChanged = 0
nDig=minutes dig 1 : nPos=0 : gosub displaydigit
ndig=minutes dig 0 : npos=4 : gosub displaydigit
npos=7 : gosub colon
ndig=seconds dig 1 : npos=8 : gosub displaydigit
ndig=seconds dig 0 : npos=12 : gosub displaydigit
ENDIF
goto main
displaydigit:
if ndig=0 then gosub zero
if ndig=1 then gosub one
if ndig=2 then gosub two
if ndig=3 then gosub three
if ndig=4 then gosub four
if ndig=5 then gosub five
if ndig=6 then gosub six
if ndig=7 then gosub seven
if ndig=8 then gosub eight
if ndig=9 then gosub nine
return
Zero:
LCDOUT $FE,$80+nPos,3,1,3
LCDOUT $FE,$C0+nPos,3,2,3
return
One:
LCDOUT $FE,$80+nPos,1,3,7
LCDOUT $FE,$C0+nPos,2,3,2
return
Two:
LCDOUT $FE,$80+nPos,0,0,3
LCDOUT $FE,$C0+nPos,3,2,2
return
Three:
LCDOUT $FE,$80+nPos,1,0,3
LCDOUT $FE,$C0+nPos,2,2,3
return
Four:
LCDOUT $FE,$80+nPos,3,2,3
LCDOUT $FE,$C0+nPos,7,7,3
return
Five:
LCDOUT $FE,$80+nPos,3,0,0
LCDOUT $FE,$C0+nPos,2,2,3
return
Six:
LCDOUT $FE,$80+nPos,3,0,0
LCDOUT $FE,$C0+nPos,3,2,3
return
Seven:
LCDOUT $FE,$80+nPos,1,1,3
LCDOUT $FE,$C0+nPos,7,3,7
return
Eight:
LCDOUT $FE,$80+nPos,3,0,3
LCDOUT $FE,$C0+nPos,3,2,3
return
Nine:
LCDOUT $FE,$80+nPos,3,0,3
LCDOUT $FE,$C0+nPos,7,7,3
return
colon:
lcdout $fe,$80+nPos,5
lcdout $FE,$C0+nPos,5
return
end
Bookmarks