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:
> 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
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
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
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.
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.