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 8th October 2007, 04:22 AM   (permalink)
Question Whats the purpose of this ANDLW?

I have this code. What I want to know is what’s the purpose of this anldw line?

From my view I can say it will never allow to compare D’125’.Bcuz it allows only D’127’.

Help me to solve this problem.

Code:
	movf	COUNT,W		;get the COUNT value
	andlw	b'01111111'	;AND with 7Fh (D’127’)
	xorlw	.125		;b'01111101'
	btfss	STATUS,Z	;compare with zero bit
	goto	Exit
	goto	Main
Suraj143 is offline  
Old 8th October 2007, 04:35 AM   (permalink)
Default

As for the ANDLW, it looks like it's used for BIT stripping. All values from bits 0-6 will be passed through but bit 7 not. (Maybe the original code was used for 7-segment display where bit <7> was not used ??)
SPDCHK is offline  
Old 8th October 2007, 04:50 AM   (permalink)
Default

MPASM has a nifty "bz" command, means branch on zero (there is also a bnz) these can make the program slightly easier to read.
so
bz Main
goto Exit
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now  
Old 8th October 2007, 06:00 AM   (permalink)
Default

You have to look at the rest of the code in order to work out why you need the andlw 0x7f. Bit 7 is used to keep track of the state of the LED. From your other thread,

Code:
		movlw	.6
		addwf	TMR0,F
		incf	TIME,F
		movf	TIME,W
		andlw	7fh
		xorlw	.125
		btfss	STATUS,Z
		goto	Away
		btfss	TIME,7
		goto	$+4
		clrf	TIME			;Bit 7 = 0
		bcf	LED			;turn OFF led
		goto	Away
		clrf	TIME
		bsf	TIME,7			;Bit 7 = 1
		bsf	LED			;turn ON led
Mike.
Pommie is offline  
Old 8th October 2007, 06:28 AM   (permalink)
Default

Thanks for the replies guys.

Now I got it. It has used a family bit of the same Time variable.
To avoid confusion I can remove andlw & use another variable before writing to the LED.

BTW I have another doubt question.

I want to check whether the 7th bit of COUNT variable set.

This will set for sure bcuz it has set only the 7th bit.
Code:
	COUNT = b’10000000’
	Btfss	COUNT, 7

What about this It has some other values in first 5 bits but 7th bit is set.
Code:
COUNT = b’10111111’
	Btfss	COUNT, 7
Will this also be set?

Thanks
Suraj143 is offline  
Old 8th October 2007, 09:12 AM   (permalink)
Default

Yes, BTFSS is only checking one specific bit, the rest make no difference.

As for ANDLW, it's the normal logical AND instruction, as used in computers since their first days. With micro-processors (and lesser micro-controllers) your only option form checking (or setting) individual bits is to use combinations of logical AND, OR, XOR instructions.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Old 9th October 2007, 04:37 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143
I have this code. What I want to know is what’s the purpose of this anldw line?
Code:
	movf	COUNT,W		;get the COUNT value
	andlw	b'01111111'	;AND with 7Fh (D’127’)
	xorlw	.125		;b'01111101'
	btfss	STATUS,Z	;compare with zero bit
	goto	Exit
	goto	Main
"Just as 256 is not a true max, 256 is also not a true minimum" (donniedj circa see post time stamp):

As already stated, it and its accomplice is used to compare an unknown count to a known comparator value. But whats important for you to take from this is how you can compare PARTS of a value, in this case bits 6-0, while not caring about the other parts for the moment. A single variable can have multiple segments. Bit 7 of COUNT could be used for some other purpose such as a flag. Imagine a processor where the smallest data was 4 bytes. A resource limited yet smart coder could make use of each PART as their own 4 separate 1 byte variables coexisting inside 1 entity by a parts compare technique as above.
Code:
	
	;--COMPARE SEGMENT OF COUNT TO COMPARATOR--
	MOVF	COUNT, W	;STORING COUNT[6-0] INTO W
	ANDLW	B'01111111'	;
	XORLW	.125		;ASSIGN COMPARATOR = 125
	BTFSS	STATUS, Z	;DOES COUNT[6-0] = COMPARATOR?,
	GOTO	EXIT		;NO, EXIT
	GOTO	MAIN		;YES, GOTO MAIN.
	;-------------------------------
Do yourself a favor, comment on the significance and not on the literate. Stating lines like
Code:
	movf	COUNT,W		;get the COUNT value
	andlw	b'01111111'	;AND with 7Fh (D’127’)
	xorlw	.125		;b'01111101'
	btfss	STATUS,Z	;compare with zero bit
helps as much as an empty comment line.

Last edited by donniedj; 9th October 2007 at 04:48 AM.
donniedj is offline  
Old 9th October 2007, 04:59 AM   (permalink)
Default

Hi I got cover up all your comments.And donniedj thanks for your excellent comparator idea.worth of thanks for that.
Suraj143 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
General purpose DAC Sceadwian General Electronics Chat 3 10th February 2007 08:02 AM
Simple question. What is the purpose of diode across 7805 William At MyBlueRoom General Electronics Chat 24 14th April 2006 08:26 PM
Purpose of assembly instructions? gregmcc Micro Controllers 2 27th December 2005 09:58 AM
ya mari_69 Micro Controllers 4 7th June 2004 02:29 PM
Purpose of ... bryan Electronic Projects Design/Ideas/Reviews 3 19th September 2003 08:30 AM



All times are GMT. The time now is 09:29 PM.


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

eXTReMe Tracker