Shop OBEX P1 Docs P2 Docs Learn Events
Wrote program for LM34 and ADC need to display on LCD — Parallax Forums

Wrote program for LM34 and ADC need to display on LCD

cmc074cmc074 Posts: 4
edited 2011-11-07 14:41 in BASIC Stamp
' {$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!!

Comments

  • xanatosxanatos Posts: 1,120
    edited 2011-11-04 17:29
    Hi,

    If you're using the Parallax LCD Serial Display, you'll need to add a few constants:
    LcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)      ' $FE $51 on NHD
    LcdBLon         CON     $11             ' backlight on                       ' $FE $53 [brightness]  1 byte, val 0 to 8.
    LcdBLoff        CON     $12             ' backlight off                      ' $FE $52 [contrast]  1 byte, val 1 to 50.
    LcdOff          CON     $15             ' LCD off                            ' $FE $42
    LcdOn1          CON     $16             ' LCD on; cursor off, blink off      ' $FE $46
    LcdOn2          CON     $17             ' LCD on; cursor off, blink on
    LcdOn3          CON     $18             ' LCD on; cursor on, blink off
    LcdOn4          CON     $19             ' LCD on; cursor on, blink on
    LcdLine1        CON     $80             ' move to line 1, column 0
    LcdLine2        CON     $94             ' move to line 2, column 0
    
    

    Be sure to assign a pin to your LCD's dataline (any pin, I just happened to use 14 here):
    LCD             PIN     14               ' Parallax Serial LCD Display  
    

    I always add an LCD initialization section before the Main program:
    Reset_LCD:
      HIGH LCD                              ' setup serial output pin
      PAUSE 300                             ' allow LCD to initialize
      SEROUT LCD, LcdBaud, [LcdBLon, LcdOn1, LcdCls]  'LcdBLoff/LcdBLon
      PAUSE 250
      SEROUT LCD, LcdBaud, [LcdCls]  'LcdBLoff/LcdBLon
      PAUSE 20
    
    


    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.
    LcdBaud         CON     110             ' LCD Baud
    

    Let me know if that helps.

    Dave
  • cmc074cmc074 Posts: 4
    edited 2011-11-05 12:13
    its does help thanks!

    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
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2011-11-07 14:41
    IF IN6=0 THEN HIGH 1
    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
Sign In or Register to comment.