Menu

Newbie Help with a code problem

Help
Keith
2012-06-14
2013-05-30
  • Keith

    Keith - 2012-06-14

    Hi again. Could someone please help me out with this one.

    I am trying to set up an a pair of ports which will read the pins and select a subroutine bit I am simply running around in circles. My code compiles but it does not run on the chip.

    if select_1 =0 and select_2 =0 then
    Option = routine_1
    End if

    if select_1 =1 and select_2 =0 then
    option = routine_2
    end if
    if select_1 =0 and select_2 =1 then
    option = routine_3
    end if
    if select_1 =1 and select_2 =1 then
    'option = routine_3
    'end if

    what I want it to do is to use whichever sub routine is selected.

    Once again any help would be appreciated

     
  • Nobody/Anonymous

    if select_1 =0 and select_2 =0 then
    routine_1    '(routine_1  is the name of the SUB used)
    End if
    etc.

     
  • Keith

    Keith - 2012-06-15

    Hi and thank so much for your reply.

    I'm not too sure as to how to implement your recommendation. Perhaps it has been the way I have presented my problem.

    I have elaborated the problem below :

    if select_1 =0 and select_2 =0 then
    Option = routine_1
    End if

    if select_1 =1 and select_2 =0 then
    option = routine_2
    End if

    if select_1 =0 and select_2 =1 then
    option = routine_3
    End if

    if select_1 =1 and select_2 =1 then
    option = routine_3
    End if

    Main:

    If trigger = 1 Then
    Call option
    End If

    Goto Main

    Sub routine_1

    'Tone sequence goes here

    end Sub

    I have several extensive  tone routines which I have embedded into Sub routine_1  to  Sub routine_4

    I want to be able to preselect the Sub routine (n) then trigger it with trigger input.

    The problem I am having is as I see it, is I  want the variable called ‘option’ to carry the value of  the preselect be it routine_1, routine_2 etc. etc.

    Or am I going the wrong way of around it???

     
  • mmotte

    mmotte - 2012-06-16

    In GCBasic on line Help lookup Keyword "Select"  as in  select case.  this works like a series of 'if's.

    Also you may have them but you did not include them in the example.
       Need to tell the processor and speed
       need to setup  the port directions
    you need to set up a loop so if  you change the select_in  bits then the tones will change to another routine

    73
    mike
      

     
  • Keith

    Keith - 2012-06-16

    Thank you so much for your reply. I managed to get this up and running in a fashion late last night by changing the trigger statement 'If trigger = 1 Then' to a line which reads,

    'If trigger = 1  And 1 =0 and select_2 =0 Then
    routine_1
    End If

    It works but it is messy.

    I will research that 'Select' information you have given me. (thank you once again).

    Yes, I missed the chip info and definitions from the post for the sake of brevity.

     
  • Nobody/Anonymous

    You could use nested if - else statements like this -

    if trigger = 1 then
        if select_2 = 0 then
            if select_1 = 0 then
                routine_1
            else
                routine_2
            end if
        else
            if select_1 = 0 then
                routine_3
            else
                routine_4
            end if
        end if
    end if
    

    That would probably result in smaller code than testing all three bits for each routine.

     
  • Nobody/Anonymous

    The testing of the 3 bits can be very simple with the 'select case statement.
    First use 3 adjacent bits on one port.,, like the  the lower three bits of PortA.  0,1,2
    Then read the portA   and "mask " it with  AND b'00000111' which will allow only the lower three bits through.

    example:

    Mode =1

    do
    Mode = PortA & b'00000111'

         SELECT CASE Mode

        CASE 1
            GOSUB Measure

        CASE 2
            GOSUB AdjLowFreq

         END SELECT
      wait 100 ms
    loop

    If you took a programming course,  this is called a "dispacher".

    73
    Mike

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.