Code:
Include "modedefs.bas" ' Include serial modes
Define OSC 4 ' 4MHz crystal
CMCON = 7 ' All digital
OPTION_REG = %10000111 ' TMRO prescale = 256
TRISA = %00010000 ' All outputs except RA4
TRISB = %00000000 ' All outputs ...
INTCON.5 = 1 ' Enable TMR0 interrupts
INTCON.2 = 0 ' Reset overflow flag
on interrupt goto Clock
'// Chrs (0-9) stored in on-chip E²PROM
data @0,62,65,65,65,62 ' 0
data @5,64,127,66,0,0 ' 1
data @10,70,73,81,97,66 ' 2
data @15,54,73,73,65,34 ' 3
data @20,16,127,18,20,24 ' 4
data @25,49,73,73,73,39 ' 5
data @30,50,73,73,73,62 ' 6
data @35,3,5,9,113,1 ' 7
data @40,54,73,73,73,54 ' 8
data @45,62,73,73,73,38 ' 9
data @50,0,0,0,0,0 ' Space
data @55,8,8,8,8,8 ' Colm
Row_Data VAR BYTE ' Contains one column worth of a chr at a time
Column_Scan VAR BYTE ' Current col that's active
Digit_Pos Var byte ' E²PROM address pointing to current col data
Digit_Loc VAR Byte ' Start E²PROM address for new chr
Colm var byte ' Blinking colm ...
Counter VAR Word ' Time keeping counter
Secs_Digit1 var byte ' Secs (1's)
Secs_Digit2 var byte ' Secs (10's)
Mins_Digit1 var byte ' Mins (1's)
Mins_Digit2 var byte ' Mins (10's)
Hrs_Digit1 var byte ' Hrs (1's)
Hrs_Digit2 var byte ' Hrs (10's)
Clock_Cols VAR PORTB.6
Reset_Cols VAR PORTB.5
ROW1 VAR PORTA.2
ROW2 VAR PORTA.3
ROW3 VAR PORTB.4
ROW4 VAR PORTB.3
ROW5 VAR PORTB.0
ROW6 VAR PORTB.2
ROW7 VAR PORTB.1
Prog_Button VAR PORTA.4
TX_To_PC var PORTB.7
Counter = $7A12
TMR0 = 0
Column_Scan = 0
Digit_Pos = 0
Secs_Digit1 = 0
Secs_Digit2 = 0
Mins_Digit1 = 0
Mins_Digit2 = 0
Hrs_Digit1 = 2
Hrs_Digit2 = 1
Colm = 0
Reset_Cols = 1
Reset_Cols = 0
LED_Display: ' Scan cols & output row dat
@ incf _Column_Scan, 1 ' Inc col
@ incf _Digit_Pos, 1 ' Inc chr pos (0-4)
Row_Data = 0 ' Reset
IF Column_Scan = 37 THEN Column_Scan = 1 ' ^
select case Column_Scan
case 1 ' Secs (1's)
Digit_Pos = 0 ' Reset
Digit_Loc = (Secs_Digit1 * 5) ' Set loc
case 6 ' Space
Digit_Pos = 0
Digit_Loc = 50
case 7 ' Secs (10's)
Digit_Pos = 0
Digit_Loc = (Secs_Digit2 * 5)
case 12,13 ' Colm
Digit_Pos = 0
IF Colm = 2 then ' Blink colm
Digit_Loc = 55
else
Digit_Loc = 50
endif
case 14 ' Mins (1's)
Digit_Pos = 0
Digit_Loc = (Mins_Digit1 * 5)
case 19
Digit_Pos = 0 ' Space
Digit_Loc = 50
case 20 ' Mins (10's)
Digit_Pos = 0
Digit_Loc = (Mins_Digit2 * 5)
case 25,26 ' Colm
Digit_Pos = 0
IF Colm = 2 then
Digit_Loc = 55
else
Digit_Loc = 50
endif
case 27 ' Hours (1's)
Digit_Pos = 0
Digit_Loc = (Hrs_Digit1 * 5)
case 32 ' Space
Digit_Pos = 0
Digit_Loc = 50
case 33 ' Hours (10's)
Digit_Pos = 0
if Hrs_digit2 = 0 then ' Show either 1 or nothing
Digit_Loc = 50 ' (12hr time only)
else
Digit_Loc = 5
endif
end select
read Digit_loc + Digit_Pos, Row_Data ' Fetch portion of digit
' One column at a time
'// Switch off all rows before advancing the counters
ROW1 = 0
ROW2 = 0
ROW3 = 0
ROW4 = 0
ROW5 = 0
ROW6 = 0
ROW7 = 0
'// Prog button pressed?
if Prog_Button = 0 then GOTO Set_Time
'// Clock cascaded counters
Clock_Cols = 1
Clock_Cols = 0
'// Logically AND data with row bit values and write to port asynchronously
IF Row_Data & 1 THEN ROW1 = 1
IF Row_Data & 2 THEN ROW2 = 1
IF Row_Data & 4 THEN ROW3 = 1
IF Row_Data & 8 THEN ROW4 = 1
IF Row_Data & 16 THEN ROW5 = 1
IF Row_Data & 32 THEN ROW6 = 1
IF Row_Data & 64 THEN ROW7 = 1
GOTO LED_Display ' Loop back
disable ' Disable interrupts here
Clock: ' Time keeping routine
INTCON.2 = 0 ' Clear TMR0 overflow flag
Counter = Counter - $1000 ' Dec
IF Counter < $1000 THEN ' 0.5 sec elapsed?
if colm = 2 then ' 1 sec elapsed
@ incf _Secs_Digit1, 1 ' Inc secs first digit
If Secs_digit1 = 10 Then ' Secs first digit = 10?
@ incf _Secs_Digit2, 1 ' Inc 10's of secs
Secs_digit1 = 0 ' Reset first digit
If Secs_digit1 = 0 then ' Has one minute elapsed?
if Secs_digit2 = 6 Then
@ incf _Mins_Digit1, 1 ' Inc mins first digit
Secs_digit2 = 0 ' Reset secs second digit
if Mins_digit1 = 10 then ' 10 mins elapsed?
@ incf _Mins_Digit2, 1 ' Inc 10's of mins
Mins_digit1 = 0 ' Reset first mins digit
If mins_digit1 = 0 then ' 60 mins elapsed?
if mins_digit2 = 6 Then '
@ incf _Hrs_Digit1, 1 ' Inc hours first digit
mins_digit2 = 0 ' Reset mins second digit
if Hrs_digit1 = 10 then ' 10 hours elapsed?
Hrs_digit1 = 0 ' Set hours digits to show 10
Hrs_Digit2 = 1
EndIf
if Hrs_digit1 = 3 then ' 12 hours elapsed?
if hrs_digit2 = 1 then '
Hrs_digit1 = 1 ' Reset hours to 1
Hrs_digit2 = 0 '
endif
endif
endif
endif
endif
endif
endif
endif
Colm = 0 ' Colm off ...
endif '
Counter = Counter + $7A12 ' Reset counter with 0.5s
@ incf _Colm, 1 ' Toggle colm every 0.5s
endif
resume
Set_Time:
low Prog_Button ' Set LED
SERIN TX_To_PC, N2400, ["@"], Hrs_Digit2, Hrs_Digit1, Mins_Digit2, Mins_Digit1, Secs_Digit2, Secs_Digit1
input Prog_Button ' Resume as input for prog but
Reset_Cols = 1 ' Reset 4017 counters
Reset_Cols = 0 '
Column_Scan = 0 ' Reset to start of scan
goto LED_Display ' Start clock
Trent Jackson
Bookmarks