'********************************************
'* PORTAIL FAAC *
'* PILOTE PAR MICROCONTROLEUR 68HC11 *
'* Programme réalisé par : *
'* BERTRAND HOAREAU *
'* Professeur Certifié Génie Electrique *
'* OCTOBRE 1998 *
'* Contact Email: creole@guetali.fr *
'********************************************
#include "start.bas"
int i, s, seca, seconde, t_up_down
int tp(4), tp_ok(4), tmax(4), nb_tempos, tp_courant,
tp_courant_max
byte telecommande,barriere,code_secret,X(4),
last_telecommande,commande
byte demande_ouverture, fin_ouverture, fin_fermeture, fin_tempo1,
fin_tempo2
byte presence_obstacle
byte ouvrir_portail, fermer_portail, attente , nb,clignote,VI
byte flag1,flag2,flag3, flag4
byte code, tab(5),bon_code(5),code_index,code_ok
byte tp_ok_courant, comp
comp = 0 ' variable intervenant sur temps de fermeture
code_index = 0
bon_code(1)= `1`
bon_code(2)= `1`
bon_code(3)= `2`
bon_code(4)= `2`
DDRD = 0 ' PD5=PD4=PD3=PD2=input
SCONF = 0x4C ' B,C = sorties
lcdinit()
PORTB = 0 ' Arret moteur et clignotant
print "Portail Hoareau" 'Affichage LCD Controlboy 3
tempo (500)
' print " "
' tempo (150)
PACTL.1 = 0 ' selectionner la vitesse
PACTL.0 = 0
TMSK2.6 = 1 ' declencher le timer
cli ' autoriser les inter
'initialisations diverses
flag1 =0
flag2 =0
flag3 =0
flag4 =0
t_up_down = 0 ' incrémente(1) ou décrémente (-1) tempo
courante
tp_ok_courant = 0 ' validation temporisation
tp_courant = 0 ' Tempo courante
' Initialisation grafcet et tempos
X(0) = 1
X(1) = 0
X(2) = 0
X(3) = 0
tmax(0) = 0
tmax(1) = 2500
tmax(2) = 500 ' laps de temps min entre 2 commandes
tmax(3) = 2500 ' non utilisé
tp_courant_max = 3000 ' valeur max tempo courante
nb_tempos = 3 ' (+1)
code_secret = 0
last_telecommande = 0
do
' lecture des entrées
LDAA PORTD
ANDA #32 ' MASQUAGE
EORA #32 ' inversion du bit car
STAA commande ' Interrupteur carte actif niveau 0
LDAA PORTA
ANDA #2 ' bit1 = 1 si non actif
EORA #2 ' Inversion bit
STAA barriere
' mise à jour des réceptivités
' détection front montant sur télécommande
if last_telecommande = 0 and commande > 0 then
telecommande = 1
else
telecommande = 0
end if
demande_ouverture = telecommande or barriere or code_secret
last_telecommande = commande
' fin_ouverture = testtempo(1)
' fin_fermeture = testtempo(3)
if tp_courant >= tp_courant_max then
fin_ouverture = 1
fin_fermeture = 0
else
if tp_courant <=1 then
fin_ouverture = 0
fin_fermeture = 1
else
fin_ouverture = 0
fin_fermeture = 0
end if
end if
fin_tempo1 = testtempo(1)
fin_tempo2 = testtempo(2)
presence_obstacle = barriere
' mise à jour des étapes
if X(0)=1 AND demande_ouverture > 0 then
X(1)=1
X(0)=0
end if
if X(1) = 1 then
t_up_down = 1 ' pour incrémenter compteur
end if
if X(1)=1 AND (fin_ouverture = 1 or (telecommande > 0 and
fin_tempo2=1)) then
X(2)=1
X(1)=0
fin_tempo2 = 0
tp_ok(2) = 0
tp(2) = 0
end if
if X(2)=1 AND presence_obstacle=0 AND ((telecommande > 0 and
fin_tempo2=1) or (fin_tempo1=1 and code_secret=1)) then
X(3)=1
X(2)=0
fin_tempo2 = 0
tp_ok(2) = 0
tp(2) = 0
end if
if X(3) = 1 then
t_up_down = -1 ' pour décrémenter compteur
end if
if X(3)=1 AND fin_fermeture = 1 then
X(0)=1
X(3)=0
PORTB = 1 ' couper alim (RE3 = 0) et SENS FERMETURE : RE1 = 1
tempo(500)
PORTB = 0 ' désactive RE1 (SENS OUVERTURE PAR DEFAUT RE1 = 0)
end if
if X(3)=1 AND presence_obstacle = 1 or (telecommande > 0 and
fin_tempo2=1) then
X(1)=1
X(3)=0
fin_tempo2 = 0
tp_ok(2) = 0
tp(2) = 0
tp_ok_courant = 0 ' bloque tempo courante afin que délais relais
' ne fausse pas le temps de fermeture
PORTB = 1 ' je dois arreter relais alim RE3=0
tempo(500) ' delais relais
PORTB = 0 ' puis passer en sens ouverture RE1 =0
tempo (500) ' delais relais
tp_ok_courant = 1 ' réactive tempo courante
end if
' EQUATION DES SORTIES et tempo
ouvrir_portail = X(1)
fermer_portail = X(3)
attente = X(2)
' clignote = X(1) or X(3)
clignote = 0
tp_ok(1) = X(2) ' tempo d'attente mode automatique
tp_ok(2) = X(1) or X(2) or X(3)
tp_ok_courant = X(1) or X(3)
' Note HOAREAU B : les tempos ne doivent pas être bloquantes !
' affectation des sorties
' -------- OUVERTURE PORTAIL ----------
if ouvrir_portail <> 0 and flag1=0 then
print " ouvrir portail "
flag1 = 1
flag3 = 0
flag4 = 0
PORTB = 2 'SENS OUVERTURE RE1=0 + ALIM RE3=1
end if
' ----- FERMETURE DU PORTAIL ------
if fermer_portail <> 0 and flag2=0 then
print " fermer portail "
flag2 = 1
flag1 = 0
tp_ok_courant = 0 ' bloque tempo courante afin que délais relais
' ne fausse pas le temps de fermeture
PORTB = 1 ' SENS FERMETURE RE1 = 1
tempo (500) ' delais relais
tp_ok_courant = 1 ' autorise tempo courante
PORTB = 3 ' SENS FERMETURE RE1 = 1 + ALIM RE3=1
end if
if attente <> 0 and flag3=0 then
print " attente "
flag3 = 1
flag2 = 0
PORTB = 0 ' désactive relais RE1 (SENS fermeture par défaut)
end if
if X(0) = 1 then
code_secret = lirecode() 'Code via clavier du FAAC
end if
if X(0) = 1 and flag4=0 then
flag4 = 1
print " Entrer code ! "
end if
' clignotant
if clignote <> 0 then
if seconde<> s then
if PORTB.2 = 1 then
PORTB.2 = 0
else
PORTB.2 = 1
end if
end if
s = seconde
end if
loop
function testtempo(n)
if tp(n) >= tmax(n) then
return 1
else
return 0
end if
end function
function lirecode()
int retour
retour = 0
code = keyget()
if code <> 0 then
putchar(code)
code_index = code_index + 1
tab(code_index)=code
if code_index = 4 then
code_index = 0
code_ok = 1 ' VRAI
for i=1 to 4
if tab(i) <> bon_code(i) then
code_ok = 0 ' FAUX
end if
next i
if code_ok = 1 then
retour = 1 ' variable retournée
else
print " CODE ERRONE ! "
tempo(2000)
print " Entrer Code "
end if
code_ok=0
end if
end if
return retour
end function
function tempo(cnt)
int t
for cnt=cnt to 0 step -1
for t=0 to 200
next
next
end function
' Fonction d'interruption pour Tempo non bloquante
interrupt function temporiser3 at $FFF0
if clignote > 0 then
seca = seca +1
if seca > 200 then '244 pour avoir seconde
seconde = seconde + 1 ' donc un peu moins d'une seconde ...
seca = 0
end if
else
seca = 0
seconde = 0
s = 0
end if
if tp_ok_courant = 1 then
if t_up_down = -1 then ' Il faut ralonger de 20% le temps de
fermeture
comp = comp + 1
end if
if comp > 4 then
comp = 0 ' exécuté 1 fois sur 5 lors de la fermeture (=20 %)
else
tp_courant = tp_courant + t_up_down
if tp_courant > tp_courant_max then
tp_courant = tp_courant_max
end if
if tp_courant < 1 then
tp_courant = 1
end if
end if
end if
for nb = 0 to nb_tempos
if tp_ok(nb) = 1 then
if tp(nb)>20000 then ' Limit max si erreur programme
tp(nb) = 20000
end if
tp(nb) = tp(nb) + 1
else
tp(nb) = 0
end if
next
TFLG2.6 = 1 ' autoriser l'interruption à nouveau
end function
#include "lcd.bas"
' Il faut toujours couper RE3 (alim ) avant d'agir sur
' le relais RE1 (sens ouverture/fermeture)