All,
I am using PIC Basic and a keypad and would like to save the numbers and then output them as a whole decimal through RS232.
Example: On the keypad enter '1' then '0' then '0' and then press the ENT button to send out the whole number of 100 out serially to some device.
I am able to store the numbers individually (1 then 0 then 0)to the on board eeprom at different addresses but I am stuck as how to send the whole number of 100 out.
I think I missunderstood what you were trying to do the first time; I don't think you need arrays for what you are talking about. I haven't used Basic in years but I can give you a start.
When you declare a variable it gets put in ram.
Here's some pseudo code:
Code:
BYTE Ser_Data;
BYTE Keypad_Input;
BYTE Key_Count;
Ser_Data = 0;
Key_Count = 0;
loop:
Keypad_Input = the data you read from the keypad;
if Keypad_Input equals ENT then
jump out of loop;
else
KeyCount + 1;
Ser_Data = Ser_Data + Key_Count*Keypad_Input;
jump to loop;
send Ser_Data with UART.
You could read the numbers from the keypad into an array.
When enter is pressed, use a few if-thens to determine how many numbers were entered and therefore a place value. Multiply the number x10 or x100 to give it it's real value then add all the entered numbers together
for example:
if you enter 4, 3, 5, <enter>
your array would have 4 values (if you included <enter>)
so...
multiply 4 x 100
multiply 3 x 10
5 is good the way it is.
Add them up 400 + 30 + 5
and send them out serially.
Sorry I wasn't thinking last night. Lavenetti has it right. The Ser_Data line was intended to multiply by the correct power of 10 but I forgot the exponentiation and was counting the wrong way with Key_Count. Just ignore my code and do what Lavenatti says.