5 ' --- Disjoncteur Statique Programmable --- 10 const device = 3B 15 lcdinit 20 cls : csroff 25 ' --- Affichage du message d'accueil --- 30 locate 0,0 : print "* Disjoncteur *" : locate 0,1 : print "(c) ELEKTOR 2008" : sound 7,159,2 : delay 5000 : cls 40 ' --- Déclaration des variables utilisées --- 45 dim N as integer : dim RI as integer : dim NR as integer : dim CHF as integer : dim NI as integer : dim VALEUR as integer 46 dim INC as integer : dim DEC as integer : dim VALEURMAX as integer : dim VALEURMIN as integer 47 dim U as integer : dim UMAX as integer : dim I as integer : dim ID as integer 48 dim F as integer 50 dim S1 as byte : dim S2 as byte 55 dim X0 as byte : dim X1 as byte : dim X2 as byte : dim X3 as byte : dim X4 as byte : dim X5 as byte : dim X6 as byte : dim X7 as byte 60 dim X10 as byte : dim X11 as byte : dim X12 as byte : dim X13 as byte : dim X14 as byte : dim X15 as byte 65 dim PT1I as integer : dim PT2I as integer : dim PT3I as integer : dim PT4I as integer : dim PT5I as integer 66 dim PT1T as integer : dim PT2T as integer : dim PT3T as integer : dim PT4T as integer : dim PT5T as integer 67 dim T1 as byte : dim T2 as byte : dim T3 as byte : dim T4 as byte : dim T5 as byte : dim TP as integer 70 ' --- Initialisation du grafcet principal --- 71 X0 = 1 : X1 = 0 : X2 = 0 : X3 = 0 : X4 = 0 : X5 = 0 : X6 = 0 : X7 = 0 80 ' --- Initialisation du grafcet de saisie --- 81 X10 = 1 : X11 = 0 : X12 = 0 : X13 = 0 : X14 = 0 : X15 = 0 100 ' --- Paramétrage du disjoncteur --- 105 cls : locate 0,0 : print "Parametrage du " : locate 0,1 : print "disjoncteur... " : sound 7,159,2 : delay 3000 110 ' --- Saisie des seuils de courant et de temps --- 115 cls : locate 0,0 : print "Courant PT1 ? : " : VALEUR = 10 : gosub 2000 : sound 7,159,2 120 VALEURMIN = 10 : VALEURMAX = 160 : INC = 2 : DEC = 2 125 gosub 1000 130 PT1I = VALEUR 135 cls : locate 0,0 : print "Temps PT1 ? : " : VALEUR = 10000 : gosub 4000 : sound 7,159,2 140 VALEURMIN = 10000 : VALEURMAX = 30000 : INC = 1000 : DEC = 1000 145 gosub 1500 150 PT1T = VALEUR 155 cls : locate 0,0 : print "Courant PT2 ? : " : VALEUR = 10 : gosub 2000 : sound 7,159,2 160 VALEURMIN = 10 : VALEURMAX = 160 : INC = 2 : DEC = 2 165 gosub 1000 170 PT2I = VALEUR 175 cls : locate 0,0 : print "Temps PT2 ? : " : VALEUR = 5000 : gosub 4000 : sound 7,159,2 180 VALEURMIN = 5000 : VALEURMAX = 10000 : INC = 500 : DEC = 500 185 gosub 1500 190 PT2T = VALEUR 195 cls : locate 0,0 : print "Courant PT3 ? : " : VALEUR = 10 : gosub 2000 : sound 7,159,2 200 VALEURMIN = 10 : VALEURMAX = 160 : INC = 2 : DEC = 2 205 gosub 1000 210 PT3I = VALEUR 215 cls : locate 0,0 : print "Temps PT3 ? : " : VALEUR = 2000 : gosub 4000 : sound 7,159,2 220 VALEURMIN = 2000 : VALEURMAX = 5000 : INC = 100 : DEC = 100 225 gosub 1500 230 PT3T = VALEUR 235 cls : locate 0,0 : print "Courant PT4 ? : " : VALEUR = 10 : gosub 2000 : sound 7,159,2 240 VALEURMIN = 10 : VALEURMAX = 160 : INC = 2 : DEC = 2 245 gosub 1000 250 PT4I = VALEUR 255 cls : locate 0,0 : print "Temps PT4 ? : " : VALEUR = 1000 : gosub 4000 : sound 7,159,2 260 VALEURMIN = 1000 : VALEURMAX = 2000 : INC = 50 : DEC = 50 265 gosub 1500 270 PT4T = VALEUR 280 cls : locate 0,0 : print "Courant PT5 ? : " : VALEUR = 10 : gosub 2000 : sound 7,159,2 285 VALEURMIN = 10 : VALEURMAX = 160 : INC = 2 : DEC = 2 290 gosub 1000 295 PT5I = VALEUR 300 cls : locate 0,0 : print "Temps PT5 ? : " : VALEUR = 100 : gosub 4000 : sound 7,159,2 305 VALEURMIN = 100 : VALEURMAX = 1000 : INC = 50 : DEC = 50 310 gosub 1500 315 PT5T = VALEUR 400 ' --- Vérification du paramétrage --- 410 cls : locate 0,0 : print "Verification du " : locate 0,1 : print "parametrage... " : sound 7,159,2 : delay 3000 420 if PT1I < PT2I and PT2I < PT3I and PT3I < PT4I and PT4I < PT5I then goto 440 430 goto 450 440 if PT1T > PT2T and PT2T > PT3T and PT3T > PT4T and PT4T > PT5T then goto 460 450 cls : locate 0,0 : print " Parametrage " : locate 0,1 : print " INCORRECT !! " : sound 7,255,64 : delay 2000 : goto 100 460 cls : locate 0,0 : print " Parametrage " : locate 0,1 : print " CORRECT !! " : sound 7,159,8 : delay 2000 470 PT1T = PT1T / 100 475 PT2T = PT2T / 100 480 PT3T = PT3T / 100 490 PT4T = PT4T / 100 495 PT5T = PT5T / 100 500 ' --- Gestion du fonctionnement du disjoncteur --- 505 T1 = 0 : T2 = 0 : T3 = 0 : T4 = 0 : T5 = 0 : TP = 0 510 S1 = keyin(1,5) : S2 = keyin(12,5) 511 if S1 = 0 or S2 = 0 then sound 7,159,4 515 gosub 5000 520 if X0 = 1 and S1 = 0 then X1 = 1 : X0 = 0 525 if X1 = 1 and I >= PT1I and I < PT2I then X2 = 1 : X1 = 0 530 if X1 = 1 and I >= PT2I and I < PT3I then X4 = 1 : X1 = 0 535 if X1 = 1 and I >= PT3I and I < PT4I then X5 = 1 : X1 = 0 540 if X1 = 1 and I >= PT4I and I < PT5I then X6 = 1 : X1 = 0 545 if X1 = 1 and I >= PT5I then X7 = 1 : X1 = 0 550 if X2 = 1 and I < PT1I then X1 = 1 : X2 = 0 555 if X4 = 1 and I < PT2I and I >= PT1I then X2 = 1 : X4 = 0 560 if X5 = 1 and I < PT3I and I >= PT2I then X4 = 1 : X5 = 0 565 if X6 = 1 and I < PT4I and I >= PT3I then X5 = 1 : X6 = 0 566 if X7 = 1 and I < PT5I and I >= PT4I then X6 = 1 : X7 = 0 570 if X1 = 1 and S2 = 0 then X0 = 1 : X1 = 0 575 if X2 = 1 and T1 = 1 then X3 = 1 : X2 = 0 580 if X4 = 1 and T2 = 1 then X3 = 1 : X4 = 0 585 if X5 = 1 and T3 = 1 then X3 = 1 : X5 = 0 590 if X6 = 1 and T4 = 1 then X3 = 1 : X6 = 0 595 if X7 = 1 and T5 = 1 then X3 = 1 : X7 = 0 600 if X3 = 1 and S1 = 0 then X1 = 1 : X3 = 0 605 if X2 = 1 and I >= PT2I and I < PT3I then X4 = 1 : X2 = 0 610 if X4 = 1 and I >= PT3I and I < PT4I then X5 = 1 : X4 = 0 615 if X5 = 1 and I >= PT4I and I < PT5I then X6 = 1 : X5 = 0 620 if X6 = 1 and I >= PT5I then X7 = 1 : X6 = 0 621 if X0 = 1 or X3 = 1 then out 13,0 else out 13,1 623 if X3 = 1 then out 14,1 else out 14,0 625 if X0 = 1 then locate 0,0 : print "Disjoncteur :OFF" : locate 0,1 : print "Impulsion sur S1" 630 if X1 = 1 then locate 0,0 : print "Disjoncteur : ON" : gosub 2000 631 if X1 = 1 then T1 = 0 : T2 = 0 : T3 = 0 : T4 = 0 : T5 = 0 : TP = 0 635 if X2 = 1 then locate 0,0 : print " SURCHARGE !!! " : gosub 2000 640 if X2 = 1 then gosub 6000 645 if TP >= PT1T then T1 = 1 650 if X4 = 1 then locate 0,0 : print " SURCHARGE !!! " : gosub 2000 655 if X4 = 1 then gosub 6000 660 if TP >= PT2T then T2 = 1 665 if X5 = 1 then locate 0,0 : print " SURCHARGE !!! " : gosub 2000 670 if X5 = 1 then gosub 6000 675 if TP >= PT3T then T3 = 1 680 if X6 = 1 then locate 0,0 : print " SURCHARGE !!! " : gosub 2000 685 if X6 = 1 then gosub 6000 690 if TP >= PT4T then T4 = 1 695 if X7 = 1 then locate 0,0 : print " SURCHARGE !!! " : gosub 2000 700 if X7 = 1 then gosub 6000 705 if TP >= PT5T then T5 = 1 710 if X3 = 1 then locate 0,0 : print "Disjoncteur :OFF" : gosub 2500 715 goto 510 1000 ' --- Grafcet de saisie du paramètre COURANT --- 1005 gosub 3000 1010 if X10 = 1 and S1 = 0 then X11 = 1 : X10 = 0 1015 if X11 = 1 and S1 = 1 then X12 = 1 : X11 = 0 1020 if X12 = 1 and S1 = 0 then X13 = 1 : X12 = 0 1025 if X13 = 1 and S1 = 1 then X14 = 1 : X13 = 0 1030 if X14 = 1 and S1 = 0 then X11 = 1 : X14 = 0 1035 if X14 = 1 and S2 = 0 then X15 = 1 : X14 = 0 1040 if X15 = 1 and S2 = 1 then X10 = 1 : X15 = 0 1045 if X12 = 1 and S2 = 0 then X15 = 1 : X12 = 0 1050 if X10 = 1 and S2 = 0 then X15 = 1 : X10 = 0 1055 if X11 = 1 and VALEUR < VALEURMAX then VALEUR = VALEUR + INC 1060 if X13 = 1 and VALEUR > VALEURMIN then VALEUR = VALEUR - INC 1065 if X15 = 1 then sound 7,159,16 : return 1070 gosub 2000 : goto 1005 1500 ' --- Grafcet de saisie du paramètre TEMPS --- 1505 gosub 3000 1510 if X10 = 1 and S1 = 0 then X11 = 1 : X10 = 0 1515 if X11 = 1 and S1 = 1 then X12 = 1 : X11 = 0 1520 if X12 = 1 and S1 = 0 then X13 = 1 : X12 = 0 1525 if X13 = 1 and S1 = 1 then X14 = 1 : X13 = 0 1530 if X14 = 1 and S1 = 0 then X11 = 1 : X14 = 0 1535 if X14 = 1 and S2 = 0 then X15 = 1 : X14 = 0 1540 if X15 = 1 and S2 = 1 then X10 = 1 : X15 = 0 1545 if X12 = 1 and S2 = 0 then X15 = 1 : X12 = 0 1550 if X10 = 1 and S2 = 0 then X15 = 1 : X10 = 0 1555 if X11 = 1 and VALEUR < VALEURMAX then VALEUR = VALEUR + INC 1560 if X13 = 1 and VALEUR > VALEURMIN then VALEUR = VALEUR - INC 1565 if X15 = 1 then sound 7,159,16 : return 1570 gosub 4000 : goto 1505 2000 ' --- SP : Affichage du courant (valeur décimale) --- 2001 NI = VALEUR 2005 N = NI 2010 RI = N / 10 2025 NR = 10 * RI 2030 CHF = N - NR 2035 if CHF = 0 then locate 10,1 : print "0" 2040 if CHF = 1 then locate 10,1 : print "1" 2045 if CHF = 2 then locate 10,1 : print "2" 2050 if CHF = 3 then locate 10,1 : print "3" 2055 if CHF = 4 then locate 10,1 : print "4" 2060 if CHF = 5 then locate 10,1 : print "5" 2065 if CHF = 6 then locate 10,1 : print "6" 2070 if CHF = 7 then locate 10,1 : print "7" 2075 if CHF = 8 then locate 10,1 : print "8" 2080 if CHF = 9 then locate 10,1 : print "9" 2085 locate 9,1 : print "," 2190 CHF = NR / 10 2195 locate 4,1 : print dec (CHF) 2100 locate 0,1 : print " I =" 2105 locate 11,1 : print " A " 2110 return 2500 ' --- SP : Affichage du courant de défaut (valeur décimale) --- 2501 NI = ID 2505 N = NI 2510 RI = N / 10 2525 NR = 10 * RI 2530 CHF = N - NR 2535 if CHF = 0 then locate 10,1 : print "0" 2540 if CHF = 1 then locate 10,1 : print "1" 2545 if CHF = 2 then locate 10,1 : print "2" 2550 if CHF = 3 then locate 10,1 : print "3" 2555 if CHF = 4 then locate 10,1 : print "4" 2560 if CHF = 5 then locate 10,1 : print "5" 2565 if CHF = 6 then locate 10,1 : print "6" 2570 if CHF = 7 then locate 10,1 : print "7" 2575 if CHF = 8 then locate 10,1 : print "8" 2580 if CHF = 9 then locate 10,1 : print "9" 2585 locate 9,1 : print "," 2590 CHF = NR / 10 2595 locate 4,1 : print dec (CHF) 2600 locate 0,1 : print " Id =" 2605 locate 11,1 : print " A " 2610 return 3000 ' --- SP : Action sur les boutons poussoirs --- 3005 S1 = keyin(1,5) : S2 = keyin (12,5) 3010 if S1 = 1 and S2 = 1 then return 3015 if S1 = 0 then sound 7,255,2 3020 return 4000 ' --- Affichage du temps --- 4005 locate 2,1 : print "T = ": locate 6,1 : print dec(VALEUR) : locate 11,1 : print " ms " 4010 return 5000 ' --- Mesure du courant --- 5005 UMAX = 511 5010 for F = 1 to 50 5020 U = ADIN(0) 5030 if U > UMAX then UMAX = U 5040 next F 5050 I = ((UMAX-511)*43) / 50 5055 VALEUR = I 5060 IF X1 = 1 or X2 = 1 or X4 = 1 or X5 = 1 or X6 = 1 or X7 = 1 then ID = I 5065 return 6000 ' --- Temporisation --- 6010 TP = TP + 1 6030 return