PDA

View Full Version : Addition problem with word value on PIC18F8722



ImAnEE
- 11th June 2010, 03:00
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!

ImAnEE
- 11th June 2010, 04:24
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.:o