Two’s Compliment… again

Status
Not open for further replies.

VBguru

New Member
MBASIC
pic16f876



I am trying to get an accurate count from two bytes, one high and one low. I can get the low byte to work but the high byte doesn’t seem to want to work. When I have just the low byte part of my code then it counts fine it counts up and down smoothly. As soon as I put in the high byte part in it will only count one way correctly. Clock wise it counts up by one and other direction just makes it add 15 each time. What am i doing wrong?

_________________________________________________________________

Total var sword
Work var sword 'small
small var sword
Large var sword
Work2 var sword 'large

Work2 = 0
Work = 0
Total = 0
Small = 0
OE con P10
SEL con P11

High SEL
Low OE
High OE
Dirl = $FF

Main

Low SEL
low OE

work2 = INL
Large = Large + Work2
If Work2 > 127 then
Large = Large - 256
endif

High SEL
Work = INL
small = small + work
if Work > 127 then
small = small - 256
endif
High OE

Total = Total + small + Large

serout S_out,I38400,["Total = ",sDec Total," High = ",bin Large," Low = ",bin small,13]

Large = 0
Small = 0

Goto main
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…