Help on routine-Work with a button


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    Thanks you for all the reaplys, I will analyse all of them...in the mean time, if anyone have more options, please post.!!

    Thanks

  2. #2
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    Hi Again;

    I made this code, however is not working like i wont, only sometimes, can somebody tell me why;
    Code:
    '*********************************************************************
    '                         INCLUDE's e FUSES
    ' ====================================================================
    DEFINE OSC 4
    
    '                     CONFIGURAÇÃO DAS INTERRUPÇÕES
    ' ====================================================================
     
    '                               VARIÁVEIS
    ' ====================================================================
    VAR1 var byte
    VAR2 var byte
    I    var byte
    var1=0
    var2=0
    
    '                        REGISTOS PINOUT 1 = IN; 0 = OUT
    ' ====================================================================
              '76543210
     TRISA  = %00000001 
     TRISB  = %00000000 
     TRISC  = %10000000 
     TRISD  = %00000000 
     TRISE  = %00000000
     ADCON1 = 7
    '                              NOMES PINOUT
    ' ====================================================================
     LED1  VAR PORTC.0
     LED2  var PORTD.0
     Botao var PORTA.0
    
    '                              DEFINIÇÕES
    ' ====================================================================
    
       DEFINE LCD_DREG PORTB       ' LCD Data bits on PORTB
       DEFINE LCD_DBIT 0           ' PORTB starting address
       DEFINE LCD_RSREG PORTB      ' LCD RS bit on PORTB
       DEFINE LCD_RSBIT 4          ' LCD RS bit address
       DEFINE LCD_EREG PORTB       ' LCD E bit on PORTB
       DEFINE LCD_EBIT 5           ' LCD E bit address
       DEFINE LCD_BITS 4           ' LCD in 4-bit mode
       DEFINE LCD_LINES 2          ' LCD has 2 rows
       DEFINE LCD_COMMANDUS 2000   ' Set command delay time in us
       DEFINE LCD_DATAUS 50        ' Set data delay time in us
    '                             INICIO PROGRAMA
    ' ====================================================================
     low led1
     low lED2
     LCDOUT $fe, 1
     lcdout "  Teste     Botoes  "
     lcdout $FE,$C0," Por Hugo  Oliveira "
     
    Main:
        if botao = 1 then  'Button presse
            pause 80      'debounce for 80ms
            If Botao = 0 then BotaoClick 'Button Unpressed -> Only Click 
        else
            if Botao = 1 then  'Button Still pressed
                for i = 1 to 6
                    pause 486
                    If Botao = 0 then Main 'Test if was unpressed in the mean while
                next
            If Botao = 1 then BotaoClickHold 'IF Still pressed after 3s -> Click&Hold
            endif
        endif
    GOTO MAIN
    '                          SUB-ROTINAS
    ' ====================================================================
    BotaoClick:
        if var1 = 0 then
            high led1
            var1 = 1
            pause 500
        else
            low led1
            var1 = 0
            pause 500
        endif
    Goto Main
    
    BotaoClickHold:
        if var2 = 0 then
            high led2
            var2 = 1
            pause 500
        else
            low led2
            var2 = 0
            pause 500
        endif
    Goto Main
    END
    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gadelhas View Post
    Hi Again;

    I made this code, however is not working like i wont, only sometimes, can somebody tell me why;

    Thanks

    Hi, Hugo

    Code:
    While Button pressed
      Wait a bit
     
     
      Increment a counter 
    WEND
     
    ...
     
     
    Is Counter limit reached ?
    I do not see those two actions in your program ...

    Alain

    PS for Administrators ... There is a bug with high size characters: suppress the blank lines inserted after " wait a bit " and it will appear ...
    Last edited by Acetronics2; - 18th August 2010 at 10:17.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  4. #4
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    Hi, thanks Acetronics;

    Hi made thsi way, and its working, however later, i will make more tests.
    Code:
     '                         INCLUDE's e FUSES
    ' ====================================================================
    DEFINE OSC 4
    
    '                     CONFIGURAÇÃO DAS INTERRUPÇÕES
    ' ====================================================================
     
    '                               VARIÁVEIS
    ' ====================================================================
    VAR1 var byte
    VAR2 var byte
    I    var byte
    counter var byte
    
    
    '                        REGISTOS PINOUT 1 = IN; 0 = OUT
    ' ====================================================================
              '76543210
     TRISA  = %00000001 
     TRISB  = %00000000 
     TRISC  = %10000000 
     TRISD  = %00000000 
     TRISE  = %00000000
     ADCON1 = 7
    '                              NOMES PINOUT
    ' ====================================================================
     LED1  VAR PORTC.0
     LED2  var PORTD.0
     Botao var PORTA.0
    
    '                              DEFINIÇÕES
    ' ====================================================================
    
       DEFINE LCD_DREG PORTB       ' LCD Data bits on PORTB
       DEFINE LCD_DBIT 0           ' PORTB starting address
       DEFINE LCD_RSREG PORTB      ' LCD RS bit on PORTB
       DEFINE LCD_RSBIT 4          ' LCD RS bit address
       DEFINE LCD_EREG PORTB       ' LCD E bit on PORTB
       DEFINE LCD_EBIT 5           ' LCD E bit address
       DEFINE LCD_BITS 4           ' LCD in 4-bit mode
       DEFINE LCD_LINES 2          ' LCD has 2 rows
       DEFINE LCD_COMMANDUS 2000   ' Set command delay time in us
       DEFINE LCD_DATAUS 50        ' Set data delay time in us
    '                             INICIO PROGRAMA
    ' ====================================================================
     low led1
     low lED2
     LCDOUT $fe, 1
     lcdout "  Teste     Botoes  "
     lcdout $FE,$C0," Por Hugo  Oliveira "
     
    Main:
      while botao = 1
          pause 100
          counter = counter + 1
      Wend
    
        if counter >= 30 then  BotaoClickHold
        if counter>0 and counter<=5  then  BotaoClick
    counter=0
    GOTO MAIN
    '                          SUB-ROTINAS
    ' ====================================================================
    BotaoClick:
    counter = 0
        if var1 = 0 then
            high led1
            var1 = 1
            pause 500
        else
            low led1
            var1 = 0
            pause 500
        endif
    Goto Main
    
    BotaoClickHold:
    counter = 0
        if var2 = 0 then
            high led2
            var2 = 1
            pause 500
        else
            low led2
            var2 = 0
            pause 500
        endif
    Goto Main
    END
    Thanks Again.

  5. #5
    Join Date
    Aug 2008
    Location
    Portugal
    Posts
    240


    Did you find this post helpful? Yes | No

    Default

    Hi;

    It's Working just like the way i want, just made this change in the Main loop, from the code above;

    Code:
     '                         INCLUDE's e FUSES
    ' ====================================================================
    DEFINE OSC 4
    
    '                     CONFIGURAÇÃO DAS INTERRUPÇÕES
    ' ====================================================================
     
    '                               VARIÁVEIS
    ' ====================================================================
    VAR1 var byte
    VAR2 var byte
    I    var byte
    counter var byte
    
    
    '                        REGISTOS PINOUT 1 = IN; 0 = OUT
    ' ====================================================================
              '76543210
     TRISA  = %00000001 
     TRISB  = %00000000 
     TRISC  = %10000000 
     TRISD  = %00000000 
     TRISE  = %00000000
     ADCON1 = 7
    '                              NOMES PINOUT
    ' ====================================================================
     LED1  VAR PORTC.0
     LED2  var PORTD.0
     Botao var PORTA.0
    
    '                              DEFINIÇÕES
    ' ====================================================================
    
       DEFINE LCD_DREG PORTB       ' LCD Data bits on PORTB
       DEFINE LCD_DBIT 0           ' PORTB starting address
       DEFINE LCD_RSREG PORTB      ' LCD RS bit on PORTB
       DEFINE LCD_RSBIT 4          ' LCD RS bit address
       DEFINE LCD_EREG PORTB       ' LCD E bit on PORTB
       DEFINE LCD_EBIT 5           ' LCD E bit address
       DEFINE LCD_BITS 4           ' LCD in 4-bit mode
       DEFINE LCD_LINES 2          ' LCD has 2 rows
       DEFINE LCD_COMMANDUS 2000   ' Set command delay time in us
       DEFINE LCD_DATAUS 50        ' Set data delay time in us
    '                             INICIO PROGRAMA
    ' ====================================================================
     low led1
     low lED2
     LCDOUT $fe, 1
     lcdout "  Teste     Botoes  "
     lcdout $FE,$C0," Por Hugo  Oliveira "
     
    Main:
      while botao = 1
          pause 100
          counter = counter + 1
          if counter = 30 then  BotaoClickHold
      Wend
        if counter>0 and counter<=5  then  BotaoClick
    counter=0
    GOTO MAIN
    '                          SUB-ROTINAS
    ' ====================================================================
    BotaoClick:
    counter = 0
        if var1 = 0 then
            high led1
            var1 = 1
            pause 500
        else
            low led1
            var1 = 0
            pause 500
        endif
    Goto Main
    
    BotaoClickHold:
    counter = 0
        if var2 = 0 then
            high led2
            var2 = 1
            pause 500
        else
            low led2
            var2 = 0
            pause 500
        endif
    Goto Main
    END
    Thanks Again.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by gadelhas View Post
    Hi;

    It's Working just like the way i want, just made this change in the Main loop, from the code above;


    Thanks Again.


    Glad you're happy !!!

    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 " !!!
    *****************************************

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