![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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 ??) | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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 Thanks | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |
| Quote:
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. ;------------------------------- 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 Last edited by donniedj; 9th October 2007 at 04:48 AM. | ||
| |
| | (permalink) |
| Hi I got cover up all your comments.And donniedj thanks for your excellent comparator idea.worth of thanks for that. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |