change source code C to Basic

Discussion in 'Homework Help' started by ajimenez92, Jan 17, 2014.

  1. ajimenez92

    Thread Starter New Member

    Jan 17, 2014
    2
    0
    Code ( (Unknown Language)):
    1.  
    2. void   code_enter()
    3. {
    4. kp  = 0;                                         // Reset key  code  variable
    5. // Wait  for key  to be  pressed and  released
    6. do
    7. kp  = Keypad_Key_Click();                        // Store key  code  in kp  variable
    8. while (!kp);
    9. switch (kp)
    10. {
    11. case  1: kp  = '1'; break; // 1
    12. case  2: kp  = '2'; break; // 2
    13. case  3: kp  = '3'; break; // 3
    14. case  5: kp  = '4'; break; // 4
    15. case  6: kp  = '5'; break; // 5
    16. case  7: kp  = '6'; break; // 6
    17. case  9: kp  = '7'; break; // 7
    18. case 10:   kp  = '8'; break; // 8
    19. case 11:   kp  = '9'; break; // 9
    20. case 13:   kp  = 42;   break; // *
    21. case 14:   kp  = 48;   break; // 0
    22. case 15:   kp  = 35;   break; // #
    23. }
    24. code1[i] = kp;
    25. Lcd_Chr(2, i+1, code1[i]);                         // Print key  ASCII value on  Lcd
    26. i++;
    27. }
    28. [/i][/i]
     
    Last edited by a moderator: Jan 18, 2014
  2. ericgibbs

    Senior Member

    Jan 29, 2010
    2,499
    380
    hi,
    Which version of Basic are you using.?, its fairly easy to convert.
    Look at the 'Select Case...Case... End Select', statement, [to replace the Switch] its common to many Basic versions.
    E.
     
  3. ajimenez92

    Thread Starter New Member

    Jan 17, 2014
    2
    0
    Hi
    It is mikrobasic.. I don't understand the statement Do and While..

    thank you?
     
  4. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
  5. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788


    So what's your question? Are you just expecting someone to translate the code for you?

    What are you going to do about the function calls such as Keypad_Key_Click and Lcd_Chr()?
     
  6. studiot

    AAC Fanatic!

    Nov 9, 2007
    5,005
    513
    You have posted this in homework help so I assume you are studying both languages.

    Your question suggests you have been asked reprogram a subroutine in another language (Basic) to replicate the C subroutine.

    So your first task is to decide the type of Basic subroutine you wish to write.

    The Do statement tells the C program to check the contents of the keypad variable, repeatedly.

    The while bit tells C to compare with the set value (0).

    ie wait for an entry.

    There are several ways to achieve this in Basic.

    Suggest one or two to us

    When the keypad variable is non zero following a check the program falls through a series of condition filters to select the appropriate action.

    Again there are several methods of achieving this in Basic.
    Again suggest one or two.

    The subroutine then needs to reset the keypad variable to zero


    finally the subroutine must return control to the main program.

    Does this help?
     
  7. WBahn

    Moderator

    Mar 31, 2012
    17,716
    4,788
    Are you saying that you don't understand what a do...while() structure does in general, or that you do not understand what this particular do...while() structure accomplishes in this particular function?
     
  8. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Yep. He's provided everything needed;
    The command issued to his slaves; "change source code C to Basic"
    AND the code item his slaves need to start working on.

    And it seems most unlikely to be a homework question. This is just the forum area that has the hardest working slaves. ;)
     
  9. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988

    If you don't understand do and while then you have no business trying to convert this code.

    do and while are used in C and BASIC. Albeit the syntax is different but the function is the same. You need to start by first understanding BASIC then learn a little about C. After that the conversion will be easy to do.
     
Loading...