Final Button Code


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    May 2008
    Location
    Texas
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    I was refering to my button command. Should I start the port high and pull it low or start low and pull high based on this bit of code?

    Code:
    delay = 0
        Button Temp_Up, 0, 255, 0, delay, 0, Up_Loop
        button Temp_Down, 0, 255, 0, delay, 0, Down_Loop
    Up_Loop:
        If Temp_Up = 0 Then
            Setpoint = Setpoint + 1
            lcdout $fe, 1, "Setpoint = ", Setpoint
            Pause 1000
        Else
            Goto Start_Convert
        Endif
        Goto Up_Loop
    Down_Loop:                
        If Temp_Down = 0 Then
            Setpoint = Setpoint - 1
            lcdout $fe, 1, "Setpoint = ", Setpoint
            Pause 1000
        Else
            Goto Start_Convert
        Endif
        Goto Down_Loop

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Well, I was referring to your schematic. The way you code depends on the way you wired it up...

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by WarPony View Post
    I was refering to my button command. Should I start the port high and pull it low or start low and pull high based on this bit of code?

    Code:
    delay = 0
        Button Temp_Up, 0, 255, 0, delay, 0, Up_Loop
        button Temp_Down, 0, 255, 0, delay, 0, Down_Loop
    Up_Loop:
        If Temp_Up = 0 Then
            Setpoint = Setpoint + 1
            lcdout $fe, 1, "Setpoint = ", Setpoint
            Pause 1000
        Else
            Goto Start_Convert
        Endif
        Goto Up_Loop
    Down_Loop:                
        If Temp_Down = 0 Then
            Setpoint = Setpoint - 1
            lcdout $fe, 1, "Setpoint = ", Setpoint
            Pause 1000
        Else
            Goto Start_Convert
        Endif
        Goto Down_Loop
    Hello WarPony,
    You have written your code, If X=0 true, then do something, so you would pull the ports up to supply + with a resistor or WPUs, and the if / then loop would be true when the switch grounds it. Did I answer the right question or are you asking which way is better ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    May 2008
    Location
    Texas
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    I am getting all twisted up with the button code and loop. I havent added my switches to my circuit yet. I just want 1 to be added to or subtracted from my setpoint when one of the two switches is pressed.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by WarPony View Post
    I am getting all twisted up with the button code and loop. I havent added my switches to my circuit yet. I just want 1 to be added to or subtracted from my setpoint when one of the two switches is pressed.
    When we say pullup/pulldown, generally we're referring to the state of the pin when the switch isn't being actuated.
    Usually, a person will put a resistor (4.7K-10K, whatever), from the pin to Vdd, and the switch is wired in to ground that pin. Since the resistor runs from the pin to Vdd, the pin is high with the switch open, low with the switch closed.
    So, if you want to use the button command, that's great...but why not play around with it without using the button command so you can understand it's inner working a bit better.
    i.e.
    loop:
    if switch1 = 0 then setpoint = setpoint - 1
    if switch2 = 0 then setpoint = setpoint + 1
    ......blah blah blah....
    Yes, a loop like this will likely execute entirely too fast, and will most likely cause the setpoint value to 'wrap around'...but that's what 'pause' can be used for.

  6. #6
    Join Date
    May 2008
    Location
    Texas
    Posts
    16


    Did you find this post helpful? Yes | No

    Talking aha

    Why couldnt the pbp manual explain it like that?

    Thanks skimask

    I will finish my circuit and let you know how it went.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink Some ideas to pick up ...

    Hi WP

    I played a bit with the code these two days ...

    that gives the following ...

    Code:
    '*****************************************************************************
    '*****************************************************************************
    ' Thermostat F84 test sur EasyPic5
    ' Thermostat 16F877a + DS 18B20
    '*****************************************************************************
    '*****************************************************************************
    
    '*****************************************************************************
    '*****************************************************************************
    
    @ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _BODEN_ON & _LVP_OFF & _CP_OFF 
    
    '*****************************************************************************
    '*                  LCD Defines for EasyPic5                                 *
    '*****************************************************************************
      
        DEFINE LCD_DREG PORTB               ' I/O port where LCD is connected
        DEFINE LCD_DBIT 0
        DEFINE LCD_RSREG PORTB
        DEFINE LCD_RSBIT 4                  ' Register select pin
        DEFINE LCD_EREG PORTB
        DEFINE LCD_EBIT 5                   ' Enable pin
        DEFINE LCD_BITS 4                   ' 4-bit data bus
        DEFINE LCD_LINES 2                  ' LCD has 2 character lines
     
        DEFINE OSC 8
        DEFINE BUTTON_PAUSE 100
        
    'Define	    LCD_DREG	PORTD
    'Define	    LCD_DBIT	4
    'Define	    LCD_RSREG	PORTE
    'Define	    LCD_RSBIT	0
    'Define	    LCD_EREG	PORTE
    'Define	    LCD_EBIT	1
    
    
    Temp_Down     	VAR PortA.0    	 'Temp down button input port
    Temp_Up      	VAR PortA.1    	 'Temp up button input port
    G_LED         	VAR PortC.0   	  ' Green LED output cold needed
    Relay_Cold		VAR PORTC.1
    R_LED        	VAR PortC.6   	  ' Red LED output  hot needed
    Relay_hot		VAR PortC.7
    DQ           	VAR PortE.2   	  ' One-wire Data-Pin "DQ" on PortE.2
    
    
    'Temp_Down    	VAR PortB.3    	 'Temp down button input port
    'Temp_Up       	VAR PortB.2    	 'Temp up button input port
    'R_LED        	VAR PortB.0   	  ' Red LED output
    'G_LED        	VAR PortB.1   	  ' Green LED output
    'DQ            	VAR PortC.0   	  ' One-wire Data-Pin "DQ" on PortC.0
    '
    
    
    Busy          	VAR BIT        	 ' Busy Status-Bit
    
    delay         	VAR BYTE       	 'Button working variable
    Dummy         	VAR BYTE       	 ' Dummy for Div32
    Loscale			VAR BYTE
    Hiscale			VAR BYTE
    Decal			VAR BYTE
    
    Tempeff			VAR WORD
    Setpoint      	VAR WORD
    R_Temp        	VAR WORD        	' RAW Temperature readings
    TempC         	VAR WORD        	' Temp in deg C
    Float         	VAR WORD       	' Holds remainder for + temp C display
    
    ColdStart		VAR BIT
    Sign			VAR BIT
    
    Cold_Bit      	VAR R_Temp.Bit11	' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    
     
    ADCON1 = 7			          	' Set PORTD and PORTE to digital
    CMCON  = 7						' Comparators OFF
    
    PORTA = %00000011
    PORTB = 0
    PORTC = 0
    PORTD = 0
    PORTE = 0
    
    TRISA = %00000011
    TRISB = 0
    TRISC = 0
    TRISD = 0
    TRISE = %00000010
    
    
    DS18B20_9bit  CON %00011111   	' 93.75ms, 0.5°C
    DS18B20_10bit CON %00111111   	' 187.5ms, 0.25°C  <-- My favorite
    DS18B20_11bit CON %01011111   	' 375ms,   0.125°C
    DS18B20_12bit CON %01111111   	' 750ms,   0.0625°C  (default)
    
       
    Setpoint = 200                                  'Default setpoint on start up
    ColdStart = 1
    
        LCDOut  $FE,1                                     'Clear LCD     
        PAUSE 750
        
    'Chargement motifs en CGRAM
    
      LCDOUT  $FE,$40,$00,$00,$00,$00,$00,$04,$04,$04  ' Cust Char #0
      LCDOUT  $FE,$48,$00,$00,$00,$04,$04,$04,$04,$04  ' Cust Char #1
      LCDOUT  $FE,$50,$04,$04,$04,$04,$04,$04,$04,$04  ' Cust Char #2
      LCDOUT  $FE,$58,$04,$04,$0E,$0E,$0E,$1F,$1B,$11  ' Cust Char #3
      LCDOUT  $FE,$60,$11,$1B,$1F,$0E,$0E,$0E,$04,$04  ' Cust Char #4
    
      
        OWOUT DQ, 1, [$CC, $4E, 0, 0, DS18B20_10bit]    'Skip ROM search and write 10bit 														resolution to scratch pad    
        
    Start_Convert:
    
        OWOUT   DQ, 1, [$CC, $44]                       ' Skip ROM search & do temp conversion
        
        
        delay = 0
        Button Temp_Up,   0, 255, 0, delay, 1, Up_Loop
        button Temp_Down, 0, 255, 0, delay, 1, Down_Loop  
        
    '*****************************************************************************
    ' Check for still busy converting ( ~ 4500 fois ... )
    '*****************************************************************************
    
    waitloop: 
    
    		INPUT DQ
    		If NOT DQ Then waitloop
    		
        
        OWOUT   DQ, 1, [$CC, $BE ]                       ' Skip ROM search & read scratchpad 														memory
        OWIN    DQ, 2, [R_Temp.Lowbyte, R_Temp.Highbyte]' Read two bytes / end comms
          
    Convert_Temp:                                       
    
    	IF R_Temp.15 THEN
    	
    		 R_Temp = ~R_Temp + 1
    		 Sign = 1									'Signe -
    		 
    	ELSE			                       
    	
       		 Sign = 0									'Sign  = "+"
       		 
       	ENDIF
       	
    												
        TempC =  ( R_Temp & $7FF ) >> 4   				' Partie Entière
                      
        Float = ((R_Temp.Lowbyte & $0F ) * 25 )>> 2     ' Partie décimale 100èmes
        
        Tempeff = TempC*10 + Float/10					'Préparation 1/10 degrés
    
    	gosub Aff
           
     GOTO    Start_Convert
        
                                                                     
    Up_Loop:
    
        If Temp_Up = 0 Then
            Setpoint = Setpoint + 5
            lcdout $fe, $C0, "Setpoint = ", DEC2 (Setpoint/10),".",DEC1(SetPoint // 10)," "
            Gosub Show
            Pause 500
        Else
            Goto Start_Convert
        Endif
        Goto Up_Loop
        
        
    Down_Loop:
                    
        If Temp_Down = 0 Then
            Setpoint = Setpoint - 5
            lcdout $fe, $C0, "Setpoint = ",  DEC2 (Setpoint/10),".",DEC1(SetPoint // 10)," "
            Pause 500
            Gosub Show
        Else
            Goto Start_Convert
        Endif
        Goto Down_Loop    
       
    
    
    '*****************************************************************************
    '*****************************************************************************
    '                              AFFICHAGE
    '*****************************************************************************
    '*****************************************************************************
    
    'Motifs
    
    'Small bar     LCDOUT  $FE,$40,$00,$00,$00,$00,$00,$04,$04,$04  ' Cust Char #0
    'Mid bar       LCDOUT  $FE,$48,$00,$00,$00,$04,$04,$04,$04,$04  ' Cust Char #1
    'Big bar       LCDOUT  $FE,$50,$04,$04,$04,$04,$04,$04,$04,$04  ' Cust Char #2
    'Arrow 		   LCDOUT  $FE,$58,$04,$04,$0E,$0E,$0E,$1F,$1B,$11  ' Cust Char #3
    'Inv Arrow     LCDOUT  $FE,$60,$11,$1B,$1F,$0E,$0E,$0E,$04,$04  ' Cust Char #4
    
    '*****************************************************************************
    Aff:'Affichage temp
    '*****************************************************************************
    
    'préparation chiffre : sign = 1 = valeur négative
    
    Loscale = ( TempC /5 + Sign ) * 5  + Sign << 7
    Decal = 0
    Decal	= ( TempC // 5 ) << 1 
    
    IF Sign THEN
    
    	IF Float > 25 AND Float <= 75 then Decal = Decal - 1
    	IF Float > 75 Then Decal = Decal - 2
    	
    ELSE
    	
    	IF Float > 25 AND Float <= 75 then Decal = Decal + 1
    	IF Float > 75 Then Decal = Decal + 2
    	
    ENDIF
    
    Hiscale = (TempC /5 + ( Sign ^1)) * 5 + Sign << 7
    
    'Impression valeurs 1ère ligne
    
      LCDOUT	$FE, $81 ,SDEC2 Loscale,178,"C"," ",SDEC TempC,".",dec2 Float,$FE,$80 + 12,SDEC2 Hiscale,178,"C"
      
    'Impression échelle 2ème ligne
    
     LCDOUT	$FE,$C0,$01,$00,$02,$00,$01,$00,$01,$00,$01,$00,$01,$00,$02,$00,$01,$00
      
    'Impression index
    
     IF Tempeff < Setpoint THEN
     
    	LCDOUT	$FE, $C2 + Decal,$03				'Index Chauffage
    	
     ELSE
     
    	LCDOUT	$FE, $C2 + Decal,$04				' Index Refroidissement
    	
    ENDIF
    
    Show:
    
     IF Tempeff < Setpoint THEN
       
    	high R_LED                                   ' Turn on Red LED C0  and turn off Green 														LED C6
    	low G_LED
    	
    	IF Coldstart THEN Relay_hot = 1 : Relay_cold = 0 : Coldstart = 0
                           
     ELSE
    	
        High G_LED                                   ' Turn on Green LED C6 and turn off Red 														LED C0
        low R_LED
        
        IF Coldstart THEN Relay_hot = 0 : Relay_cold = 1 : coldstart = 0
                               
     ENDIF
      
    '*****************************************************************************
    Drive:
    '*****************************************************************************
     	
    	IF Tempeff < (Setpoint - 5) AND Relay_hot = 0 THEN Relay_hot = 1 : Relay_cold = 0  'C7
    	  
    	IF Tempeff > (Setpoint + 5) AND Relay_cold = 0 THEN Relay_hot = 0 : Relay_cold = 1	'C1
    	  
    RETURN
    
        END
    Some little improvements to work further on for the drive section ...

    but the idea is here ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    May 2008
    Location
    Texas
    Posts
    16


    Did you find this post helpful? Yes | No

    Thumbs up

    meersee buukuu alain (bad french accent)

    gonna grab some of that code you worked up...this is for residential so the temps I am working with will be from about 60 degrees F to 80 degrees F for setpoints and 20 degrees F to 120 degrees F for the outside reference temp.

    thanks again
    Bryan

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by WarPony View Post
    Why couldnt the pbp manual explain it like that?
    Because PicBasicPro isn't basic digital electronics.
    You get basic digital electronics from a book called 'Basic Digital Electronics'.

  10. #10
    Join Date
    May 2008
    Location
    Texas
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Read that book....didnt hold my attention...maybe thats my problem...haha

Similar Threads

  1. TSA5512/5511 code for PIC16F877/84
    By Marin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th August 2013, 06:16
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43

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