Wrote program for LM34 and ADC need to display on LCD
cmc074
Posts: 4
' {$STAMP BS2}
' {$PBASIC 2.5}
DigDataIn VAR Bit ' Digital input data
ADC_DataIn VAR Byte ' Analog to Digital Converter data
ADC_CS PIN 15 ' ADC Chip Select pin
ADC_Clk PIN 14 ' ADC Clock pin
ADC_Dout PIN 13 ' ADC Data output
'
[ Initialize ]
PAUSE 1000 ' Allow connection to stabilize
DEBUG CLS 'Start display.
'
[ Main Routine ]
DO
GOSUB ReadData
GOSUB Display_Data
PAUSE 500
LOOP
'
[ Subroutines ]
ReadData: ' Read ADC 0831
LOW ADC_CS ' Enable chip
SHIFTIN ADC_Dout, ADC_Clk, MSBPOST,[ADC_DataIn\9] ' Clock in data from ADC
HIGH ADC_CS ' Disable ADC
RETURN
Display_Data:
DEBUG "INC:",DEC ADC_DataIn, CR
DEBUG "Temperature:", DEC (ADC_DataIn *196)/100, ".", DEC2 ABS(ADC_DataIn *196)," F", CR
RETURN
'
LCD Display
SEROUT 11, 84, [22, 12, 17]
PAUSE 5
SEROUT 11, 84, ["INC:"]: DEC ADC_DataIn, CR
SEROUT 11, 84, [13], ["Temperature"], DEC (ADC_DataIn *196/100, ".", DEC2 ABS_DataIn *196), " F" CR
RETURN
I have the debug on there still for reference right before the LCD display part, can anyone help me with the serout commands to get the lcd to display the temp
Thanks to any and all help!!
' {$PBASIC 2.5}
DigDataIn VAR Bit ' Digital input data
ADC_DataIn VAR Byte ' Analog to Digital Converter data
ADC_CS PIN 15 ' ADC Chip Select pin
ADC_Clk PIN 14 ' ADC Clock pin
ADC_Dout PIN 13 ' ADC Data output
'
[ Initialize ]
PAUSE 1000 ' Allow connection to stabilize
DEBUG CLS 'Start display.
'
[ Main Routine ]
DO
GOSUB ReadData
GOSUB Display_Data
PAUSE 500
LOOP
'
[ Subroutines ]
ReadData: ' Read ADC 0831
LOW ADC_CS ' Enable chip
SHIFTIN ADC_Dout, ADC_Clk, MSBPOST,[ADC_DataIn\9] ' Clock in data from ADC
HIGH ADC_CS ' Disable ADC
RETURN
Display_Data:
DEBUG "INC:",DEC ADC_DataIn, CR
DEBUG "Temperature:", DEC (ADC_DataIn *196)/100, ".", DEC2 ABS(ADC_DataIn *196)," F", CR
RETURN
'
LCD Display
SEROUT 11, 84, [22, 12, 17]
PAUSE 5
SEROUT 11, 84, ["INC:"]: DEC ADC_DataIn, CR
SEROUT 11, 84, [13], ["Temperature"], DEC (ADC_DataIn *196/100, ".", DEC2 ABS_DataIn *196), " F" CR
RETURN
I have the debug on there still for reference right before the LCD display part, can anyone help me with the serout commands to get the lcd to display the temp
Thanks to any and all help!!
Comments
If you're using the Parallax LCD Serial Display, you'll need to add a few constants:
Be sure to assign a pin to your LCD's dataline (any pin, I just happened to use 14 here):
I always add an LCD initialization section before the Main program:
And then replace your DEBUGs with your SEROUTS in the following format:
SEROUT LCD, LcdBaud, ["Initializing "]
or, to display variables:
SEROUT LCD, Baud, [HEX2 month, "/", HEX2 date, "/", HEX2 year," ", HEX2 hrs, ":", HEX2 mins]
Of course, replace the HEX2 formatters with the formatters of your choice and the proper variable.
Play with it - you'll figure it out.
Be sure your BAUD RATE IS SET PROPERLY! It varies by stamp. If you're sending regular ASCII text and you get odd japanese-looking characters - your baud rate is wrong. I'm running a BS2sx and sending to the LCD at 19.2 for the baud, which is a CON of 110.
Let me know if that helps.
Dave
now my problem is a little more difficult.
I am running a thermoelectric cooling unit with the program and in my program i want the tec to power off whenever my current temp is below my set temp (right now set at 57 degrees)
it works whenever the temp is above my set temp, i.e. the TEC powers on, but when the temp is below my set 57 when it is supposed to be turned off it goes on and off repeatedly
below this is the part ofmy program that pertains to it, can someone tweek it to fix my problem
'
[ Open ]
Open:
IF IN6=0 THEN DEBUG CRSRXY,0,0, "Lid Status: Closed"
PAUSE 500
RETURN
'
[ Close ]
Close:
IF IN6=1 THEN DEBUG CRSRXY, 0,0, "Lid Status: Open "
PAUSE 500
RETURN
'
[ TEC ]
TEC:
IF IN6=0 THEN HIGH 1
IF IN6=1 THEN LOW 1
RETURN
'
[ TEC TEMP ]
TEC_TEMP:
IF (ADC_DataIn *196)/100 > 57 THEN HIGH 1
RETURN
'
[TEC TEMP 2]
TEC_TEMP2:
IF (ADC_DataIn *196)/100 < 57 THEN LOW 1
RETURN
IF IN6=1 THEN LOW 1
RETURN
IF (ADC_DataIn *196)/100 > 57 THEN HIGH 1
RETURN
'
[TEC TEMP 2]
TEC_TEMP2:
IF (ADC_DataIn *196)/100 < 57 THEN LOW 1
RETURN
What you have above dose not work right very often try what I have below and see if this works better
IF (ADC_DataIn *196)/100 > 57 THEN
HIGH 1
ELSE
LOW1
ENDIF
RETURN
IF IN6=0 THEN
HIGH 1
ELSE
LOW 1
ENDIF
RETURN
When it is supposed to be turned off it goes on and off repeatedly below this is the part of my program that pertains to it, can someone tweek it to fix my problem
You might have to put this in a DO.......... LOOP