c un pic16F84 alimente sous 5v tres bien filtree et regule.
voici le code source realise par bruno gavand.
program
symbol LUNDI = 0
symbol MARDI = 1
symbol MERCREDI = 2
symbol JEUDI = 3
symbol VENDREDI = 4
symbol SAMEDI = 5
symbol DIMANCHE = 6
symbol LMMJV = 7
symbol NBALARM = 21
const alarmTable as byte[NBALARM * 4] = (
' JOUR HEURE MINUTE DUREE (secondes, 59 maxi)
LMMJV, 7, 45, 6,
LMMJV, 7, 55, 6,
LMMJV, 8, 55, 6,
LMMJV, 9, 55, 6,
LMMJV, 10, 05, 6,
LMMJV, 11, 00, 6,
LMMJV, 12, 00, 6,
LMMJV, 13, 45, 6,
LMMJV, 13, 55, 6,
LMMJV, 14, 55, 6,
LMMJV, 15, 55, 6,
LMMJV, 16, 05, 6,
LMMJV, 17, 00, 6,
LMMJV, 18, 00, 6,
SAMEDI, 7, 45, 6,
SAMEDI, 7, 55, 6,
SAMEDI, 8, 55, 6,
SAMEDI, 9, 55, 6,
SAMEDI, 10, 05, 6,
SAMEDI, 11, 00, 6,
SAMEDI, 12, 00, 6
)
dim maxcount as word
dim scaler as word
dim jj as byte
dim hh as byte
dim mn as byte
dim ss as byte
dim digiled as byte[4]
dim digit as byte
dim dp as byte
dim key as byte
dim alarm as byte
sub procedure interrupt
dim i as byte
scaler = scaler + 1
if scaler > maxcount
then
scaler = 0
inc(ss)
if ss = 60
then
ss = 0
inc(mn)
if mn = 60
then
mn = 0
inc(hh)
if hh = 24
then
hh = 0
inc(jj)
if jj = 7
then
jj =0
end if
end if
end if
end if
end if
#ifdef CATHODE_COMMUNE
PORTA = PORTA and $f0
TRISA = $0f
key = PORTA
TRISA = 0
PORTB = 0
#else
PORTA = PORTA or $0f
TRISA = $0f
key = PORTA
key = not(key)
TRISA = 0
PORTB = $ff
#endif
key = key and $07
digit = digit + 1
if digit > 3
then
digit = 0
i = $01
else
i = $01 << digit
end if
#ifdef CATHODE_COMMUNE
PORTB = digiled[digit]
PORTA = PORTA or i
#else
PORTB = digiled[digit]
PORTB = not(PORTB)
PORTA = PORTA and not(i)
#endif
INTCON.T0IF = 0
end sub
sub function intTo7seg(dim n as byte) as byte
select case n
case 0 result = $3F
case 1 result = $06
case 2 result = $5B
case 3 result = $4F
case 4 result = $66
case 5 result = $6D
case 6 result = $7D
case 7 result = $07
case 8 result = $7F
case 9 result = $6F
end select
end sub
sub procedure setValue(dim v as ^byte, dim s as byte, dim max as
byte)
digiled[0] = s
digiled[1] = 0
while 1
if key.0
then
inc(v^)
if(v^ > max)
then
v^ = 0
end if
end if
if key.1
then
if(v^ = 0)
then
v^ = max
else
dec(v^)
end if
end if
if key.2
then
Delay_ms(50)
while key.2
wend
Delay_ms(50)
scaler = 0
ss = 0
return
end if
digiled[2] = intTo7seg(v^ / 10)
digiled[3] = intTo7seg(v^ mod 10)
delay_ms(300)
wend
end sub
main:
dim i as byte
dp = 0
hh = 0
mn = 0
ss = 0
jj = 0
maxcount =15625
PORTA = %00010000
TRISA = %00000000
PORTB = 0
TRISB = $00
INTCON = %10100000
OPTION_REG = %11011000
Delay_ms(50)
setValue(@hh, 116, 23)
setValue(@mn, 55, 59)
setValue(@jj, 14, 6)
while true
if key
then
digiled[0] = intTo7seg(jj)
digiled[1] = 0
digiled[2] = intTo7seg(ss / 10)
digiled[3] = intTo7seg(ss mod 10)
else
if hh < 10
then
digiled[0] = 0
digiled[1] = intTo7seg(hh)
else
digiled[0] = intTo7seg(hh / 10)
digiled[1] = intTo7seg(hh mod 10)
end if
digiled[2] = intTo7seg(mn / 10)
digiled[3] = intTo7seg(mn mod 10)
end if
if scaler > maxcount / 2
then
dp.1 = 1
else
dp.1 = 0
end if
digiled[0].7 = dp.0
digiled[1].7 = dp.1
digiled[2].7 = dp.2
digiled[3].7 = dp.3
alarm = 0
for i = 0 to (NBALARM - 1) * 4 step 4
if ((alarmTable[i] = jj) or
((alarmTable[i] = LMMJV)and (jj< SAMEDI))) and (alarmTable[i + 1]
= hh) and (alarmTable[i + 2] = mn) and (alarmTable[i + 3] > ss)
then
inc(alarm)
end if
next i
if alarm
then
dp.3 = 1
PORTA.4 = 0
else
dp.3 = 0
PORTA.4 = 1
end if
wend
end.