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 15th August 2008, 03:23 AM   (permalink)
Question Masking Upper Nibble

Hi I need to mask the upper nibble & must not do any harm to the lower nibble.

But this code never work.

Code:
	movf	Data,W
	andlw	b'11110000'
	iorwf	PORTB,F

But this code works but corrupting lower nibble.

Code:
	movf	Data,W
	andlw	b'11110000'
	movwf	PORTB,F
Suraj143 is offline  
Old 15th August 2008, 03:52 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143 View Post
Hi I need to mask the upper nibble & must not do any harm to the lower nibble.

But this code works but corrupting lower nibble.
Code:
	movf	Data,W
	andlw	b'11110000'
	movwf	PORTB,F
That's because you should use AND to clear, or mask, the upper nibble - not the lower nibble. Like this:
Code:
	andlw	b'00001111'
This will zero out the upper nibble and leave the lower nibble exactly the way it was.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 15th August 2008 at 03:53 AM.
futz is online now  
Old 15th August 2008, 03:57 AM   (permalink)
Default

Do you wish to transfer the upper nibble of Data to the upper nibble of PORTB without disturbing the lower nibble in either?
__________________
--- The days of the digital watch are numbered. ---
kchriste is offline  
Old 15th August 2008, 04:06 AM   (permalink)
Default

Quote:
Originally Posted by kchriste View Post
Do you wish to transfer the upper nibble of Data to the upper nibble of PORTB without disturbing the lower nibble in either?
Exactly this is what I need to do.
Suraj143 is offline  
Old 15th August 2008, 04:13 AM   (permalink)
Default

Quote:
Originally Posted by Suraj143 View Post
Exactly this is what I need to do.
Then first move Data to a temp variable or W and mask the lower nibble. Then mask the upper nibble of PORTB (maybe move it to a temporary variable first). Then OR them together.

Maybe there's a simpler way?
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 15th August 2008 at 04:15 AM.
futz is online now  
Old 15th August 2008, 04:19 AM   (permalink)
Default

Quote:
Originally Posted by futz View Post
Then first move Data to a temp variable or W and mask the lower nibble. Then mask the upper nibble of PORTB (maybe move it to a temporary variable first). Then OR them together.

Maybe there's a simpler way?
Code:
	movf	Data,W
	andlw	b'00001111'
	????	????
	iorwf	PORTB,F
Suraj143 is offline  
Old 15th August 2008, 04:29 AM   (permalink)
Default

Code:
	movf	Data,W
	andlw	b'11110000'
	movwf	temp1
	movf	PORTB,w
	andlw	b'00001111'
	iorwf	temp1,w
	movwf	PORTB
Hmm... Is that right? Just quickly banged it out. Can't test it quickly.
__________________
=========================
Futz's Microcontrollers & Robotics
=========================
futz is online now  
Old 15th August 2008, 04:33 AM   (permalink)
Default

Quote:
Originally Posted by futz View Post
Code:
	movf	Data,W
	andlw	b'11110000'
	movwf	temp1
	movf	PORTB,w
	andlw	b'00001111'
	iorwf	temp1,w
	movwf	PORTB
Hmm... Is that right? Just quickly banged it out. Can't test it quickly.
OK thanks for your help.It will work.
Suraj143 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Upper Cut off Frequency in Common Emitter Amplifier Callo1234 General Electronics Chat 4 18th April 2008 05:13 PM
sample frequency and upper limit Gaston General Electronics Chat 20 10th June 2007 10:22 PM
masking pcb through dipping - is this effective? spyghost Electronic Projects Design/Ideas/Reviews 9 6th May 2004 01:01 PM



All times are GMT. The time now is 04:14 AM.


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

eXTReMe Tracker