Code:
'**************************************************************** *
'* : PIC16F628 *
'****************************************************************
;-- Place a copy of these variables in your Main program -------------------
;-- The compiler will tell you which lines to un-comment --
;-- Do Not un-comment these lines --
;---------------------------------------------------------------------------
;wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
wsave VAR BYTE $70 SYSTEM ' alternate save location for W
' if using $70, comment wsave1-3
' --- IF any of these three lines cause an error ?? ------------------------
' Comment them out to fix the problem ----
' -- Which variables are needed, depends on the Chip you are using --
wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
;wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
' --------------------------------------------------------------------------
define OSC 10 'oscillator setting
define LCD_COMMANDUS 1500 'set command delay in us
define LCD_DATAUS 50 'set data delay in us
define LCD_DREG PORTB 'set LCD data port
define LCD_DBIT 4 'set LCD starting data bit
define LCD_RSREG PORTB 'define RS port
define LCD_RSBIT 2 'define RS bit
define LCD_EREG PORTB '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
cmcon=7
trisb=%00000000
trisa=%11111111
input porta.0
input porta.1
input porta.2
nPos var byte
nDig var byte
'CONFIGURE DISPLAY
pause 100
ln1 con $80
ln2 con $C0
CS con 1
pause 500
LCDOUT $FE,1
'setup the custom characters
LCDOUT $FE,$40,$01,$01,$01,$01,$01,$01,$01,$01 ' Cust Char #0
LCDOUT $FE,$48,$1F,$11,$11,$11,$11,$11,$11,$11 ' Cust Char #1
LCDOUT $FE,$50,$1F,$10,$10,$10,$10,$10,$10,$1F ' Cust Char #2
LCDOUT $FE,$58,$01,$01,$01,$01,$01,$01,$01,$1F ' Cust Char #3
LCDOUT $FE,$60,$1F,$11,$11,$11,$11,$11,$11,$1F ' Cust Char #4
LCDOUT $FE,$68,$11,$11,$11,$11,$11,$11,$11,$1F ' Cust Char #5
LCDOUT $FE,$70,$1F,$01,$01,$01,$01,$01,$01,$1F ' Cust Char #6
LCDOUT $FE,$78,$1F,$01,$01,$01,$01,$01,$01,$01 ' Cust Char #7
LCDOUT $FE,$80,$01,$01,$01,$01,$01,$01,$01,$01 ' Cust Char #0
'ELAPSED TIMER
INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
INCLUDE "Elapsed_INT.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
lcdout $fe, CS ' Clear screen
MAIN: 'Display time
if porta.0 = 1 then GOSUB StartTimer ' Start the Elapsed Timer
if porta.1 = 1 then gosub StopTimer
if porta.2 = 1 then GOSUB ResetTime ' Reset Time
nDig=seconds dig 2 : nPos=0 : gosub displaydigit 'hundreds
nDig=seconds dig 1 : nPos=1 : gosub displaydigit 'tens
ndig=seconds dig 0 : npos=2 : gosub displaydigit 'ones
LCDOUT $FE,$C0+3,":"
ndig=ticks dig 1 : npos=4 : gosub displaydigit 'tenths
ndig=ticks dig 0 : npos=5 : gosub displaydigit 'hundreths
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,1
LCDOUT $FE,$C0+nPos,5
return
One:
LCDOUT $FE,$80+nPos,0
LCDOUT $FE,$C0+nPos,0
return
Two:
LCDOUT $FE,$80+nPos,7
LCDOUT $FE,$C0+nPos,2
return
Three:
LCDOUT $FE,$80+nPos,6
LCDOUT $FE,$C0+nPos,3
return
Four:
LCDOUT $FE,$80+nPos,5
LCDOUT $FE,$C0+nPos,0
return
Five:
LCDOUT $FE,$80+nPos,2
LCDOUT $FE,$C0+nPos,3
return
Six:
LCDOUT $FE,$80+nPos,2
LCDOUT $FE,$C0+nPos,5
return
Seven:
LCDOUT $FE,$80+nPos,7
LCDOUT $FE,$C0+nPos,0
return
Eight:
LCDOUT $FE,$80+nPos,4
LCDOUT $FE,$C0+nPos,5
return
Nine:
LCDOUT $FE,$80+nPos,4
LCDOUT $FE,$C0+nPos,3
return
end
Bookmarks