Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 28th January 2007, 11:45 AM   (permalink)
Default Testing for transition 255 to 0

Micro: 18F Microchip family.

Given a common register, to detect the transition from 0 to 255 (DECF), what can I test? Is it any trick other than looking for the value 255 in the byte?
__________________
Agustín Tomás
In theory, there is no difference between theory and practice. In practice, however, there is.
atferrari is offline  
Old 28th January 2007, 12:06 PM   (permalink)
Default

Try looking at the flags register!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 28th January 2007, 01:04 PM   (permalink)
Default

Going from 255 to 0 sets C but the opposite has not a single flag set, only for the case. At least, simulation shows that.
__________________
Agustín Tomás
In theory, there is no difference between theory and practice. In practice, however, there is.
atferrari is offline  
Old 28th January 2007, 01:23 PM   (permalink)
Default

Doesn't it set the overflow flag?

Mike.
Pommie is offline  
Old 28th January 2007, 01:56 PM   (permalink)
Default

The DECF instruction on a reg with a value of zero to 255 sets the Negative flag (Status reg bit 4)
picasm is offline  
Old 28th January 2007, 02:37 PM   (permalink)
Default

Wouldn't it also clear the Zero flag bit? Yep, the DECF instructions affects a whole bunch of STATUS bits. Check out the instruction set summary.

Mike

Last edited by Mike, K8LH; 28th January 2007 at 02:44 PM.
Mike, K8LH is offline  
Old 28th January 2007, 02:41 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH
Wouldn't it also clear the Zero flag bit?
Yes, but you would have to check that it was set BEFORE you did the DECF, because it would be clear in all cases except one.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 28th January 2007, 02:46 PM   (permalink)
Default

I wonder if the OP is trying to avoid decrementing a register if its value is 0? If that's the case, most of us recommend testing for that condition before performing the decrement operation. Isn't that right guys?

Mike
Mike, K8LH is offline  
Old 28th January 2007, 02:53 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH
I wonder if the OP is trying to avoid decrementing a register if its value is 0? If that's the case, most of us recommend testing for that condition before performing the decrement operation. Isn't that right guys?
If that was the case, then yes!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 28th January 2007, 02:57 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH
I wonder if the OP is trying to avoid decrementing a register if its value is 0? If that's the case, most of us recommend testing for that condition before performing the decrement operation. Isn't that right guys?

Mike
Yes, For that situation I have used:
tstfsz reg ; skip if the reg has already reached zero
decf reg,f

If he wants to test if a reg has reached 255, then he could use:
DECF reg,f
BN destination ; Branch if negative
picasm is offline  
Old 28th January 2007, 03:42 PM   (permalink)
Default

How about
decf file,F
incfsnz file,W ; check if file was zero before the decrement
goto WasZero

Or OV=1 and N=1 gives the same thing.

Checking Z=0 will give all numbers except zero.
Checking N=1 will give all numbers from 0x80 to 0xff.
Checking just OV will give 255 and 127.

Someone with more knowledge about 18 code, does the Carry flag act as a borrow and is therefore reset only if there is a transition from 0 to 255? This would seem likely to me.

Mike.
Pommie is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Sytem Testing -=GST=- Nemisis (cs/cz) Electronic Projects Design/Ideas/Reviews 3 3rd April 2006 02:00 PM
know about testing tools arun_dexter General Electronics Chat 1 15th May 2005 07:55 AM
testing a thermocouple evandude General Electronics Chat 8 29th October 2004 05:25 PM
Capacitor testing zachtheterrible General Electronics Chat 9 31st May 2004 07:21 AM
Testing any Monitor Without PC xpacer General Electronics Chat 6 13th July 2003 09:55 AM



All times are GMT. The time now is 08:03 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker