| Home | Terms of Use | Site Map | Contact Us |
IndustryCommunity.com > Electrical and Electronic Community > Analog Circuit Design Forum > Message
Main Menu
Find

[ List Subjects ][ Main Page ]
[ View Followups ][ Post Followup ]

Subject: Re: bsf instruction in pic micro

Date: 08/15/00 at 9:47 PM
Posted by: Tony Kerr
E-mail: ozzyman69@hotmail.com
Message Posted:

In Reply to: bsf instruction in pic micro posted by Kristian Brinckmann on 08/08/00 at 12:16 AM:

Hi, Kristian

What does that code fragment do? It appears to set all bits in porta. I'm sure there are other ways to achieve the same result, depending on what you're trying to do. If you want a rolling 1 on port a, the code might look like:

start
clrf count ;clear count
bsf status,c ;and set the carry flag

loop
rlf count,1 ;rotate count left through carry
btfsc status,c ;gone all the way around?
rlf count,1 ;yes, do one more to get a 1 in LSB
movwf count,0 ;get count in W
movwf porta,1 ;put W to port a
goto loop ;and do it all again

What this does is rotate the "1" in the carry flag into the count register, then put it out to port a. The bits on port a will rotate, i.e

0000 0001
0000 0010
0000 0100
0000 1000
0001 0000 ... and so on.

Alternatively, to simply set all 8 bits in port a,

movlw 0xFF ;get FF into the w register (all bits set)
movwf porta ;move w register to port a

Or, inclusive OR all the bits in port a with FF.

movlw 0xFF ; put FF into the W register
iorwf porta,1 ; inlusive OR W (0xFF) with port a

Mind you my PIC code is a bit rusty. My code examples are (more or less) for a 12C508, and I think you're using a 16F84 or something, but you get the idea I hope.

Tony


Follow Ups:


Post a Follow-up:

Name:
E-Mail:
Subject:

Message to Post:

 

1999-2001 Sunlit Technology Co., Ltd. All rights reserved.