Group - ungroup of commands


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    The code posted earlier ...
    Code:
    ;reading buttons on line 2         
    Portb.0 = 0     
    TrisA.1 = 1     
    pause 10     
    status_3 = PortA & 011100     
          select case status_3                 
          case 20                 
          gosub starting                 
                 while (PortA & 011100) = 20                 
                        gosub volup                 
                 wend     
          end select                            
    Portb.0 = 1      
    TrisA.1 = 0   
    Goto main
    Work verry, verry fine !!!
    Thank You, Mr.Henrik !!!
    Last edited by fratello; - 9th May 2012 at 14:01.

  2. #2
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Mr.Henrik, I need Your advice, again ...
    I make some "experiments" with my specific matrix ... searching for best solution.
    I use the code from previous post, with good results.
    But now I need to have a little different function of buttons.
    I need to have portb.x = 1 while correspondent button.x is pressed.
    I don't understand why the code don't work proper ...
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _LVP_OFF 
    include "alldigital.pbp"
       Define   OSC 4           ' 4MHz 
       CMCON = 7                ' Disable on-chip comparator, PORTA in digital mode
    
    
    TRISA = %00011100           ; coloane la RA2, 3, 4 ; randuri la RA1, 0 ,7 
    PORTA = %00011100
    PORTB = %00000000
    TRISB = %00000000
    
    status_1 VAR BYTE
    
    Main:
    ;reading buttons on row 1
    PortA.0 = 0
    TrisA.1 = 1
    pause 10
    status_1 = PortA & %00011100
    ;    PortA.0 = 1
    ;    TrisA.1 = 0
    select case status_1
                    
    case 12
      while status_1 = 12
      portb.1 = 1
      wend
      portb.2 = 0 
    
    case 20
      while status_1 = 20
      portb.2 = 1
      wend
      portb.2 = 0
                    
    case 24
      while status_1 = 24
      portb.3 = 1
      wend
      portb.3 = 0
        
    end select
    PortA.0 = 1
    TrisA.1 = 0
    
    Goto main
    I KNOW I made some mistakes, but I DONT KNOW where ... Please, can You help me ?! Thank You so much !
    Attached Images Attached Images  

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,626


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    You're not updating status_1 within the while-wend loop so it will always be whatever it was when you entered that loop.
    Code:
    status_1 = PortA & %00011100     '<---This is where status_1 gets its value.
    ;    PortA.0 = 1
    ;    TrisA.1 = 0
    select case status_1
                    
    case 12
      while status_1 = 12    ' <---- Here, if you don't "refresh" the status_1 variable within the loop its value will NEVER change.
      portb.1 = 1
      wend
      portb.2 = 0
    /Henrik.

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Hm, now is clear why don't work !
    It's possible to refresh this status ? I guess not ..
    Or it's another way to get results ?
    Sorry I am so dumb ...

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    LE : Solution (not so elegant, but working) :
    Code:
    Main:
    ;reading buttons on row 1
    PortA.0 = 0
    TrisA.1 = 1
    pause 10
    if porta.2 = 0 then
      portb.1 = 1
    while porta.2=0 :  wend
      portb.1 = 0 
    endif
    
    if porta.3 = 0 then
      portb.2 = 1
    while porta.3=0 :  wend
      portb.2 = 0
    endif
                    
    if porta.4 = 0 then
      portb.3 = 1
    while porta.4=0 : wend
      portb.3 = 0
    endif
    
    PortA.0 = 1
    TrisA.1 = 0
    
    
    ;reading buttons on line 2    
    Portb.0 = 0
    TrisA.1 = 1
    pause 10
    if porta.2 = 0 then
      portb.4 = 1
    while porta.2=0 :  wend
      portb.4 = 0 
    endif
    
    if porta.3 = 0 then
      portb.5 = 1
    while porta.3=0 :  wend
      portb.5 = 0
    endif
                    
    if porta.4 = 0 then
      portb.6 = 1
    while porta.4=0 : wend
      portb.6 = 0
    endif
    
    Portb.0 = 1
    TrisA.1 = 0
        
    Goto main

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,626


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Hi,
    It's possible to refresh this status ? I guess not ..
    Of course there is, same way as you got the status in the first place, here with a little twist:
    Code:
    Main:
    GOSUB GetStatus    ' Get inital state
    
    Select Case status_1
    
    Case 12
      PortB.1 = 1
      WHILE status_1 = 12
      GOSUB GetPortStatus    ' <--- Now we'll update status_1 so we know when the button is released.
      WEND
      PortB.1 = 0 
    
    '.... And so on
    '.... and so on
    '.... and so on
    
    Goto Main
    
    GetPortStatus:
       status_1 = PortA & %00011100
    RETURN
    /Henrik.

  7. #7
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Wow ! Nice ! Thanks !
    How far am I from this technique ...

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