Searching \ for '[PIC] 12f629 bsf function' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: '12f629 bsf function'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] 12f629 bsf function'
2006\05\24@125122 by Goran Hosinsky

picon face
I am trying to set selected bits in GPIO using
bsf GPIO, n   where n can be 0,1,2,4
The selected bit gets set ok but any bit which is
already on is cleared at the same time. Why is
this - and how should I do to set and clear bits
individually?
test code: bit 0 blinks once and then bit 1 is set:

        bsf     GPIO,0
        call    delay
        bsf     GPIO,1
loop    goto    loop

Goran

2006\05\24@130220 by Jan-Erik Soderholm

face picon face
Goran Hosinsky wrote :

> test code: bit 0 blinks once and then bit 1 is set:
>
>          bsf     GPIO,0
>          call    delay
>          bsf     GPIO,1
> loop    goto    loop

That can't be a full test-case !
What is connected to the pins ? And how ?
How long is "delay" ?
What does "blinks" mean ?

Regards,
Jan-Erik.



2006\05\24@131817 by Wouter van Ooijen

face picon face
> I am trying to set selected bits in GPIO using
> bsf GPIO, n   where n can be 0,1,2,4
> The selected bit gets set ok but any bit which is
> already on is cleared at the same time. Why is
> this

google (or search http://www.piclist.com) for read-modify-write problem

I have probably mentioned and explained it somewhere in http://www.voti.nl/swp.

>  - and how should I do to set and clear bits
> individually?

use a shadow register (google will explain)

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu


2006\05\24@143203 by Steve Smith

flavicon
face
Goran:
Wouter explains it well
Use a shadow register as below

For instance:-

Bsf        PORT_A,0        ; PORT_A is the name of the shadow register for GPIO
(A)
Movfw        PORT_A        ; get the shadow reg
Movwf        GPIO                ; then transfer the whole reg to the port
Call        delay
Bsf        PORT_A,1
Movfw        PORT_A
Movwf        GPIO
Call        delay

Bcf        PORT_A,0        ; PORT_A is the name of the shadow register for GPIO
(A)
Movfw        PORT_A        ; get the shadow reg
Movwf        GPIO                ; then transfer the whole reg to the port
Call        delay
Bcf        PORT_A,1
Movfw        PORT_A
Movwf        GPIO
Call        delay


Goto        $                ; stop here

This will fix any read modify write problems that maybe causing the pins to
become unset its straight line code and can be simplified by the following

Bsf        PORT_A,0        ;on PORT_A is the name of the shadow register for
GPIO (A)
Call        Update_port
Bsf        PORT_A,1
Call        Update_port

Bcf        PORT_A,0        ;off
Call        Update_port
Bcf        PORT_A,1
Call        Update_port

Update_port
Movfw        PORT_A        ; get the shadow reg
Movwf        GPIO                ; then transfer the whole reg to the port
Goto        delay

Goto        $                ; stop here

The two code bits do the same thing but the second set uses less program
space the example turns on led 0 then led 1 then turns off led 0 then led 1
but uses the update port section four times.
Regards
Steve

{Original Message removed}

2006\05\24@160048 by Dwayne Reid
flavicon
face
At 10:51 AM 5/24/2006, Goran Hosinsky wrote:
>I am trying to set selected bits in GPIO using
>bsf GPIO, n   where n can be 0,1,2,4
>The selected bit gets set ok but any bit which is
>already on is cleared at the same time. Why is
>this - and how should I do to set and clear bits
>individually?
>test code: bit 0 blinks once and then bit 1 is set:
>
>          bsf     GPIO,0
>          call    delay
>          bsf     GPIO,1
>loop    goto    loop

Hi there, Goran.

I suspect that your problem is caused by the default setting in the
CMCON register.  The default power-up settings configure ports GPIO,0
and GPIO,1 as analog inputs.  This means that they will always read
as a logic 0 when read.

Others have mentioned R-M-W problems and that is exactly what this
is.  However, the easy cure (assuming that you are using the internal
RC oscillator at 4 MHz) is to simply load the value of 0x07 into
register CMCON.

Hope this helps.

dwayne

--
Dwayne Reid   <spam_OUTdwaynerTakeThisOuTspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 22 years of Engineering Innovation (1984 - 2006)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

More... (looser matching)
- Last day of these posts
- In 2006 , 2007 only
- Today
- New search...