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 20th September 2007, 04:46 AM   (permalink)
Arrow How to check whether it is ZERO or not?

Hi I have a COUNT variable. When power up the PIC don’t know what value in it. (It depends on the last saved value in EEPROM)

I want to check whether it is ZERO or other. If it is zero I want to goto NORMAL program. If not zero I want to goto UPDATE routine.

Here is my code please tell me am I right?

Code:
	movf	COUNT,W		;get the count value
	xorlw	00h		;compare with zero
	btfss	STATUS,Z	;check the ZERO bit
	goto	UPDATE		;NO, it is not ZERO
	goto	NORMAL		;YES, it is ZERO
Suraj143 is offline  
Old 20th September 2007, 04:55 AM   (permalink)
Default

Yep that'll work. MPASM also has a couple of macros built in to make that eaiser.

so..

Code:
  movf   COUNT,W   ;sets the z flag
  bz     NORMAL    ;it's zero so branch
  goto   UPDATE    ;not zero so goto UPDATE
PS movf will set the zero flag, you don't need the xor.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now  
Old 20th September 2007, 05:10 AM   (permalink)
Default

Another useful way to test for zero is movf COUNT,F. This will set/clear the zero flag without corrupting W.

Mike.
Pommie is offline  
Old 20th September 2007, 05:23 AM   (permalink)
Default

Oh I see now I got it.Everywhere I'm corrupting W I must prevent this by moving the value to the FILE register.

Also built in macros really helpful.I must give a try for that.

Thank you both of you for the instant replies.
Suraj143 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
How can I check a transistor is working mettam General Electronics Chat 6 2nd October 2006 02:48 AM
How to check a Live Chassis walters General Electronics Chat 5 17th August 2005 08:06 AM
Chip talk dreamproject Electronic Projects Design/Ideas/Reviews 8 2nd April 2005 08:24 PM
Motor control interface dreamproject Micro Controllers 0 31st March 2005 04:48 AM
Check this Out! mechanicats General Electronics Chat 1 7th February 2003 08:28 PM



All times are GMT. The time now is 06:23 PM.


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

eXTReMe Tracker