Here is a description of the temptest.bas program.
init: pause 1000 serout 7,N2400,(254,1) serout 6,N2400,("START",10,13)Serial line 7 connects to the LCD, and line 6 connects to the host PC. We send a "clear screen" signal to the LCD by writing byte value 254, and a "START" signal out to the host PC. The 10,13 on the end are carriage-return and linefeed.
main: pause 300 serout 7,N2400,(254,128,"A") serout 6,N2400,("A") readtemp12 3,w0 gosub print12 readtemp12 2,w0 serout 7,N2400,("B") serout 6,N2400,("B") gosub print12 serout 7,N2400,(254,192,"C") serout 6,N2400,("C") readtemp12 1,w0 gosub print12 readtemp12 0,w0 serout 7,N2400,("D") serout 6,N2400,("D") gosub print12 serout 6,N2400,(13,10) goto main
This is the main loop. We read the 4 temp sensors in turn by calling the builtin "readtemp12" command, and then write the data to the serial line (line 7) and also display it on the LCD (line 6) by calling print12. This loop runs about 3 times per second.
The LCD ends up displaying something like this:
A 21.12 B 21.06 C 22.25 D 22.62
print12: if w0 > 32767 then neg serout 7,N2400,(" ") serout 6,N2400,(" ") goto cvt neg: serout 7,N2400,("-") serout 6,N2400,("-") let w0 = 65535 - w0 let w0 = w0 + 1 cvt: let b1 = b1 * 16 let b13 = b0 / 16 let b1 = b1 + b13 if b1 > 9 then nopad serout 7,N2400,(" ") serout 6,N2400,(" ") nopad: serout 7,N2400,(#b1,".") serout 6,N2400,(#b1,".") let b0 = b0 % 16 branch b0,(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15)
This is a routine to print the temperature on the LCD (line 6) and also sends it to the host PC (line 7). Because the temp is read in steps of 0.065 degrees there are only 16 possible fractional values. I just work out which one we want and then jump to a print statement that prints it. This code also handles negative temperatures.
p0: serout 7,N2400,("00") serout 6,N2400,("00") goto px p1: serout 7,N2400,("06") serout 6,N2400,("06") goto px p2: serout 7,N2400,("12") serout 6,N2400,("12") goto px p3: serout 7,N2400,("19") serout 6,N2400,("19") goto px p4: serout 7,N2400,("25") serout 6,N2400,("25") goto px p5: serout 7,N2400,("31") serout 6,N2400,("31") goto px p6: serout 7,N2400,("37") serout 6,N2400,("37") goto px p7: serout 7,N2400,("44") serout 6,N2400,("44") goto px p8: serout 7,N2400,("50") serout 6,N2400,("50") goto px p9: serout 7,N2400,("56") serout 6,N2400,("56") goto px p10: serout 7,N2400,("62") serout 6,N2400,("62") goto px p11: serout 7,N2400,("69") serout 6,N2400,("69") goto px p12: serout 7,N2400,("75") serout 6,N2400,("75") goto px p13: serout 7,N2400,("81") serout 6,N2400,("81") goto px p14: serout 7,N2400,("87") serout 6,N2400,("87") goto px p15: serout 7,N2400,("94") serout 6,N2400,("94") px: serout 7,N2400,(" ") serout 6,N2400,(" ") return