The worst programmer ever to grace this forum - ME!


Results 1 to 40 of 50

Threaded View

  1. #36
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Oops, that last posting of mine missed a middle bit out! It should have read more like below...


    I've kludged the following code taken from here & there (plagiarism is alive & well!), towards getting the HSERIN working to fit my needs.


    I'm using HSERIN to take 3 characters (which always will be numbers), input from my PC keyboard into my PIC. I'd then like to use these three separate numbers & combine them into a variable. All my serial end to end connectivity is is now working (no gobbledegook etc)...I'm happy with the signal flow aspect, fuses etc - ddata is moving to & fro fine - my query is now a basic simple programming one!

    With HSERIN, I'd read that's it's best to have a 'trigger' character, followed on immdeiately by the actual data. So this is what I've done, when my PIC sees a leading 0, it takes in the folloiwing three bytes as a string. I need my 3 byte input string to be 3 actual numbers that my PIC program can act upon.


    Here's what I'm doing .....

    turns_required VAR BYTE[3] ; this is the user input for how many turns of a motor
    direction_change var byte[3] ; again, user input for when the motor should change direction.

    turns_required VAR BYTE[3]
    counter var byte
    counter = 0
    pause 800 ; let things settle
    HSEROUT [13,10]
    HSEROUT ["Enter Number of turns required (with a leading 0)>>>", 13,10]

    Main
    HSERIN 5000,finish,[WAIT("0"),STR turns_required \3] ; wait for 3 bytes following the character '0;
    HSEROUT ["Number of turns will be.... ", STR turns_required \3,13,10] ' oyutput it to screen to confirm

    counter = turns_required ' this is the key bit that isn't working as turns_required is a string

    count_loop:
    counter = counter -1
    HSEROUT [DEC COUNTER,13,10]
    pause 200
    GOTO count_loop



    How can I convert my three character 'input' string (which will always be numbers) into an actual number that my program can use - I guess what i need is a way of converting a string into a number? (or perhaps a way of taking the input as raw number vs the string method I'm using?)

    When I run the program, I can see the counter starts decrementing from a different number to that what I input (if for example I input 0032, the count below starts decrementing at 48, in fact it starts at 48 no matter what number I input!!)
    Last edited by HankMcSpank; - 21st May 2009 at 19:59.

Similar Threads

  1. Melabs U2 Programmer Command Line Options
    By Robert Wells in forum General
    Replies: 5
    Last Post: - 3rd July 2009, 03:11
  2. problems with USB programmer
    By malc-c in forum General
    Replies: 7
    Last Post: - 10th May 2007, 21:14
  3. USB programmer problems
    By uiucee2003 in forum USB
    Replies: 2
    Last Post: - 16th August 2006, 00:47
  4. General Programmer Questions
    By mslaney in forum General
    Replies: 1
    Last Post: - 17th December 2004, 19:16

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts