121 lines
2.4 KiB
Plaintext
121 lines
2.4 KiB
Plaintext
' ########### start ###########
|
|
' pic:PIC16C84
|
|
' ########### end ###########
|
|
'
|
|
' ******************************************************************
|
|
' Binary Clock
|
|
' 2014-09-23 (c) Paolo Iocco
|
|
' ******************************************************************
|
|
'
|
|
' Circuit diagram
|
|
' ---------------
|
|
' +--\/--+
|
|
' Hour<-------|1° 18|-------->Min
|
|
' t_hour>-----|2 17|-------->Sec
|
|
' t_min >-----|3 16|<--------H
|
|
' +5V--+50K+-->|4 15|<--------H = 4 MHz chrystal+ capacitors
|
|
' GND-------->|5 14|<--------+5V
|
|
' Bit1<-------|6 13|-------->t_set
|
|
' Bit2<-------|7 12|-------->Bit7
|
|
' Bit3<-------|8 11|-------->Bit6
|
|
' Bit4<-------|9 10|-------->Bit5
|
|
' +------+
|
|
'
|
|
' ******************************************************************
|
|
|
|
#Chip 16C84, 4
|
|
#Config OSC = XT, WDT = OFF, PWRTE = ON, CP = OFF
|
|
|
|
#define l_sec PORTA.0
|
|
#define l_min PORTA.1
|
|
#define l_hour PORTA.2
|
|
#define t_set PORTB.7
|
|
#define t_hour PORTA.3
|
|
#define t_min PORTA.4
|
|
'#define Timer_Charge 130 '255-125 on a 4MHz Clock
|
|
#define Timer_Charge 124 '255-131 on a 4.19MHz Clock
|
|
|
|
dir PORTB out
|
|
dir l_sec out
|
|
dir l_min out
|
|
dir l_hour out
|
|
dir t_set in
|
|
dir t_hour in
|
|
dir t_min in
|
|
|
|
dim milliseconds as byte
|
|
dim Timer_1 as byte
|
|
dim Timer_10 as byte
|
|
dim _hour as byte
|
|
dim _min as byte
|
|
dim _sec as byte
|
|
|
|
Startup:
|
|
_hour=0
|
|
_min=0
|
|
_sec=0
|
|
milliseconds=0
|
|
Timer_10=100 '1s
|
|
Timer_1=10 '10ms
|
|
InitTimer0 Osc, PS0_8
|
|
TMR0=Timer_Charge
|
|
|
|
Interrupts:
|
|
On Interrupt Timer0Overflow Call Tmr0_ISR
|
|
|
|
Loop:
|
|
do
|
|
if Timer_1=0 then
|
|
Timer_1=10
|
|
'controllo del tasto premuto
|
|
end if
|
|
if Timer_10=0 then
|
|
Timer_10=100 '1s period
|
|
Inc_Clock 'icrements evrey 1s
|
|
end if
|
|
Led_Display
|
|
loop
|
|
|
|
Sub Tmr0_ISR
|
|
'on Timer0 Overflow (IRQ on transition 255 to 0)
|
|
TMR0=Timer_Charge 'reset counter --> Timer_Charge
|
|
if Timer_1>0 then Timer_1 --
|
|
milliseconds ++
|
|
if milliseconds=10 then
|
|
if Timer_10>0 then Timer_10 --
|
|
milliseconds=0
|
|
end if
|
|
End Sub
|
|
|
|
Sub Inc_Clock
|
|
'sub to increment _sec, _min and _hour
|
|
_sec ++
|
|
if _sec >59 then
|
|
_sec=0
|
|
_min ++
|
|
if _min >59 then
|
|
_min=0
|
|
_hour ++
|
|
if _hour >23 then
|
|
_hour=0
|
|
end if
|
|
end if
|
|
end if
|
|
End Sub
|
|
|
|
Sub Led_Display
|
|
'Sub per visualizzare le tre variabili
|
|
set l_sec on
|
|
set l_min off
|
|
set l_hour off
|
|
PORTB = _sec
|
|
set l_sec off
|
|
set l_min on
|
|
set l_hour off
|
|
'PORTB = _min
|
|
set l_sec off
|
|
set l_min off
|
|
set l_hour on
|
|
'PORTB = _hour
|
|
End Sub
|