Displaying temperature Setpoints


Closed Thread
Results 1 to 40 of 59

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    47

    Red face Displaying temperature Setpoints

    Hi Guys. I'm pretty new to picbasic pro. I've tried to create a temperature control system but having endless dead-ends. I've tried my best with the code and so far I managed to get the program to display the temperature. Adding in buttons though is what's giving me problems. Below is a copy of my program. Please help me somebody.


    /Define LCD_DREG PORTB
    Define LCD_DBIT 0
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 5
    Define LCD_EREG PORTB
    Define LCD_EBIT 4
    dEFINE LCD_BITS 4
    DEFINE LCD_LINES 2

    adval var word ' Create adval to store result
    tempc var word ' Create tempc to store result
    Setpoint var word
    sethigh var byte
    setlow var byte

    Temp_Up var PORTC.0
    Temp_Down var PORTC.1
    High_sp var PORTC.2
    Low_sp VAR PORTC.3
    Main_disp VAR PORTC.4


    TRISC = %11111111 ' Set PORTC to all input
    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %11000001 ' Configure and turn on A/D Module
    Pause 100 ' Wait 0.1 second

    START:
    if High_sp = 1 then gosub Set_High
    IF Low_sp = 1 then gosub Set_Low
    IF Main_disp = 1 then gosub Main
    pause 10 '????????????? debounce how?

    Keypress:
    if Temp_Up = 1 then gosub Up_Loop
    if Temp_Down = 1 then gosub Down_Loop


    GOTO START

    Main: ADCON0.2 = 1 ' Start Conversion

    AGAIN: Pause 1

    If ADCON0.2 = 1 Then AGAIN ' Wait for low on bit-2 of ADCON0, conversion finished

    adval.highbyte = ADRESH ' Move HIGH byte of result to adval
    adval.lowbyte = ADRESL ' Move LOW byte of result to adval

    Lcdout $fe, 1 ' Clear screen
    tempc=50*adval ' Conversion to Degrees
    tempc=tempc/100
    Lcdout "Temp = ",DEC tempc,$DF,"C" ' Display the value of temp

    if Tempc > 100 then
    lcdout "Out of range!"
    endif
    if Tempc < 0 then
    lcdout "Out of Range!"
    endif
    Pause 1000 ' Wait 1 second

    Goto Main ' Do it forever

    Up_Loop:
    If Temp_Up = 1 Then
    Setpoint = Setpoint + 1
    if Setpoint>100 then SetPoint=0
    lcdout $fe, 1, "Setpoint = ", Setpoint
    Pause 10
    Else
    Goto Keypress
    Endif
    Goto Up_Loop

    Down_Loop:
    If Temp_Down = 1 Then
    Setpoint = Setpoint - 1
    if Setpoint>0 then SetPoint=100
    lcdout $fe, 1, "Setpoint = ", Setpoint
    Pause 10
    Else
    Goto Keypress
    Endif
    Goto Down_Loop

    Set_High: '?????????? Im trying to store the value
    gosub Keypress '?????????? from the Temp_Up/Temp_Down.
    write sethigh, Keypress '??????????

    Set_Low: '?????????? Im trying to store the value
    gosub Keypress '?????????? from the Temp_Up/Temp_Down.
    write setlow, Keypress '??????????

    end
    Last edited by Kalind; - 15th October 2008 at 17:08.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Looking good.

    Now go back here http://www.picbasic.co.uk/forum/showthread.php?t=9741
    and re-read how to store and read the value.

    If there is a part you do not understand ask a specific question, it will make it easier to help you.
    Dave
    Always wear safety glasses while programming.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Looking good.
    ????????????????????????????????????????????????

    Code:
    if Tempc < 0 then
    lcdout "Out of Range!"
    endif
    
    That looks REAL good! for one thing...

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    ????????????????????????????????????????????????

    Code:
    if Tempc < 0 then
    lcdout "Out of Range!"
    endif
    
    That looks REAL good! for one thing...
    Well maybe I should have said looking better? At least the OP has code that looks like he wrote.
    Dave
    Always wear safety glasses while programming.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    At least the OP has code that looks like he wrote.
    Now, I'll admit, sometimes there's only one way to do something, and sometimes there are hundreds of ways of doing something...but...
    http://www.picbasic.co.uk/forum/show...ight=down_loop
    See anything in there?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Now, I'll admit, sometimes there's only one way to do something, and sometimes there are hundreds of ways of doing something...but...
    http://www.picbasic.co.uk/forum/show...ight=down_loop
    See anything in there?
    There goes the benefit of doubt.
    Dave
    Always wear safety glasses while programming.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Don't know what PIC you're using...so don't really know if that PIC has onchip eeprom or not...or what...
    Code:
    Define	LCD_DREG	PORTB
    Define	LCD_DBIT	0
    Define	LCD_RSREG	PORTB
    Define	LCD_RSBIT	5
    Define	LCD_EREG	PORTB
    Define	LCD_EBIT	4
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    mode var byte : keyin var byte : adval var word : tempc var word
    highpt var byte : lowpt var byte : up var portc.0 : down var portc.1
    sethighp var portc.2 : setlowp var portc.3 : maindisp var portc.4
    trisc=$ff : trisa=$ff : adcon1=$82 : adcon0=$c1 : pause 100
    mode = 1 : lcdout $fe , 1 : goto main
    getkey:  pause 50 : keyin = portc : return
    gettemp:  adcon0.2=1 : pause 1
    checkdone: if adcon0.2=1 then checkdone
    adval.highbyte=adresh : adval.lowbyte=adresl : tempc=(50*adval)/100 : return
    main:  gosub gettemp : gosub getkey
    if maindisp = 1 then
         write 0 , sethighp : pause 10 : write 1 , sethighp : mode = 1
    endif
    if sethighp = 1 then mode = 2
    if setlowp = 1 then mode = 3
    select case mode
    case 1
    lcdout $fe , $80 , "Temp = ", DEC3 tempc , $DF , "C"
    case 2
    lcdout $fe , $80 , "High Pt=" , $fe , $c0 , highpt
    if up = 1 then highpt = highpt + 1
    if down = 1 then highpt = highpt - 1
    case 3
    lcdout $fe , $80 , "Low Pt=" , $fe , $c0 , lowpt
    if up = 1 then lowpt = lowpt + 1
    if down = 1 then lowpt = lowpt - 1
    end select
    goto main
    If that doesn't give you some ideas...nothing will...
    But remember, I SUCK! DUDE!

    P.S. Your program has been COLONized! In the process of De-COLONizing the code above and figuring out what goes where, you might learn something...
    Last edited by skimask; - 15th October 2008 at 17:38.

Similar Threads

  1. Write Onewire data toa I2C memory / read ASCI
    By Eugeniu in forum mel PIC BASIC Pro
    Replies: 67
    Last Post: - 16th November 2008, 19:19
  2. Displaying temperature using a -40 to 185F??
    By jblackann in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th January 2008, 18:45
  3. Conversion problem
    By eva in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th March 2007, 18:21
  4. Help for decimal conversion
    By eva in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th March 2007, 18:20
  5. Serout "onewire.bas"
    By puru in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th July 2005, 00:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts