Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC BASIC USERS -- HELP!!

Status
Not open for further replies.

Beefer3

New Member
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. :(

Any help is greatly appreciated. :lol:

Thanks
 
You should store the numbers in RAM in an array. When ENT is pressed you just read the numbers out of the array.
 
bmcculla
How do i go about doing this? My number that I want to send out may very from 0 to 200.

I have never really used RAM in pic basic before and I am at a loss...

If you don't mind, can you give me some example code or maybe explain it in detail for this feeble mind. :wink:

Thanks for any help you can give
 
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.
 
thanks bmcculla. I understand the psuedo code up until the ser_data part.
When you say
Code:
"Ser_Data = Ser_Data + Key_Count*Keypad_Input"
, wouldn't this just multiply the Key_Count value times Keypad_Input value?

Example: Let's say that my Key_Count value is 1 and my Key_Input value is 9. This value is 9 (1 * 9 = 9).

Now let's say I entered 4. My Key_Count value is 2 and my Key_Input is 4. This value is now 8 (2 * 4 = 8).

Now I have two values 9 and 8. Using the ser_data code above this would add the two together ( 9 + 8 = 17), correct?

This is not the number I want to send. I want to send the Key_Input values of 94.

Sorry to question your ways but am I way off course here?

Thanks
 
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.
 
Thanks guy. I will try the code tonight.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top