Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '****************************************************************
- '* Name : UNTITLED.BAS *
- '* Author : Mike Mummert *
- '* Notice : Copyright (c) 2013 under penelty of death *
- '* : All Rights Reserved *
- '* Date : 6/30/2013 *
- '* Version : 1.0 *
- '* Notes : *
- '* : *
- '****************************************************************
- INCLUDE "modedefs.bas"
- include "ALLDIGITAL.pbp"
- DEFINE DEBUG_REG PORTB
- DEFINE DEBUG_BIT 3
- DEFINE DEBUG_BAUD 9600
- ' Set Debug mode: 0 = true, 1 = inverted
- DEFINE DEBUG_MODE 1
- DEFINE OSC 4
- OSCCON =$60 'clock speed
- '_______ports
- 'TX VAR portB.1
- ' RX VAR PortB.4
- lcd var PortA.6
- DQ var PortA.0
- Clock var PortA.1
- RESET var PortA.2
- OpenRelay var PortB.2
- CloseRelay Var portB.1
- up_button var PortA.3
- Down_button var PortA.4
- '_______Cons
- Baud CON 84 ' 9600 baud, non-inverted
- BaudMode CON 84 ' 9600 baud, non-inverted
- RdTmp CON $AA ' read temperature
- WrHi CON $01 ' write TH (high temp)
- WrLo CON $02 ' write TL (low temp)
- RdHi CON $A1 ' read TH
- RdLo CON $A2 ' read TL
- RdCntr CON $A0 ' read counter
- RdSlope CON $A9 ' read slope
- StartC CON $EE ' start conversion
- StopC CON $22 ' stop conversion
- WrCfg CON $0C ' write config register
- RdCfg CON $AC ' read config register
- DegSym CON 186 ' degrees symbol
- ' -----[ Variables ]-------------------------------------------------------
- tempIn VAR Word ' raw temperature
- sign VAR tempIn.BIT8 ' 1 = negative temperature
- tC VAR Word ' Celsius
- tF VAR Word ' Fahrenheit
- program VAR Byte
- tempup VAR Byte
- tempdown VAR Byte
- temp VAR Word
- timelmt VAR Word
- result var word
- myTemp var byte
- tempAdj_bit var byte
- tempAdj_bit =0
- Attn var byte
- time_bit var bit
- hyst VAR BYTE
- hyst =8
- mode var byte
- backlight_bit var bit
- mem var byte
- step1 var bit
- step2 var bit
- step3 var bit
- step4 var bit
- multiplier_switch var PortB.0
- step1 = 0
- step2 = 0
- step3 = 0
- step4 = 0
- 'thermistor vars
- co0 VAR Word
- co0 = 162
- co1top VAR Word
- co1top = 255
- co1btm VAR Word
- co1btm = 2125
- co2bt1 VAR Word
- co2bt1 = 25
- co2top VAR Word
- co2top = 3
- co2btm VAR Word
- co2btm = 50
- thermvar0 var word
- thermvar1 var word
- ' -----[ Initialization ]--------------------------------------------------
- Setup:
- pause 1000
- serout2 lcd,baud,["?B64"]'set backlight intensity
- Pause 500
- serout2 lcd,baud,["?f"]'clear screen
- pause 200
- serout2 lcd,baud,["?c0"] 'no cursor
- serout2 lcd,baud,["?G216"]
- HIGH RESET ' alert the DS1620
- SHIFTOUT DQ, Clock, LSBFIRST, [WrCfg, %10] ' use with CPU; free-run
- LOW RESET
- PAUSE 10
- HIGH RESET
- SHIFTOUT DQ, Clock, LSBFIRST, [StartC] ' start conversions
- LOW RESET
- 'lcd setup
- pause 200
- serout2 lcd,baud,["?f"]
- READ 1, mytemp 'read target from mem
- IF mytemp > 75 THEN mytemp = 73
- ' -----[ Program Code ]----------------------------------------------------
- Main:
- debug dec step1,dec step2,dec step3,dec step4, cr
- timelmt=0 'button time out zero-ing
- serout2 lcd,baud,["?x00?y1Target ?x08?y1",dec myTemp]
- pause 1000
- GOSUB Read_DS1620 ' get the temperature
- serout2 lcd,baud,["?x08?y1"," "] 'Blink :
- pause 500
- GOSUB Check_temp 'compare set temp with actual
- IF Down_button=0 OR up_button =0 THEN
- GOSUB inpress
- IF tempadj_bit = 1 THEN
- WRITE 1,mytemp 'write target from mem only if changed
- debug "Writing", cr
- tempadj_bit = 0
- endif
- ENDIF
- GOTO main
- ' -----[ Subroutines ]-----------------------------------------------------
- Read_DS1620:
- HIGH RESET ' alert the DS1620
- SHIFTOUT DQ, Clock, LSBFIRST, [WrCfg, %10] ' use with CPU; free-run
- LOW RESET
- PAUSE 10
- HIGH RESET
- SHIFTOUT DQ, Clock, LSBFIRST, [StartC] ' start conversions
- LOW RESET
- HIGH RESET ' alert the DS1620
- SHIFTOUT DQ, Clock, LSBFIRST, [RdTmp] ' give command to read temp
- SHIFTIN DQ, Clock, LSBPRE, [tempIn\9] ' read it in
- IF tempIn =0 THEN GOTO read_ds1620
- ''tempin = tempin -2 'calibration attempt..unit running 2 degrees on the warm side, attempting -2
- LOW RESET ' release the DS1620
- tempIn.BYTE1 = -sign ' extend sign bit
- tC = tempIn * 5 ' convert to tenths
- IF (tC.BIT15 = 0) THEN ' temp C is positive
- tF = tC */ $01CC + 320 ' convert to F
- ELSE ' temp C is negative
- tF = 320 - ((ABS tC) */ $01CC) ' convert to F
- ENDIF
- '-----------------thermistor code
- high portA.7
- pause 1
- RCTIME portA.7,1,thermvar0 ' 46 is the scale factor.
- DEBUG DEC thermvar0, cr, cr
- '_____Display Temp on LCD
- serout2 lcd,baud, ["?x00?y0Temperature ",DEC (ABS tF / 10)," "] 'display temp on lcd
- RCSTA.4=0
- RCSTA.4=1
- RETURN
- Check_temp:
- IF multiplier_switch = 1 THEN
- IF (ABS tF / 10) => mytemp+2 THEN
- debug "in high",cr
- IF step1 = 0 THEN
- low closerelay
- high OpenRelay
- pause 10000
- low openrelay
- step1=1
- endif
- endif
- IF (ABS tF / 10) =< mytemp THEN
- IF step1 =1 THEN
- low openrelay
- high CloseRelay
- step1 = 0
- step2 = 0
- step3 = 0
- step4 = 0
- endif
- endif
- IF (ABS tF / 10) => mytemp +4 THEN
- IF step2 = 0 THEN
- low closerelay
- high OpenRelay
- pause 10000
- low openrelay
- step2=1
- endif
- endif
- IF (ABS tF / 10) =< mytemp +2 THEN
- IF step2 =1 THEN
- low openrelay
- high CloseRelay
- pause 8750
- low closerelay
- step2=0
- endif
- endif
- IF (ABS tF / 10) => mytemp +6 THEN
- IF step3 = 0 THEN
- low closerelay
- high OpenRelay
- pause 10000
- low openrelay
- step3=1
- endif
- endif
- IF (ABS tF / 10) =< mytemp +4 THEN
- IF step3 =1 THEN
- low openrelay
- high CloseRelay
- pause 8750
- low closerelay
- step3=0
- endif
- endif
- IF (ABS tF / 10) => mytemp +8 THEN
- IF step4 = 0 THEN
- low closerelay
- high OpenRelay
- step4=1
- endif
- endif
- IF (ABS tF / 10) =< mytemp +6 THEN
- IF step4=1 THEN
- low openrelay
- high CloseRelay
- pause 8750
- low closerelay
- step4=0
- endif
- endif
- endif
- IF multiplier_switch = 0 THEN
- IF (ABS tF / 10) => mytemp+2 THEN
- debug "in low",cr
- IF step1 = 0 THEN
- low closerelay
- high OpenRelay
- pause 7500
- low openrelay
- step1=1
- endif
- endif
- IF (ABS tF / 10) =< mytemp THEN
- IF step1 =1 THEN
- low openrelay
- high CloseRelay
- step1 = 0
- step2 = 0
- step3 = 0
- step4 = 0
- endif
- endif
- IF (ABS tF / 10) => mytemp +4 THEN
- IF step2 = 0 THEN
- low closerelay
- high OpenRelay
- pause 5000
- low openrelay
- step2=1
- endif
- endif
- IF (ABS tF / 10) =< mytemp +2 THEN
- IF step2 =1 THEN
- low openrelay
- high CloseRelay
- pause 4375
- low closerelay
- step2=0
- endif
- endif
- IF (ABS tF / 10) => mytemp +6 THEN
- IF step3 = 0 THEN
- low closerelay
- high OpenRelay
- pause 5000
- low openrelay
- step3=1
- endif
- endif
- IF (ABS tF / 10) =< mytemp +4 THEN
- IF step3 =1 THEN
- low openrelay
- high CloseRelay
- pause 4375
- low closerelay
- step3=0
- endif
- endif
- IF (ABS tF / 10) => mytemp +8 THEN
- IF step4 = 0 THEN
- low closerelay
- high OpenRelay
- step4=1
- endif
- endif
- IF (ABS tF / 10) =< mytemp +6 THEN
- IF step4=1 THEN
- low openrelay
- high CloseRelay
- pause 4375
- low closerelay
- step4=0
- endif
- endif
- endif
- RETURN
- inpress:
- timelmt=timelmt +1
- IF timelmt >5000 THEN
- RETURN
- endif
- IF up_button = 0 THEN GOTO plus
- IF down_button =0 THEN GOTO minus
- GOTO inpress
- plus:
- mytemp=mytemp +1
- IF mytemp>85 THEN mytemp =85
- timelmt=0
- serout2 lcd,baud,["?x08?y1",dec myTemp]
- pause 500
- tempAdj_bit = 1
- hyst =15
- GOTO inpress
- minus:
- mytemp=mytemp -1
- IF mytemp <40 THEN mytemp =40
- timelmt=0
- serout2 lcd,baud,["?x08?y1",dec myTemp]
- pause 500
- tempAdj_bit = 1
- hyst = 5
- GOTO inpress
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement