'************************************************************************ '*** *** '*** FLM.BAS is the sorce for a Flow Meter using the 80C552 *** '*** *** '*** Started on 15-12-1998 by Mike Crean, Email autlec@nw.com.au *** '*** *** '*** This code will run on a 80C552 Micro with 64K bit of ROM and *** '*** 64K bit of non volatile RAM with RTC *** '*** *** '*** The sensor for this flow meter was made from a turbine (fan) *** '*** with 2 * magnets mounted on it seperated by 180deg's. & *** '*** opposite polarity's out. A Hall sensor that switches on with *** '*** one polarity and of with the other was mounted on the out side *** '*** of a pice of polly pipe. This signal is then fed to a 4018 chip *** '*** running in / by 10 mode, it's out put is sent to P4.0 as the *** '*** input signal for the 80C552. *** '*** *** '*** If this setup was to be used in another application it would be *** '*** wise to use / switches on the 4018 to allow for more *** '*** calibration. *** '*** *** '*** I have sent this to Mark Alberts C/O MCS Electronics. As the *** '*** code listed may give some helpfull ideas to some of the many *** '*** Bascomlt user's out there. This code is far from complete or *** '*** bug free, so I hope that Mark will place it on his web site. *** '*** *** '*** Ps. The flow rate is output on the LCD or to a terminal when *** '*** requested. Four buttons allow you to scroll menu's on the LCD *** '*** *** '************************************************************************ $large $baud = 9600 $crystal = 11059200 Config Lcd = 16 * 2 Dim W1 As Integer , W2 As Integer , W3 As Integer , W4 As Integer Dim W5 As Integer , Cal As Integer , Adc As Integer , Ad As Integer Dim Rtc As Byte , Rx As Byte , Ck As Byte , Ckgfm As Byte , Min As Byte Dim Gf As Long Ck = 0 : Ckgfm = 0 : Gf = 0 : Cal = 0 : W1 = 0 : W2 = 0 : W3 = 0 W4 = 0 : W5 = 0 : Adc = 0 : Min = 0 : Ad = 8299 Cursor Off Out 16376 , 0 : Out 16377 , 0 Cal = Inp(8194) If Cal = 0 Then Cal = 1 End If Print : Print Print "; = Version" Print "f = Flow in m3" Startone: W4 = Inp(8202) Gf = W4 * 255 W3 = Inp(8201) Gf = Gf + W3 Gf = Gf * 255 W2 = Inp(8200) Gf = Gf + W2 Start: Cls Locate 1 , 1 : Lcd " Flow Meter" Locate 2 , 1 : Lcd " fL m3" Locate 2 , 5 : Lcd Gf Do If Ck > 103 Then Goto Getgasreading End If If Ck = 0 Then Getgasreading: Min = Inp(16378) If Min = 48 Then Goto Skipone End If If Min > 1 Then If Ck = 200 Then Ck = 0 End If End If Skipone: If Min = 48 Then If Ck = 0 Then Gosub Saveit End If End If If Min = 1 Then If Ck = 0 Then Gosub Saveit End If End If If P4.0 = 1 Then If Ckgfm = 0 Then W1 = W1 + 1 Ckgfm = 1 End If End If If P4.0 = 0 Then If Ckgfm = 1 Then Ckgfm = 2 End If End If If P4.0 = 1 Then If Ckgfm = 2 Then Ckgfm = 0 End If End If If W1 > Cal Then If W2 = 10 Then If Ck = 0 Then Locate 2 , 5 : Lcd " " End If End If If W2 = 100 Then If Ck = 0 Then Locate 2 , 5 : Lcd " " End If End If If Ck = 0 Then Locate 2 , 5 : Lcd Gf End If W1 = 0 W2 = W2 + 1 Gf = Gf + 1 Out 8200 , W2 If Gf = 16581375 Then W1 = 0 : W2 = 0 : W3 = 0 : W4 = 0 : Gf = 0 Out 8200 , 0 : Out 8201 , 0 : Out 8202 , 0 End If End If If W2 = 255 Then W1 = 0 : W2 = 0 W3 = W3 + 1 Out 8201 , W3 End If If W3 = 255 Then W1 = 0 : W2 = 0 : W3 = 0 W4 = W4 + 1 Out 8202 , W4 End If If W4 = 255 Then W1 = 0 : W2 = 0 : W3 = 0 : W4 = 0 : Gf = 0 Out 8200 , 0 : Out 8201 , 0 : Out 8202 , 0 End If End If Rx = Inkey If Rx = 102 Then Print ":" ; Gf ; " fL-m3" End If If Rx = 59 Then Print : Print ":Flow Meter V1.2" Print ":Copyright (c) Autlec Perth Aust. 1998" End If If Rx = 91 Then Goto Sendtime End If If Rx = 92 Then Cls : Locate 1 , 3 : Lcd "PC Download" Locate 2 , 3 : Lcd "Add. " Print ":Start Download" : Print : Print ":"; Adc = 0 For W5 = 8300 To 15020 Adc = Inp(w5) Print Adc ; "~"; Locate 2 , 8 : Lcd W5 Next W5 Print : Print ":End Download" W5 = 0 : Adc = 0 Waitms 100 Goto Start End If If P4.7 = 0 Then If Ck = 0 Then Ck = 1 Waitms 250 End If End If If P4.7 = 0 Then If Ck = 100 Then Ck = 2 Waitms 250 End If End If If P4.7 = 0 Then If Ck = 101 Then Ck = 3 Waitms 250 End If End If If P4.7 = 0 Then If Ck = 102 Then Ck = 4 Waitms 250 End If End If If P4.7 = 0 Then If Ck = 103 Then Ck = 5 Waitms 250 End If End If If P4.7 = 0 Then If Ck = 104 Then Ck = 6 Waitms 250 End If End If If P4.7 = 0 Then If Ck = 105 Then Ck = 7 Waitms 250 End If End If If P4.7 = 0 Then If Ck = 107 Then Ck = 0 Waitms 250 Goto Start End If End If If Ck = 1 Then Cls : Locate 1 , 1 : Lcd "V1.2 Copyright" Locate 2 , 1 : Lcd "Autlec Perth1998" Print : Print ":Flow Meter V1.2" Print ":Copyright (c) Autlec Perth Aust. 1998" Ck = 100 Waitms 250 End If If Ck = 2 Then Cls : Locate 1 , 1 : Lcd "Dn * 100 +" Locate 2 , 1 : Lcd "Rb-Up Lb-Dn_Set" Print "" Print ":Changing reading m3" Print ":Right Button Up - Left Button Dn + Down Button * 100" Ck = 101 Waitms 250 End If If Ck = 3 Then Cls : Locate 1 , 1 : Lcd "fL will be ZERO" Locate 2 , 1 : Lcd "Rb-Do it" Print : Print ":Flow will be Zeroed" Print ":Right Button Do it" Ck = 102 Waitms 250 End If If Ck = 4 Then Cls : Locate 1 , 1 : Lcd " Calibrate" Locate 2 , 1 : Lcd Cal Print ":Calibrate" Print ":" ; Cal Ck = 103 Waitms 250 End If If Ck = 5 Then Cls : Locate 1 , 1 : Lcd " Line Pressure" Locate 2 , 7 : Lcd "kPa" Print ":Line Pressure" Print ":k - display" Ck = 104 Waitms 250 End If If Ck = 6 Then Cls : Locate 1 , 1 : Lcd "Line Temperature" Locate 2 , 6 : Lcd "C" Print ":Line Temperature" Print ":c - display" Ck = 105 Waitms 250 End If If Ck = 7 Then Cls : Locate 1 , 1 : Lcd "Time" Locate 2 , 1 : Lcd "Date" Print ":Time and Date" Print ":t - display" Ck = 107 Waitms 250 End If If P4.4 = 0 Then If Gf < 160000099 Then If Ck = 101 Then Cls : Locate 1 , 1 : Lcd "Changing Reading" Print ":Changing Reading" Gf = Gf + 1 W2 = W2 + 1 Locate 2 , 1 : Lcd Gf Print ":" ; Gf Waitms 80 End If End If End If If P4.5 = 0 Then If Gf > 0 Then If Ck = 101 Then Cls : Locate 1 , 1 : Lcd "Changing Reading" Print ":Changing Reading" Gf = Gf - 1 W2 = W2 - 1 Locate 2 , 1 : Lcd Gf Print ":" ; Gf Waitms 80 End If End If End If If P4.6 = 0 Then If P4.4 = 0 Then If Gf < 160000099 Then If Ck = 101 Then Cls : Locate 1 , 1 : Lcd "Changing Reading" Print ":Changing Reading" Gf = Gf + 100 W2 = W2 + 100 Locate 2 , 1 : Lcd Gf Print ":" ; Gf Waitms 10 End If End If End If End If If P4.6 = 0 Then If P4.5 = 0 Then If Gf > 100 Then If Ck = 101 Then Cls : Locate 1 , 1 : Lcd "Changing Reading" Print ":Changing Reading" Gf = Gf - 100 W2 = W2 - 100 Locate 2 , 1 : Lcd Gf Print ":" ; Gf Waitms 10 End If End If End If End If If P4.4 = 0 Then If Ck = 102 Then Goto Zero End If End If If P4.4 = 0 Then If Ck = 103 Then Locate 2 , 1 : Lcd " " If Cal < 500 Then Cal = Cal + 1 Out 8194 , Cal End If Locate 2 , 2 : Lcd Cal Waitms 100 End If End If If P4.5 = 0 Then If Ck = 103 Then Locate 2 , 1 : Lcd " " If Cal > 1 Then Cal = Cal - 1 Out 8194 , Cal End If Locate 2 , 2 : Lcd Cal Waitms 100 End If End If If Ck = 104 Then Adc = 0 Gosub Adconvert Adc = Inp(16192) Adc = Adc - 55 Adc = Adc - 100 If Adc => 0 Then Locate 2 , 1 : Lcd " " Locate 2 , 2 : Lcd Adc If Rx = 107 Then Print ":" ; Adc ; "kPa" End If End If Waitms 50 End If If Ck = 105 Then Adc = 0 Gosub Adconvert Adc = Inp(16193) Locate 2 , 1 : Lcd " " Locate 2 , 2 : Lcd Adc If Rx = 99 Then Print ":" ; Adc ; "C" End If Waitms 50 End If If Ck = 107 Then Sendtime: Rtc = 0 : Locate 1 , 6 : Lcd " " : Locate 1 , 6 Rtc = Inp(16379) : Lcd Bcd(rtc) ; ":" ; If Rx = 116 Then Print ":Time " ; Bcd(rtc) ; ":"; End If Rtc = 0 : Rtc = Inp(16378) : Lcd Bcd(rtc) ; ":" ; If Rx = 116 Then Print Bcd(rtc) ; ":"; End If Rtc = 0 : Rtc = Inp(16377) : Lcd Bcd(rtc) If Rx = 116 Then Print Bcd(rtc) End If Rtc = 0 : Locate 2 , 6 : Lcd " " : Locate 2 , 6 Rtc = Inp(16381) : Lcd Bcd(rtc) ; "/" ; If Rx = 116 Then Print ":Date " ; Bcd(rtc) ; "/"; End If Rtc = 0 : Rtc = Inp(16382) : Lcd Bcd(rtc) ; "/" ; If Rx = 116 Then Print Bcd(rtc) ; "/"; End If Rtc = 0 : Rtc = Inp(16383) : Lcd Bcd(rtc) If Rx = 116 Then Print Bcd(rtc) Rx = 0 : Ck = 0 Goto Start End If Waitms 20 End If If P4.7 = 0 Then If P4.4 = 0 Then Ck = 0 Waitms 250 Goto Start End If End If P4.4 = 1 : P4.5 = 1 : P4.6 = 1 : P4.7 = 1 Loop End Zero: Out 8200 , 0 : Out 8201 , 0 : Out 8202 , 0 : Gf = 0 If Ck = 102 Then Ck = 0 : Goto Startone End If Return Saveit: Ck = 200 If Ad > 15020 Then 'Allow for 28 days of .5 hour records Ad = 8300 End If Ad = Ad + 1 : Out Ad , Min Min = Inp(16379) Ad = Ad + 1 : Out Ad , Min Ad = Ad + 1 : Out Ad , W2 Ad = Ad + 1 : Out Ad , W3 Ad = Ad + 1 : Out Ad , W4 Return Adconvert: MOV DPTR,#16192 MOV R1,#0 !Loopit: MOV A,R1 MOV ADCON,A ADD A,#40 MOV ADCON,A !ADC1: MOV A,ADCON JNB ACC.4,ADC1 MOV A,ADCH MOVX @DPTR,A PUSH ACC !SWAP A POP ACC INC R1 INC DPTR CJNE R1,#8,Loopit Return End