'r_mem.bs2, the program for loading memory locs. 0-63 with thermistor 'temp. values, must be run first! '>>>> TO DO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<: '>>>> Add fix for a temp < 128 defaulting to 255 degF (so htrs. are off). '>>>> Implement PosCrsr: for positioning the cursor! Sub is written... '>>>> Fix level indicator circuit and implement as pin 15 '>>>> Add auto. pump speed control '>>>> Port logic and op. interface over to a PC.... ' Stamp pin connections:-------------------------------- ' Pin 0 LCD pin 11 : D4 | Can use the ' Pin 1 LCD pin 12 : D5 |-- OutA dohickey ' Pin 2 LCD pin 13 : D6 | to send data ' Pin 3 LCD pin 14 : D7 | to LCD... ' Pin 4 LCD pin 4 : RS ' Pin 5 LCD pin 6 : E ' pin6 Rims pump inlet temp, var: rt1 ' pin7 Rims pump outlet temp, var: rt2 ' pin8 Piezo sounder ' pin9 Sparge temp thermistor 'was a speaker! ' pin10 DS1302 reset- RST (reset) ' pin11 DS1302 data i/o ' pin12 DS1302 clock ' pin13 Sparge heater ' pin14 Rims heater ' pin15 level sensor '----- Clock I/O constants ---------------------------------------------- dsrst con 10 ' rst* pin 5 (normally low w 47k) dsio con 11 ' i/o pin 6 dsclk con 12 ' sclk pin 7 (pull low w 47k) '----- LCD Constants -------------------------------------------------- True CON 1 False CON 0 Nlz CON True ' No leading zeros (in T_Out) DegSym CON 223 ' degrees symbol ' LCD control pins E CON 5 ' LCD enable pin (1 = enabled) RS CON 4 ' Register Select (1 = char) ' LCD control characters ClrLCD CON $01 ' clear the LCD CrsrHm CON $02 ' move cursor to home position CrsrLf CON $10 ' move cursor left CrsrRt CON $14 ' move cursor right DispLf CON $18 ' shift displayed chars left DispRt CON $1C ' shift displayed chars right '------ Constants for addressing the DS1302---------------------- dssec con $80 ' seconds register dsmin con $82 ' minutes register dshr con $84 ' hours register dsctl con $8E ' control register dsram con $C0 ' start of ram (24 bytes) ' Variables --------------------------------------------------- ' -----LCD Variables --------- char VAR Byte 'char sent to LCD ' -----My variables------------------------------------ keyb var nib 'input from pins 0-4= keypad (val: 0-15) rts var byte 'rims suction temp via pin 6 rtd var byte 'rims discharge temp via pin 7 setp var byte 'setpoint temp et var byte 'elasped time a var byte 'temporary vav. c var byte 'thermistor count returned from GetTemp6, 7 or 9 temp var byte 'temperature var. i var byte 'temporary var. r var nib 'used to set tone for piezo via freqout tn var bit 'sound toggle rhs var bit 'rims heater status 1-=on, 0=off shs var bit 'sprg heater status 1-=on, 0=off st var byte 'sparge temp cp var nib 'cursor position level var word '-- these variables are copies of the DS1302 registers----------- os var byte 'old secs secs var byte 'bcd seconds mm var byte 'bcd minutes hh var byte 'bcd hours dsaddr var byte 'DS1302 register address we're whacking dsdata var byte 'data to and from DS1302 t1 var byte 'used with time subroutines ' Constants for lcd commands------------------------------ ' dsis is the initialisation string for the clock. ' consists of pairs . Note the first entries should ' write enable the clock and then stop it running, and the ' last entries should restart and write protect it! dsis data dsctl,0 ' write enable the clock data dssec,$80 ' stop clock, set secs to 00 data dshr,$22 ' 24 hour clock, 2000 data dsmin,$04 ' 04 minutes data dssec,$45 ' start the clock running again data dsctl,$80 ' write protect the clock data 0,0 ' end of the list '----[ memory locs ]------------------------------------------------------ '0-63: temp conversion factors, loaded by r_mem.bs2 '84 starting hrs '85 starting mins '86 set point for RIMS heater '87 DELETED rims heater on/off 1/0 '88 DELETED sparge heater on/off 1/0 '89 DELETED sparge temp.- changed to st (a variable) '90 DELETED sparge sp. ' -----[Initialization ]---------------------------------------------- DIRS = %0110000100111111 ' was DirL = %00111111 OUTS = $0000 ' all outputs off to start, in HEX gosub I_LCD ' Initialize the LCD char=ClrLCD : GOSUB LCDcmd tn=1 'startup sound as a default read 90,a if a>100 then Main a =168 Main: '################################################################ gosub GetET char=CrsrHm : GOSUB LCDcmd char="s" : gosub WrLCD char=":" : gosub WrLCD gosub GetTemp6 'suction temp gosub T_Out char=" " : gosub WrLCD char="s" : gosub WrLCD char="p" : gosub WrLCD char=":" : gosub WrLCD read 86,temp 'setpoint temp gosub T_Out char=" " : gosub WrLCD char="O" : gosub WrLCD if rhs=1 then HtrON goto HtrOff HtrOn: char="n" : gosub WrLCD char=" " : gosub WrLCD goto arf HtrOff: char="f" : gosub WrLCD char="f" : gosub WrLCD arf: char = %11000000: gosub LcdCmd 'put cursor on 2nd line char="d" : gosub WrLCD char=":" : gosub WrLCD gosub GetTemp7 'discharge temp gosub T_Out read 86,a 'rims setpoint setp=a 'rims setpoint if rts => setp then rtok 'rts is rims suction temp, setp is setpoint if rtd > setp+1 then rtok 'rtd is rims dischrg temp, setp is setpoint if tn=0 then fg 'if no noise wanted r=r+1 pwm 8,30,r/14*50 'beep twice fg: LOW 13 'S Htr Off shs=0 pause 5 HIGH 14 'R Htr ON rhs=1 goto ar2 rtok: LOW 14 'R Htr OFF rhs=0 ar2: char=" " : gosub WrLCD char="e" : gosub WrLCD char="t" : gosub WrLCD char=":" : gosub WrLCD temp=et gosub T_Out char=" " : gosub WrLCD 'checkout sparge water temp gosub GetTemp9 'sparge temp returned as Temp variable read 90,a 'get sparge setpoint if rhs=1 then SHOff 'rims heater is ON, make sure sparge heater is OFF if temp5 then key6 i=i-1 'decrease sparge sp goto dd key6: if keyb<>6 then da i=i+1 'increase sparge sp dd: write 90,i freqout 8,20,1 pause 200 da: gosub GetK if keyb=5 or keyb=6 then key5 if keyb=4 then daa 'daa is towards start of this sub. goto main ksp: '##### set RIMS setpoint ######################################## if keyb<8 or keyb>10 then main freqout 8,20,1 read 86,i 'read setpoint if i>0 then ar4 'if it's already set, jump i=130 ar4: char = %11000000: gosub LcdCmd 'put cursor on 2nd line char="R" : gosub WrLCD char=" " : gosub WrLCD char="S" : gosub WrLCD char="e" : gosub WrLCD char="t" : gosub WrLCD char=" " : gosub WrLCD char="@" : gosub WrLCD char=" " : gosub WrLCD char=">" : gosub WrLCD temp=i gosub T_Out char=" " : gosub WrLCD char=" " : gosub WrLCD char=" " : gosub WrLCD char=" " : gosub WrLCD key9: if keyb<>9 then key10 i=i-1 'decrement setpoint freqout 8,20,1 key10: if keyb<>10 then ar5 i=i+1 'decrement setpoint freqout 8,20,1 ar5: write 86,i 'write setpoint to memory pause 200 gosub GetK if keyb>7 then ar8 'redo this sub. ?change to ksp? char=ClrLCD : GOSUB LCDcmd 'goto main goto Key7 'huh? ar8: goto ksp 'delete this line? '### Subs ############################################################## ' -----[ Clock Subroutines ]---------------------------------------------- StartTime: ' get starting hh and mm and put in mem 64 and 65 gosub dsrd7 t1=hh : gosub bcd write 84,t1 'put hh in 84 t1=mm : gosub bcd write 85,t1 'put mm in 85 RETURN SetStart: 'later..... GetET: gosub dsrd7 ' update time variables t1=hh : gosub bcd read 84,i 'read starting hh et=(t1-i)*60 t1=mm : gosub bcd read 85,i 'read starting mm if t1>=i then ar6 et=et-60+(60-i)+t1 goto ar7 ar6: et=et+(t1-i) ar7: RETURN bcd: t1=t1>>4*10+(t1 & 15) RETURN dsrd7: ' block read clock vars- unfortunately, shiftin only does ' 16 bits at a shot, so I can't do all 56 bits at once dsaddr = $BF ' clock burst high dsrst ' start the cycle shiftout dsio,dsclk,lsbfirst,[dsaddr\8] shiftin dsio,dsclk,lsbpre,[secs\8] ' 8 for seconds shiftin dsio,dsclk,lsbpre,[mm\8] shiftin dsio,dsclk,lsbpre,[hh\8] low dsrst RETURN ' -----[ LCD Subroutines ]------------------------------------------------- T_Out: ' display a 3-digit number on the LCD. Output is right-justified ' Nlz = No leading zeros (if set to True) ' Hack this sub later to do via the DIG operator... char = temp / 100 + 48 ' convert 100's to ASCII IF char > "0" OR Nlz = False THEN T100 char = " " ' change 0 to space (Nlz = False) T100: GOSUB WrLCD ' show the digit char = temp // 100 / 10 + 48 ' get 10's IF char > "0" THEN T10 IF temp >= 100 OR Nlz = False THEN T10 char = " " T10: GOSUB WrLCD char = temp // 10 + 48 'get 1's GOSUB WrLCD 'write 1's RETURN LCDcmd: ' send command byte to LCD LOW RS ' RS low = command GOSUB WrLCD ' send the byte HIGH RS ' return to character mode RETURN WrLCD: ' Write ASCII char to LCD OutA = char >> 4 ' output high nibble PULSOUT E, 1 ' strobe the Enable line OutA = char ' output low nibble PULSOUT E, 1 RETURN I_LCD: 'initialize the LCD: OutA = %0011 ' 8-bit mode PULSOUT E, 1 PAUSE 5 PULSOUT E, 1 PULSOUT E, 1 OutA = %0010 ' 4-bit mode PULSOUT E, 1 char = %00101000 ' 2 line !!!!!!!!!!!!!!!!!!!! gosub WrLCD char = %00001100 ' disp on, crsr off, blink off GOSUB WrLCD char = %00000110 ' inc crsr, no disp shift GOSUB WrLCD char = %00000001 ' clear LCD GOSUB WrLCD HIGH RS ' LCD to character mode RETURN PosCrsr: 'position cursor to row cp char = CrsrHm: gosub LcdCmd if cp=0 then fff cp=cp-1 for i=0 to cp char = CrsrRt: gosub LcdCmd next fff: RETURN ' -----[ Other Subroutines ]---------------------------------------------- GetK: 'get key(s) depressed as keyb DIRS = %00000000 'change LCD lines to inputs keyb=INA DIRS = %00111111 'restore i/o pins RETURN GetTemp6: 'get RIMS pump suction temp high 6 : pause 1 'get thermistor value- pin 6 rctime 6,1,c gosub ConvTemp rts=temp RETURN GetTemp7: 'get RIMS pump discharge temp high 7 : pause 1 'get thermistor value- pin 7 rctime 7,1,c gosub ConvTemp rtd=temp RETURN GetTemp9: 'sparge temp via pin 9 high 9 : pause 1 'get thermistor value- pin 9 rctime 9,1,c gosub ConvTemp RETURN ConvTemp: 'look up temp. in memory. The memory _contents_ are values the 'RCTIME command will return & memory _address_ are an "offset" 'used to calc. the temperature in degF if c>=80 and c<=254 then ok1 'count is in range temp=255 'count NOT in range- set temp to 255 goto ar9 '? can delete this line? ok1: 'convert count (c) to degF index (i) for i=20 to 83 'cycle thru the memory addresses read i,a 'mem. contents stuff into "a" if a<=c then gotit 'we've hit the address we want next ar9: '? can delete this & next line? RETURN gotit: temp=i+105 'add 105 to address to get the temp. RETURN END