5 ' --- CO-mètre numérique --- 10 const device = 3B 11 out 8,0 : out 9,0 : out 1,0 : out 2,0 : out 4,0 : out 5,0 : out 6,0 : out 7,0 : out 16,0 : out 17,0 15 lcdinit 16 cls : csroff 17 locate 0,0 : print "*** CO-metre *** 18 locate 0,1 : print "(c) ELEKTOR 2008" : sound 11,159,2 20 ' Déclaration des variables 21 dim N as byte, V as byte, Vc as integer, Vce as integer, Vout as integer ,V1 as byte, V2 as byte, Rs as integer, R0 as byte 22 dim RsR0 as integer, RL as byte, tmin as integer, tmax as integer 50 ' Paramètrage du capteur TGS 2442 51 R0 = 0 : delay 2000 52 sound 11,159,2 53 cls : locate 0,0 : print "Parametrage" : locate 0,1 : print "Capteur TGS 2442" 54 delay 3000 60' Debut du paramétrage 61 if R0 = 0 then goto 62 else goto 100 62 sound 11,159,2 : cls : locate 0,0 : print "Capteur type 1 ?" : locate 0,1 : print "Validation : " 63 For N = 1 to 100 64 V = keyin (3,25): if V = 0 then R0 = 14 : sound 11,159,16 65 next N 66 if R0 = 14 then goto 1000 else goto 70 70 sound 11,159,2 71 cls : locate 0,0 : print "Capteur type 2 ?" : locate 0,1 : print "Validation : " 72 For N = 1 to 100 73 V = keyin (3,25): if V = 0 then R0 = 21 : sound 11,159,16 74 next N 76 if R0 = 21 then goto 1000 else goto 80 80 sound 11,159,2 81 cls : locate 0,0 : print "Capteur type 3 ?" : locate 0,1 : print "Validation : " 82 For N = 1 to 100 83 V = keyin (3,25): if V = 0 then R0 = 31 : sound 11,159,16 84 next N 86 if R0 = 31 then goto 1000 else goto 90 90 sound 11,159,2 91 cls : locate 0,0 : print "Capteur type 4 ?" : locate 0,1 : print "Validation : " 92 For N = 1 to 100 93 V = keyin (3,25) : if V = 0 then R0 = 45 : sound 11,159,16 94 next N 96 if R0 = 45 then goto 1000 else goto 60 100 ' Mesure de Vout 102 cls 105 OUT 13,1 : delay 100 : OUT 13,0 110 Vc = 1023 : RL = 33 : Vce = 123 : ' Vc = 5 V et Vce du transistor = 0,6 V 115 out 9,1 : delay 2 120 Vout = ADIN(0) 121 delay 2 : out 9,0 122 out 8,1 : delay 13 : out 8,0 130 ' Calcul de 1500 Rs/R0 135 V1 = 15*(Vc - Vce) 136 V2 = Vout - Vce 140 Rs = ((V1/V2)-15)*RL 150 RsR0 = 100 * (Rs/R0) 160 'Gestion de l'affichage du taux de CO 165 GOSUB 2000 166 delay 820 180 ' Traitement des alarmes 190 if tmin > 34 then out 14,1 195 if tmin < 35 then out 14,0 200 if tmin > 49 then goto 220 210 goto 105 220 ' Gestion de l'alarme sonore 230 out 15,1 : out 12,1 : out 14,0 240 cls : locate 0,0 : print "%CO min:";dec(tmin);"ppm" : locate 0,1 : print "Acquittement " 250 sound 11, 159, 16, 233,16 260 V = keyin (3,25) : if V = 0 then goto 280 270 goto 250 280 out 14, 0 : out 15,0 : out 12,0 : sound 11,159,2 : delay 100 290 cls : locate 0,0 : print "Acquittement OK!" 300 delay 5000 310 cls : locate 0,0 : print "Initialisation ?": locate 0,1 : print " Actionner " 320 sound 11,159,2 330 V = keyin (3,25) 340 if V = 0 then goto 360 350 goto 330 360 goto 5 1000 ' Affichage paramétrage effectif 1010 cls : sound 11,159,2 1020 if R0 = 14 then locate 0,0 : print "TGS 2442 type 1" 1021 if R0 = 14 then locate 0,1 : print "Ro = 14 K-ohms" 1030 if R0 = 21 then locate 0,0 : print "TGS 2442 type 2" 1031 if R0 = 21 then locate 0,1 : print "Ro = 21 K-ohms" 1040 if R0 = 31 then locate 0,0 : print "TGS 2442 type 3" 1041 if R0 = 31 then locate 0,1 : print "Ro = 31 K-ohms" 1050 if R0 = 45 then locate 0,0 : print "TGS 2442 type 4" 1051 if R0 = 45 then locate 0,1 : print "Ro = 45 K-ohms" 1060 delay 5000 1070 goto 105 2000 ' Sous Programme - Gestion affichage CO - 2010 if RsR0 >= 51770 then tmin = 0 2011 if RsR0 >= 14902 and RsR0 < 51770 then tmin = 5 2012 if RsR0 >= 8352 and RsR0 < 14902 then tmin = 15 2013 if RsR0 >= 5703 and RsR0 < 8352 then tmin = 25 2014 if RsR0 >= 4289 and RsR0 < 5703 then tmin = 35 2015 if RsR0 >= 3417 and RsR0 < 4289 then tmin = 45 2016 if RsR0 >= 2404 and RsR0 < 3417 then tmin = 55 2017 if RsR0 >= 2086 and RsR0 < 2404 then tmin = 65 2018 if RsR0 >= 1839 and RsR0 < 2086 then tmin = 75 2019 if RsR0 >= 1641 and RsR0 < 1839 then tmin = 85 2020 if RsR0 >= 1481 and RsR0 < 1641 then tmin = 95 2022 if RsR0 >= 1234 and RsR0 < 1347 then tmin = 115 2023 if RsR0 >= 1138 and RsR0 < 1234 then tmin = 125 2024 if RsR0 >= 1055 and RsR0 < 1138 then tmin = 135 2025 if RsR0 >= 983 and RsR0 < 1055 then tmin = 145 2026 if RsR0 >= 920 and RsR0 < 983 then tmin = 155 2027 if RsR0 >= 864 and RsR0 < 920 then tmin = 165 2028 if RsR0 >= 813 and RsR0 < 864 then tmin = 175 2030 if RsR0 >= 769 and RsR0 < 813 then tmin = 185 2031 if RsR0 >= 728 and RsR0 < 769 then tmin = 195 2032 if RsR0 >= 692 and RsR0 < 728 then tmin = 205 2033 if RsR0 >= 658 and RsR0 < 692 then tmin = 215 2034 if RsR0 >= 628 and RsR0 < 658 then tmin = 225 2035 if RsR0 >= 600 and RsR0 < 628 then tmin = 235 2036 if RsR0 >= 574 and RsR0 < 600 then tmin = 245 2037 if RsR0 >= 551 and RsR0 < 574 then tmin = 255 2038 if RsR0 >= 529 and RsR0 < 551 then tmin = 265 2039 if RsR0 >= 509 and RsR0 < 529 then tmin = 275 2040 if RsR0 >= 490 and RsR0 < 509 then tmin = 285 2041 if RsR0 >= 472 and RsR0 < 490 then tmin = 295 2042 if RsR0 >= 456 and RsR0 < 472 then tmin = 305 2043 if RsR0 >= 440 and RsR0 < 456 then tmin = 315 2044 if RsR0 >= 426 and RsR0 < 440 then tmin = 325 2045 if RsR0 >= 412 and RsR0 < 426 then tmin = 335 2046 if RsR0 >= 399 and RsR0 < 412 then tmin = 345 2047 if RsR0 >= 387 and RsR0 < 399 then tmin = 355 2048 if RsR0 >= 376 and RsR0 < 387 then tmin = 365 2049 if RsR0 >= 365 and RsR0 < 376 then tmin = 375 2050 if RsR0 >= 355 and RsR0 < 365 then tmin = 385 2051 if RsR0 >= 345 and RsR0 < 355 then tmin = 395 2052 if RsR0 >= 336 and RsR0 < 345 then tmin = 405 2053 if RsR0 >= 327 and RsR0 < 336 then tmin = 415 2054 if RsR0 >= 319 and RsR0 < 327 then tmin = 425 2055 if RsR0 >= 311 and RsR0 < 319 then tmin = 435 2056 if RsR0 >= 303 and RsR0 < 311 then tmin = 445 2057 if RsR0 >= 296 and RsR0 < 303 then tmin = 455 2058 if RsR0 >= 289 and RsR0 < 296 then tmin = 465 2059 if RsR0 >= 283 and RsR0 < 289 then tmin = 475 2060 if RsR0 >= 276 and RsR0 < 283 then tmin = 485 2061 if RsR0 >= 270 and RsR0 < 276 then tmin = 495 2062 if RsR0 >= 264 and RsR0 < 270 then tmin = 505 2063 if RsR0 >= 259 and RsR0 < 264 then tmin = 515 2064 if RsR0 >= 253 and RsR0 < 259 then tmin = 525 2065 if RsR0 >= 248 and RsR0 < 253 then tmin = 535 2066 if RsR0 >= 243 and RsR0 < 248 then tmin = 545 2067 if RsR0 >= 238 and RsR0 < 243 then tmin = 555 2068 if RsR0 >= 234 and RsR0 < 238 then tmin = 565 2069 if RsR0 >= 229 and RsR0 < 234 then tmin = 575 2070 if RsR0 >= 225 and RsR0 < 229 then tmin = 585 2071 if RsR0 >= 221 and RsR0 < 225 then tmin = 595 2072 if RsR0 >= 217 and RsR0 < 221 then tmin = 605 2073 if RsR0 >= 213 and RsR0 < 217 then tmin = 615 2074 if RsR0 >= 209 and RsR0 < 213 then tmin = 625 2075 if RsR0 >= 206 and RsR0 < 209 then tmin = 635 2076 if RsR0 >= 202 and RsR0 < 206 then tmin = 645 2077 if RsR0 >= 199 and RsR0 < 202 then tmin = 655 2078 if RsR0 >= 195 and RsR0 < 199 then tmin = 665 2079 if RsR0 >= 192 and RsR0 < 195 then tmin = 675 2080 if RsR0 >= 189 and RsR0 < 192 then tmin = 685 2081 if RsR0 >= 186 and RsR0 < 189 then tmin = 695 2082 if RsR0 >= 183 and RsR0 < 186 then tmin = 705 2083 if RsR0 >= 180 and RsR0 < 183 then tmin = 715 2084 if RsR0 >= 178 and RsR0 < 180 then tmin = 725 2085 if RsR0 >= 175 and RsR0 < 178 then tmin = 735 2086 if RsR0 >= 172 and RsR0 < 175 then tmin = 745 2087 if RsR0 >= 170 and RsR0 < 172 then tmin = 755 2088 if RsR0 >= 167 and RsR0 < 170 then tmin = 765 2089 if RsR0 >= 165 and RsR0 < 167 then tmin = 775 2090 if RsR0 >= 163 and RsR0 < 165 then tmin = 785 2091 if RsR0 >= 160 and RsR0 < 163 then tmin = 795 2092 if RsR0 >= 158 and RsR0 < 160 then tmin = 805 2093 if RsR0 >= 156 and RsR0 < 158 then tmin = 815 2094 if RsR0 >= 154 and RsR0 < 156 then tmin = 825 2095 if RsR0 >= 152 and RsR0 < 154 then tmin = 835 2096 if RsR0 >= 150 and RsR0 < 152 then tmin = 845 2097 if RsR0 >= 148 and RsR0 < 150 then tmin = 855 2098 if RsR0 >= 146 and RsR0 < 148 then tmin = 865 2099 if RsR0 >= 144 and RsR0 < 146 then tmin = 875 2100 if RsR0 >= 142 and RsR0 < 144 then tmin = 885 2101 if RsR0 >= 141 and RsR0 < 142 then tmin = 895 2102 if RsR0 >= 139 and RsR0 < 141 then tmin = 905 2103 if RsR0 >= 137 and RsR0 < 139 then tmin = 915 2104 if RsR0 >= 136 and RsR0 < 137 then tmin = 925 2105 if RsR0 >= 134 and RsR0 < 136 then tmin = 935 2106 if RsR0 >= 132 and RsR0 < 134 then tmin = 945 2107 if RsR0 >= 131 and RsR0 < 132 then tmin = 955 2108 if RsR0 >= 129 and RsR0 < 131 then tmin = 965 2109 if RsR0 >= 128 and RsR0 < 129 then tmin = 975 2110 if RsR0 >= 127 and RsR0 < 128 then tmin = 985 2111 if RsR0 < 127 then tmin = 1000 : tmax = 10000 2112 tmax = tmin + 10 2130 locate 0,0 : print "%CO min:";dec(tmin);"ppm" 2140 locate 0,1 : print "%CO max:";dec(tmax);"ppm" 2150 return