; décompteur 1/10s MM 300626
; réglage par poussoirs +/-
;pour temps=9990 10ème s => tmax=16 mn 39s;
;les poussoirs sont sur le 0V,
;Broches avec pullup sur 20X2 : bit0-bit7 = C.0,C.6,C.7,B.0,B.1,B.5,B.6,B.7
;****** MODE D'EMPLOI **********
;A la mise sous tension, mémoire vide, passage auto en mode programmartion temps
;Mode Programmation du temps:
;L'affichage est en /10 de seconde, avec un point décimal sur le digit 3
;Pour identifier ce mode,il y a en plus un point sur le digit 4
;Appui sur plus:
; appui court < 500ms => incrémentation de 0,5s
; appui long > 500ms => défilemenrt rapide
;Appui sur moins:
; Idem en décrémentation
;Appui sur MEM => clignotement vert + rouge => mise en mémoire EEPROM
;Passage en mode décomptage
;
;Mode décomptage.
;Le point sur le digit 4 disparait,reste le point décimal digit3
;Attente appui sur poussoir start => décompte du temps led rouge allumée.
;A 5 s => led orange allumée
;A 00,0 s => R et O éteintes, verte allumée 10 s => retour valeur enregistrée.
;Arrêt possible par appui sur MEM à tout moment du décompte
;MEM => arret décompte => retour attente start avec temps mémorisé
;deuxième appui sur MEM =>passge en mode programmation
#picaxe 20X2
setfreq M16
symbol dio=pinC.1 ;sur TM1637
symbol clk=pinC.2 ;idem
symbol mem=pinC.0 ;poussoir MEM
symbol plus=pinC.6 ;poussoir plus
symbol moins=pinC.7
symbol start=pinB.7
symbol orange=B.0 ;led
symbol rouge=B.1
symbol verte=B.2
symbol octet=b0 ;octet doit être en b0; le bit0 est utilisé
symbol j=b1 ;position point décimal
symbol i=b2 ;compteur
symbol chiffre=b3
symbol dp=b4
symbol point=b5
symbol second=w12 ;en fait des /10 de secondes
symbol div=w13
symbol nbre=w14
symbol Ttot=w15
symbol AdrDep=$c0 ; adresse du 1er digit (poids fort)
symbol RegLum=$8c ; réglage luminosité $80 + 8(allumé, 0:éteint) + 0 à 7(intensité)
dp=$80
;pullup sur 20X2 bit0-bit7 = C.0,C.6,C.7,B.0,B.1,B.5,B.6,B.7
pullup %10000111 ;sur C.0,C.6,C.7,B.7
dirsC=%110 ;pour utilisation pinsC
settimer 59285 ;1/10 s à 16MHs 59285
; ***** init TM1637 et temps EEPROM
clk=1 : dio=1 : dio=0 ;bal start
Octet=RegLum ;Réglage luminosité
gosub EnvoiOctet
clk=0: dio=0: clk=1: dio=1 ;bal stop
low rouge,verte,orange
read 0,Ttot ;lecture temps en EEPROM
if Ttot=0 then ;la mémoire est vide
gosub introtemp ;entrer une valeur en mémoire EEPROM
endif
second=Ttot ;initialisation compteur seconde
gosub affich ;affichage temps initial
;********decompte *******
decompt:
pause 200
do loop while mem=0 ;attente relachement suite arret decompte
low rouge
do
second=Ttot
gosub affich
do ;****** boucle attente départ ou intro temps ******
if mem=0 then gosub introtemp ;passage en programmation temps
loop while start=1 ;attente start
timer=0
high rouge
do ;boucle décomptage
second=Ttot -timer
if second < 50 then ;5 secondes avant la fin
high orange
endif
if mem=0 then decompt ;arret décompte et RAZ
gosub affich
loop while second<>0
high verte:low orange,rouge ;fin décompte
timer=0
do loop while timer <= 100 ;attente 10s led verte ON
low rouge,verte,orange
loop
introtemp: ;sub intro nouveau temps
;********** intro secondes *******
pause 200
do loop while mem=0
pause 200
point=1 ;ajout point décimal sur digit n°4
do
gosub affich
timer=0
;***** code plus *****
if plus=0 then
second =second+5 max 9995
do while plus=0
if timer >5 then ;500ms défilement accéléré
second =second+5 max 9995
gosub affich
endif
loop
gosub affich
endif
; code moins
if moins=0 then
second =second-5 min 0
do while moins=0
if timer >5 then
second =second-5
if second>9999 then: second=0 :endif ;dépassement négatif
gosub affich
endif
loop
gosub affich
endif
if mem=0 then exit ;fin de boucle intro secondes
loop
do loop while mem=0 ;attente relâchement poussoir
Ttot=second
write 0,Ttot ;mise en EEPROM
high orange, rouge :pause 500:low orange, rouge:pause 500
high orange, rouge :pause 500:low orange, rouge
point=0 ;sortie mode introtemps
gosub affich
return
affich:
div=1000
clk=1 : dio=1 : dio=0 ;balise start
Octet=adrdep ;synchro adresse départ
gosub EnvoiOctet
Nbre=second ;on tronçonne Nbre et affiche chaque chiffre
for j=1 to 4
Chiffre=Nbre/Div ;on isole le chiffre à afficher
if j=1 and second<1000 and second<>0 then
chiffre=10 ;chiffre "blanc" càd noir, en fait
endif
if j=2 and second<100 and second<>0 then
chiffre=10
endif
gosub DecTo7seg
if j=3 then ;choix affichage point
octet=octet | dp ;ajout point décimal
endif
if point=1 and j=4 then ;mode programmation temps
octet=octet | dp ;ajout point digit 4
endif
gosub EnvoiOctet;
Nbre=Nbre//Div ;isolement chiffre suivant
Div=Div/10 ;diviseur suivant
next j
clk=0: dio=0: clk=1: dio=1 ;balise stop
return
;******* Envoi des chiffres (octet) bit à bit dans le registre ********
EnvoiOctet: ;lecture de b0 bit à bit de bit0 à bit8 poids faible en tête.
for i=1 to 8 ; envoi
clk=0
dio=bit0
Octet = Octet/2 ;octet=b0 => décalage à droite, bit1 devient bit0
clk=1
next i
clk=0 :clk=1: clk=0 ; balise ACK
return
;****** Conversion des chiffres en segments
DecTo7seg:
lookup Chiffre,($3f,$06,$5b,$4f,$66,$6d,$7d,$07,$7f,$6f,0), Octet ; 0-9 +blanc uniquement
return