Addition problem with word value on PIC18F8722


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010
    Location
    Walnut Creek, CA
    Posts
    17

    Question Addition problem with word value on PIC18F8722

    Having a strange problem with addition to a word. I'm outputting the number to the PIC18F8722 EUSART. I'm using PBP v2.60. I can output a constant, e.g. 31416, but if I add one to a word value starting at zero, I get some weird results.

    Here's a snippet from my code:

    IF (bXMIT_CNTR >= 20) THEN
    CONV_X = CONV_X + 1
    'CONV_X = 31416
    bXMIT_CNTR = 0
    SERIAL_MSG_FLAG = 1
    ENDIF


    And here are some of the results. I would expect 1, 2, 3...:
    11111
    22222
    33333
    44444
    55555
    66666
    77777
    88888
    99999
    11110
    11111
    11112
    11113
    11114
    11115
    11116
    11117
    11118
    11119
    22220
    22221
    22222
    22223

    Any ideas?

    Thanks!

  2. #2
    Join Date
    Apr 2010
    Location
    Walnut Creek, CA
    Posts
    17


    Did you find this post helpful? Yes | No

    Red face Ah, my mistake of course

    My mistake. The problem is not with the addition, but rather with my binary to BCD conversion routine that I'm using to output the number serially. I foolishly tested it only with 5-digit numbers, not smaller ones. It works great with the 5-digit number. Sorry about that.

Members who have read this thread : 1

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