+ Reply to Thread
Results 1 to 8 of 8

Thread: PIC BASIC USERS -- HELP!!

  1. #1
    Beefer3 Newbie
    Join Date
    Sep 2003
    Location
    Connecticut
    Posts
    76

    Default PIC BASIC USERS -- HELP!!

    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
    I like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk.

    - Stephen King


  2. #2
    bmcculla Newbie
    Join Date
    Sep 2003
    Location
    California, USA
    Posts
    898

    Default

    You should store the numbers in RAM in an array. When ENT is pressed you just read the numbers out of the array.

  3. #3
    Beefer3 Newbie
    Join Date
    Sep 2003
    Location
    Connecticut
    Posts
    76

    Default

    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 like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk.

    - Stephen King

  4. #4
    bmcculla Newbie
    Join Date
    Sep 2003
    Location
    California, USA
    Posts
    898

    Default

    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.
    

  5. #5
    Beefer3 Newbie
    Join Date
    Sep 2003
    Location
    Connecticut
    Posts
    76

    Default

    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
    I like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk.

    - Stephen King

  6. #6
    lavenatti Newbie
    Join Date
    Feb 2003
    Location
    Peoples Republic of NJ
    Posts
    266

    Default

    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.

  7. #7
    bmcculla Newbie
    Join Date
    Sep 2003
    Location
    California, USA
    Posts
    898

    Default

    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.

  8. #8
    Beefer3 Newbie
    Join Date
    Sep 2003
    Location
    Connecticut
    Posts
    76

    Default

    Thanks guy. I will try the code tonight.
    I like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk.

    - Stephen King

+ Reply to Thread

Tags for this Thread