#picaxe 18m2 ' Converted by X2 Conversion Wizard Version 2.0.5 (2010r4.1) 'LCD routines thanks to picaxe forum guru Hippy let dirsB = %11111111 let dirsC = %00000000 let adcsetup = 0 SYMBOL RS = B.2 ; 0 = Command 1 = Data SYMBOL E = B.3 ; 0 = Idle 1 = Active SYMBOL DB4 = B.4 ; LCD Data Line 4 SYMBOL DB5 = B.5 ; LCD Data Line 5 SYMBOL DB6 = B.6 ; LCD Data Line 6 SYMBOL DB7 = B.7 ; LCD Data Line 7 SYMBOL RSCMDmask = %00000000 ; Select Command register SYMBOL RSDATmask = %00000100 ; Select Data register SYMBOL set_temp = b6 SYMBOL units = b7 SYMBOL tens = b8 SYMBOL hundreds = b9 SYMBOL temp = w2 SYMBOL fetch = b11 SYMBOL bite = b12 SYMBOL rsbit = b13 PowerOnReset: GOSUB InitialiseLcd DisplayTopLine: EEPROM 6,("Set Brew") ' to eeprom 13 FOR fetch = 6 TO 9 READ fetch,bite GOSUB SendDataByte NEXT bite = 140 GOSUB SendCmdByte 'cursor to end of topline FOR fetch = 10 TO 13 READ fetch, bite GOSUB SendDataByte NEXT IF pinC.7 = 1 AND pinC.6 = 1 THEN GOTO Fahrenheit Celsius: LET set_temp = 18 'pre-seed set temp to avoid 18sec of button pushes bite = 135 ' cursor to middle of top line GOSUB SendCmdByte bite = 223 'degrees sign GOSUB SendDataByte bite = "C" GOSUB SendDataByte main_celsius: readtemp C.1,temp if pinC.6 = 1 then inc set_temp endif if pinC.7 = 1 then dec set_temp endif let bite = 192 GOSUB SendCmdByte 'start of bottom line BINTOASCII set_temp, hundreds, tens, units let bite = hundreds GOSUB SendDataByte LET bite = tens GOSUB SendDataByte LET bite = units GOSUB SendDataByte LET bite = 205 GOSUB SendCmdByte 'end of bottom line BINTOASCII temp, hundreds, tens, units LET bite = hundreds GOSUB SendDataByte LET bite = tens GOSUB SendDataByte LET bite = units GOSUB SendDataByte IF temp = set_temp THEN LET pinB.0 = 1 ELSE LET pinB.0 = 0 ENDIF IF temp < set_temp THEN LET pinB.1 = 1 ELSE LET pinB.1=0 ENDIF GOTO main_celsius Fahrenheit: LET set_temp = 64 'pre-seed set temp to avoid 64sec of button pushes bite = 135 ' cursor to middle of top line GOSUB SendCmdByte bite = 223 ' Degrees sign GOSUB SendDataByte bite = "F" GOSUB SendDataByte main_fahrenheit: readtemp12 C.1,temp convertfarenheit: temp = temp+880/16*9/5-67 'convert 12bit raw temp to fahrenheit if pinC.6 = 1 then inc set_temp endif if pinC.7 = 1 then dec set_temp endif let bite = 192 GOSUB SendCmdByte 'start of bottom line BINTOASCII set_temp, hundreds, tens, units let bite = hundreds GOSUB SendDataByte LET bite = tens GOSUB SendDataByte LET bite = units GOSUB SendDataByte LET bite = 205 GOSUB SendCmdByte 'end of bottom line BINTOASCII temp, hundreds, tens, units LET bite = hundreds GOSUB SendDataByte LET bite = tens GOSUB SendDataByte LET bite = units GOSUB SendDataByte IF temp = set_temp THEN LET pinB.0 = 1 ELSE LET pinB.0 = 0 ENDIF IF temp < set_temp THEN LET pinB.1 = 1 ELSE LET pinB.1=0 ENDIF GOTO main_fahrenheit END InitialiseLcd: FOR fetch = 0 TO 5 READ fetch,bite GOSUB SendInitCmdByte NEXT ' Nibble commands - To initialise 4-bit mode EEPROM 0,( $33 ) ; %0011---- %0011---- 8-bit / 8-bit EEPROM 1,( $32 ) ; %0011---- %0010---- 8-bit / 4-bit ' Byte commands - To configure the LCD EEPROM 2,( $28 ) ; %00101000 %001LNF00 Display Format EEPROM 3,( $0C ) ; %00001100 %00001DCB Display On EEPROM 4,( $06 ) ; %00000110 %000001IS Cursor Move ; L : 0 = 4-bit Mode 1 = 8-bit Mode ; N : 0 = 1 Line 1 = 2 Lines ; F : 0 = 5x7 Pixels 1 = N/A ; D : 0 = Display Off 1 = Display On ; C : 0 = Cursor Off 1 = Cursor On ; B : 0 = Cursor Steady 1 = Cursor Flash ; I : 0 = Dec Cursor 1 = Inc Cursor ; S : 0 = Cursor Move 1 = Display Shift EEPROM 5,( $01 ) ; Clear Screen RETURN SendInitCmdByte: PAUSE 15 ; Delay 15mS SendCmdByte: rsbit = RSCMDmask ; Send to Command register SendDataByte: pinsB = bite & %11110000 | rsbit ; Put MSB out first PULSOUT E,2 ; Give a 10uS pulse on E pinsB = bite * %00010000 | rsbit ; Put LSB out second PULSOUT E,2 ; Give a 10uS pulse on E rsbit = RSDATmask ; Send to Data register next RETURN