change source code C to Basic

Thread Starter

ajimenez92

Joined Jan 17, 2014
2
Rich (BB code):
void   code_enter()
{
kp  = 0;                                         // Reset key  code  variable
// Wait  for key  to be  pressed and  released
do
kp  = Keypad_Key_Click();                        // Store key  code  in kp  variable
while (!kp);
switch (kp)
{
case  1: kp  = '1'; break; // 1
case  2: kp  = '2'; break; // 2
case  3: kp  = '3'; break; // 3
case  5: kp  = '4'; break; // 4
case  6: kp  = '5'; break; // 5
case  7: kp  = '6'; break; // 6
case  9: kp  = '7'; break; // 7
case 10:   kp  = '8'; break; // 8
case 11:   kp  = '9'; break; // 9
case 13:   kp  = 42;   break; // *
case 14:   kp  = 48;   break; // 0
case 15:   kp  = 35;   break; // #
}
code1 = kp;
Lcd_Chr(2, i+1, code1);                         // Print key  ASCII value on  Lcd
i++;
}
 
Last edited by a moderator:

ericgibbs

Joined Jan 29, 2010
18,766
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.
 

WBahn

Joined Mar 31, 2012
29,978
Rich (BB code):
void   code_enter()
{
kp  = 0;                                         // Reset key  code  variable
// Wait  for key  to be  pressed and  released
do
kp  = Keypad_Key_Click();                        // Store key  code  in kp  variable
while (!kp);
switch (kp)
{
case  1: kp  = '1'; break; // 1
case  2: kp  = '2'; break; // 2
case  3: kp  = '3'; break; // 3
case  5: kp  = '4'; break; // 4
case  6: kp  = '5'; break; // 5
case  7: kp  = '6'; break; // 6
case  9: kp  = '7'; break; // 7
case 10:   kp  = '8'; break; // 8
case 11:   kp  = '9'; break; // 9
case 13:   kp  = 42;   break; // *
case 14:   kp  = 48;   break; // 0
case 15:   kp  = 35;   break; // #
}
code1 = kp;
Lcd_Chr(2, i+1, code1);                         // Print key  ASCII value on  Lcd
i++;
}


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()?
 

studiot

Joined Nov 9, 2007
4,998
I don't understand the statement Do and While..
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?
 

WBahn

Joined Mar 31, 2012
29,978
Hi
It is mikrobasic.. I don't understand the statement Do and While..

thank you?
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?
 

THE_RB

Joined Feb 11, 2008
5,438
So what's your question? Are you just expecting someone to translate the code for you?
...
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. ;)
 

spinnaker

Joined Oct 29, 2009
7,830
Hi
It is mikrobasic.. I don't understand the statement Do and While..

thank you?

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.
 
Top