STATUS ?
STATUS.0 ?
Ahhh, Darrel, you confuseth me. From whence comes... STATUS ?
steve
STATUS is a register in the PIC that contains the results (status) of arithmetic operations.
Depening on the chip family, it may also have Watchdog Timer status and FSR/page bits.
STATUS.0 is the CARRY flag.
After an addition, if the result is larger than 255 the carry bit will be set (1).
After a subtraction, if the result is less than 0 (BORROW), the carry bit will be cleared (0).
The carry bit is only valid after addition/subtraction with 8-bit values.
After math with WORD values, the carry bit cannot be used because not all of the math is done by the hardware.
DT
OK, curiosity got me so I tried it with WORD values and it still seems to work...
x = 32768
Y = 32769
x = x + y
Result: X = 1, STATUS.0 = 1
'--------------------------------
x = 32768
Y = 32765
x = x + y
Result: X = 65533, STATUS.0 = 0
'-------------------------------------
x = 32768
Y = 32765
x = x - y
Result: X = 3, STATUS.0 = 1
'--------------------------------------
x = 32765
Y = 32771
x = x - y
Result: X = 65530, STATUS.0 = 0
'------------------------------------
I thought it was only 'sposed to work with 8 bit numbers?
Steve
Try it with ...
X = 32768
Y = 65523
DT
Since PBP handles the 16 (31) bit math, and certainly knows the results of the 8 bit operation, the writers of PBP *could* provide us with an overflow/underflow flag (PSTATUS?). If they really wanted to.
Charles Linquist
If the previous subtraction produced negative results, bit 0 of STATUS is set (to 1). Then you check this condition and if true, set Volume to 0.
By the way which chip are you controlling?
Ioannis
Wow... thanks Darrel. THAT is an interesting item to know about.
I'm sure I can make good use of that!
Ioannis, I'm using a 16F887. And thanks for helping explain the STATUS thing!
steve
Darrel = After a subtraction, if the result is less than 0 (BORROW), the carry bit will be cleared (0).
Ioannis = If the previous subtraction produced negative results, bit 0 of STATUS is set (to 1)
OK guys(gals?)
if I read those two statements correctly... they are contradictory. You can't have it both ways... which is it??
Dwight
These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.
Don't believe anything just because somebody said so.
Especially when there's conflicting information.
Check the datasheet, and test it for yourself. Then you will know the truth.
This program will help with the testing part.
Code:Volume VAR BYTE Vstep VAR BYTE Result VAR BYTE Carry VAR BIT HIGH PORTD.0 ; initialize serial line PAUSE 100 FOR Volume = 5 TO 0 STEP -1 FOR Vstep = 5 TO 0 STEP - 1 Result = Volume - Vstep Carry = STATUS.0 SEROUT2 PORTD.0,84,[DEC Volume," - ",DEC Vstep," = ",DEC Result," C = ",DEC Carry,13,10] NEXT Vstep NEXT Volume STOP
DT
Darrels way works with a 16F887.Code:IF !STATUS.0 THEN Volume = 0
Can't vouch for any other chips...
Darrel, what is the value of STATUS.0 at start up? I assume it should be zero (no borrow no carry) , are you going to set it at start up, in order to have your snippet @ post #12 working?
Cheers
Al.
Last edited by aratti; - 18th September 2011 at 02:50.
All progress began with an idea
Here is my test code and the debug results below...
and the Debug results...Code:DEFINE DEBUG_REGG PORTA 'set debug port to porta DEFINE DEBUG_BIT 0 'use pin a0 of porta for debug DEFINE DEBUG_BAUD 2400 'set baud rate to 2400 DEFINE DEBUG_MODE 0 'communicate in true mode valA var byte valB var byte resultA var byte resultB var byte resultC var byte resultD var byte Carry var bit vala=51 valb=50 resulta=vala-valb Carry = STATUS.0 debug "resultA : 51-50=",dec resulta," Carry=",dec carry,13,10 resultb=valb-vala Carry = STATUS.0 debug "resultB : 50-51=",dec resultb," Carry=",dec carry,13,10 resultC=vala+valb Carry = STATUS.0 debug "resultC : 51+50=",dec resultc," Carry=",dec carry,13,10 vala=55 valb=201 resultD=vala+valb Carry = STATUS.0 debug "resultD : 55+201=",dec resultd," Carry=",dec carry,13,10 end
resultA : 51-50=1 Carry=1
resultB : 50-51=255 Carry=0
resultC : 51+50=101 Carry=0
resultD : 55+201=0 Carry=1
Last edited by Heckler; - 18th September 2011 at 04:26.
Dwight
These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.
Bookmarks