rem "PicaxeBarometer.bas" 2/9/2008 #PICAXE 14M #COM1 symbol VoltmeterMode = bit0 'Flag for readout type symbol SettingMode = bit1 'Flag for adjustments symbol Iter = b1 symbol Digit = b2 symbol SettingCounter = b3 'Timeout for adjustments symbol BitPos = b4 'For shiftout symbol Mask = b5 'For shiftout symbol ReadingCounter = b6 'For accumulating samples symbol Reading = w4 'Accumulator symbol BaroBase = w5 'Holds the offset symbol AnalogValue = w6 'ADC output symbol Clock = 1 'Clocks Display Controller MC14489 symbol Enable = 2 'Enables Display Controller MC14489 symbol Outdata = 3 'Data for Display Controller MC14489 symbol Upbutton = INPUT1 'Control button for pressure symbol Downbutton = INPUT2 'Control button for voltage symbol ThreeDigitCmd = %0111 'For blanking 2 leading zeroes symbol FourDigitCmd = %0011 'For blanking 1 leading zero symbol FiveDigitCmd = %0001 'The LS nibble of the MC14489 control byte symbol Cmd4MSB = %0100 'The LS nibble of the MC14489 control byte symbol VoltOffset = 509 'Adjusts voltage range to 5 - 15V symbol BaroMult = 32 'Accumulate this number of samples symbol BaroDivisor = 25 symbol SettingStart = 200 'Adjustments time out after this number of loops DATA 0,(8,4,2,1) 'Mask of bits for DispHex DATA 4,($EE,$06) 'Inches of Mercury = 0.0128*count + 17.74 init: High Enable 'Low is active for MC14489 READ 4,WORD BaroBase 'Persistent during power-off main: pause 100 'Control processing IF Upbutton = 1 AND Downbutton = 1 THEN 'To set for barometer correction LET VoltmeterMode = 0 LET SettingMode = 1 LET SettingCounter = SettingStart ENDIF IF SettingMode = 0 THEN IF Upbutton = 1 THEN LET VoltmeterMode = 0 ENDIF IF Downbutton = 1 THEN LET VoltmeterMode = 1 ENDIF ENDIF 'Analog Data processing LET Digit = 4 * VoltmeterMode 'Input0 is pressure, Input4 is volts READADC10 Digit,AnalogValue INC ReadingCounter LET Reading = Reading + AnalogValue IF ReadingCounter >= BaroMult THEN 'Perform calculations and do readout RepeatSetting: 'This stops updating during setting IF VoltmeterMode = 1 THEN LET AnalogValue = Reading / BaroMult + VoltOffset ELSE LET AnalogValue = Reading/BaroDivisor + BaroBase 'In 1/100" Hg ENDIF 'Send the number to the MC14489 display controller, takes 1 byte control & 3 bytes data Low Enable LET Digit = Cmd4MSB GOSUB SendHex LET Digit = ThreeDigitCmd IF AnalogValue < 1000 THEN SendCmd LET Digit = FourDigitCmd IF AnalogValue < 10000 THEN SendCmd LET Digit = FiveDigitCmd SendCmd: GOSUB SendHex 'This blanks leading zeroes PULSOUT Enable,10 'This syncs the MC14489 LET Digit = 7 * SettingMode 'Displays an "C" in setting Mode by energising segments a,d,e,f GOSUB SendHex 'which are hard-wired to use the decimal point of the MC14489 FOR Iter = 0 to 4 'Five digits LET Digit = AnalogValue // 10 LET AnalogValue = AnalogValue / 10 GOSUB SendHex NEXT High Enable 'End sending number 'Adjustments IF SettingMode = 1 THEN IF Upbutton = 1 THEN INC BaroBase LET SettingCounter = SettingStart ENDIF IF Downbutton = 1 THEN DEC BaroBase LET SettingCounter = SettingStart ENDIF IF SettingCounter > 0 THEN DEC SettingCounter GOTO RepeatSetting ELSE LET SettingMode = 0 'Timer to terminate setting mode WRITE 4,WORD BaroBase ENDIF ENDIF LET ReadingCounter = 0 LET Reading = 0 ENDIF goto main SendHex: 'Input is in digit, sends the LS nibble FOR BitPos = 0 TO 3 'Faster than the shiftout workaround in the REV-ED manual READ BitPos,Mask LET Mask = Digit & Mask LOW Outdata IF Mask = 0 then Charbitislow HIGH Outdata Charbitislow: PULSOUT Clock,1 NEXT RETURN