Group - ungroup of commands


Closed Thread
Results 1 to 16 of 16

Hybrid View

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

    Default Group - ungroup of commands

    Hi !
    I need to do this : when I push a button (main program), I send through a pin this command (gosub command): Header, body,pause, body, pause .. where "body" repeat as long I push the button ( header it's something like "010001010", where 0 is us pause, 1 is "x" us of logic "1" ; the body resembles header).
    Next time when I push the button, the command must be the same : Header, body, pause, body, pause, so on, so on ...
    I cant find a way to send just for one time the header at each press of button ... I try to increment one variable (n=n+1) but wherever I put its reset, the results are not the expected ... the entire command are send (including header).
    Please, give me a clue ! Thanks in advance ! Regards !

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Something like this?

    Code:
    main:
    
         ' somewhere in main
    
        if ButtonIsPressed then gosub ButtonProcess
    
        goto main
    
    
    ButtonProcess:
         gosub SendHeader                    ' send the 010001010 pattern with this subroutine
         while ButtonIsPressed               ' as long as the button remains pressed,
              gosub SendBody                 ' send the body pattern
              Pause xxx                          ' followed by the pause
         wend                                      ' loop @ while statement
    
         '  when button is released, you may want to send something too!!
         gosub SendTrailer                    ' similar to the header but sent at end of button press.  Makes it a bit exciting !!
    return
    Regards

  3. #3
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    573


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Thank You !
    Unfortunately, my code it's a little ... special and this procedure dont work ...
    My code :
    Code:
    Main:
    ;reading buttons on line 2    
        Portb.0 = 0
        TrisA.1 = 1
        pause 10
        status_3 = PortA & 011100
        Portb.0 = 1
        TrisA.1 = 0
        select case status_3
                    case 12
                    Gosub Starting  ; this is "header"
                    Gosub Sursa     ; ths is "body"
                    case 20
                    Gosub Starting  ; this is "header"
                    Gosub VolUp     ; this is "body", composed by Adresa + VolUp
                    case 24
                    Gosub Starting
                    Gosub VolDn 
        end select                       
    Goto main
    
    STARTING:
    PORTB.4 = 0
    pauseus 8400
    PORTB.4 = 1
    pauseus 4200
    Return
    
    ADRESA:
        For i = 0 to 7
        lookup2 i, [a,a,a,a,b,b,b,a], j
        PORTB.4 = 0
        PauseUs 526
        PORTB.4 = 1
        PauseUs j
        next i 
    Return
    
    VolUp:
    GOSUB ADRESA
        for i = 0 to 7
        lookup2 i, [b,b,a,b,b,b,b,a], j
        PORTB.4 = 0
        PauseUs 526
        PORTB.4 = 1
        PauseUs j
        next i
    Pause 12    
    Return
    Last edited by fratello; - 4th May 2012 at 17:49.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Why wouldn't Jersons procedure work with that code? You just need to think about how it works and APPLY it to your program...


    Code:
    case 12
      Gosub Starting  ; this is "header"
      While (PortA & %00011100) = 12
        Gosub Sursa     ; ths is "body"
      Wend
    OR, if you want to be SURE to send 'body' atleast one time.
    Code:
    case 12
      Gosub Starting  ; this is "header"
      Gosub Sursa
      While (PortA & %00011100) = 12
        Gosub Sursa     ; ths is "body"
      Wend
    Also, since you're always sending the header you could move that to outside of the Select Case structure. Send 'header' then select which 'body' to send. That'll save a couple of GOSUBS.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Still don't work...
    First try:
    Code:
    ;reading buttons on line 2    
        Portb.0 = 0
        TrisA.1 = 1
        pause 10
        status_3 = PortA & %00011100
        Portb.0 = 1
        TrisA.1 = 0
        select case status_3
                     case 20
                     gosub starting
                     While (PortA & %00011100) = 20
                     Gosub VolUp
                     wend
         end select 
    Goto Main
    the "code" generated is ... totally inadequate (picture 1).

    Second try :
    Code:
    ;reading buttons on line 2    
        Portb.0 = 0
        TrisA.1 = 1
        pause 10
        status_3 = PortA & %00011100
        Portb.0 = 1
        TrisA.1 = 0
        select case status_3
                     case 20
                     gosub Starting
                     Gosub VolUp
                     While (PortA & %00011100) = 20
                     Gosub VolUp
                     wend
         end select                       
    Goto main
    the "code" generated is ...full, with "header" at any VolUp command ! (picture 2).
    What do I do wrong ?
    Attached Images Attached Images   

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


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Hi,
    One possible cause is that when you read PortA inside the WHILE-WEND loop PortA.1 is not read properly since you make it an output before entering the loop. If you're going to read the pins they need to be inputs.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Group - ungroup of commands

    Wherever I put this code (While (PortA & %00011100) = 20 : Wend) the result are always the same : full command is sending.

    Recap :
    - if I push button for VolUp (case 20) I need to send this code : Starting (heading) , followed by VolUp command (body). If the VolUp it still pressed, while the button is pressed, only body must be sending ;
    - the next time I press VolUp, the whole process must be repeated : Starting, followed by body while buton is pressed ...

    Maybe instead of (While (PortA & %00011100) = 20 : Wend) I must use another command ... but I dont realise which one ...

Members who have read this thread : 1

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