Searching \ for 'Bank switching ?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/mems.htm?key=bank
Search entire site for: 'Bank switching ?'.

Truncated match.
PICList Thread
'Bank switching ?'
1998\01\19@125242 by Najemy, Daniel

flavicon
face
Greetings - hoping someone would be able to help here...

I have a sub-routine that looks as follows:

bsf     STATUS,RP0      ; switch to bank 0
bcf     PORTC,6          ; light an led hanging off port c
bcf     STATUS,RP0    ; switch back

when I modify it as follows....
bsf     STATUS,RP0      ; switch to bank 0
bcf     PORTC,6          ; light an led hanging off port c
bsf     PORTC,2         ;
bcf     STATUS,RP0    ; switch back


I can't seem to write to either bit 2 or 6 on port C


Can anyone see what's wrong here?
I have bits 2 & 6 setup as ouputs...and I have the SSP enabled.

Thanks in advance. :)
Daniel Najemy - Numaliine Power Systems

1998\01\19@145832 by Bobby R. Bramlett

flavicon
face
{Quote hidden}

I am not sure why the bit set for pin 2 does not work.  But you need to
remember that the ports are read-modify-write ports.  In other words the pic
looks at the current state of the pins not the port latch and then masks the
appropriate pins to get the new value.  If the RC constant is to long when
trying to modify the PORTC,6 then when you do the bit set on the PORTC, 2
the current value of PORTC,6 is going to be written back.  In other words if
you set PORTC,6 low and it takes 1 ms for the led to drop low when you do
the bit set PORTC,2 the PIC will read that PORTC,6 is high and write a high
back out to it.  If there is a RC delay for setting the LED low then add a
couple of NOPs between the bcf PORTC,6 and bsf PORTC,2.

Bob

1998\01\19@161708 by Harold Hallikainen

picon face
On Mon, 19 Jan 1998 12:03:53 -0500 "Najemy, Daniel"
<spam_OUTDNajemyTakeThisOuTspamIMPS0014.US.DG.COM> writes:
>Greetings - hoping someone would be able to help here...
>
>I have a sub-routine that looks as follows:
>
>bsf     STATUS,RP0      ; switch to bank 0
>bcf     PORTC,6          ; light an led hanging off port c
>bcf     STATUS,RP0    ; switch back
>
>when I modify it as follows....
>bsf     STATUS,RP0      ; switch to bank 0
>bcf     PORTC,6          ; light an led hanging off port c
>bsf     PORTC,2         ;
>bcf     STATUS,RP0    ; switch back
>
>


       Looks like the classic read-modify-write without allowing enough
time for the port I/O lines to settle.  Recall that reading a port
actually reads the port pins, not the output register.  So...  if w is
available, you might do something like

       bank0           ; I have a macro for this...
       movfw   portc   ; Get current port settings in w
       andlw   b'10111111' ; Clear bit 6
       iorlw   b'00000100' ; Set bit 2
       movwf   portc   ; Update the port

Harold

1998\01\19@164807 by davewave

flavicon
face
Daniel,

This code configures the two pins to be outputs:

bsf    STATUS,RP0    ; switch to bank 1
bcf    PORTC,2       ; actually sets bit 2 of TRISC
bcf    PORTC,6       ; actually sets bit 6 of TRISC
bcf    STATUS,RP0    ; switch back to bank 0

Now, in your subroutine you just need to turn on/off the individual
pins:

bcf    PORTC,2       ; light up LED
                    ; no need to mess with the RP0 bit

Your code was twiddling bits in the TRISC register instead of PORTC!

Dave Sorlien


Najemy, Daniel wrote:

{Quote hidden}

1998\01\19@175209 by TONY NIXON 54964

flavicon
picon face
> I have a sub-routine that looks as follows:
>
> bsf     STATUS,RP0      ; switch to bank 0
> bcf     PORTC,6          ; light an led hanging off port c
> bcf     STATUS,RP0    ; switch back
>
> when I modify it as follows....
> bsf     STATUS,RP0      ; switch to bank 0
> bcf     PORTC,6          ; light an led hanging off port c
> bsf     PORTC,2         ;
> bcf     STATUS,RP0    ; switch back
>
>
> I can't seem to write to either bit 2 or 6 on port C
> Can anyone see what's wrong here?
> I have bits 2 & 6 setup as ouputs...and I have the SSP enabled.
>
You are writing to the TRIS registers for these ports, not writing to
the ports themselves.

bsf STATUS,RP0 = Bank 1, not Bank 0.

The first example probably worked because the portC bit 6 is already
set = 0 when you set the TRIS register to an output.

In the second example you are setting PortC bit 6 as an output, and
PortC,2 as an input.

Tony

For the beginner....
PicNPoke Multimedia 16F84 Simulator Assembler, and Tutorial.
Now with PicNPlay circuit simulator.
Plus animated Address Mode Tutor.

http://www.dontronics.com/picnpoke.html

1998\01\20@114803 by Najemy, Daniel

flavicon
face
Thanks Harold - I'm certainly learning this the hard way - you solution
works really well. I was also switching to the incorrect bank as well.

:)

Daniel Najemy - Numaliine Power Systems

> {Original Message removed}

1998\01\20@162003 by Harold Hallikainen

picon face
On Tue, 20 Jan 1998 11:45:35 -0500 "Najemy, Daniel"
<.....DNajemyKILLspamspam@spam@IMPS0014.US.DG.COM> writes:
>Thanks Harold - I'm certainly learning this the hard way - you
>solution
>works really well. I was also switching to the incorrect bank as well.
>

       No problem, Daniel.  I KNEW of this problem yet still did not see
it in some of my own code.  In my case, it appeared that an interrupt
routine was corrupting w even though the context (including w) was saved
on going into an interrupt.  I posted the code on the list and someone
pointed out that my disableIRQ actually just put a delay in there to
allow the port to settle.  The problem wasn't the interrupt at all.  So I
changed to code similar to what I sent you.
       I've also done a few macros so I don't have to remember which bit
does what for banks and interrupts.  I think they're real useful.  Here
they are...

;----------------------MACRO
DEFINITIONS------------------------------------------------
DisableIRQ macro
       local DIRQloop          ; Declare local symbol in macro
DIRQloop
       bcf     intcon,gie      ; disable global interrupts
       btfsc   intcon,gie      ; make sure it's clear
       goto    dirqLoop        ; if not, go clear again
       endm
EnableIRQ macro
       bsf     intcon,gie      ; set global interrupt enable
       endm

 cblock                        ; reserve ram for save and restore
context
       isrW            ; Hold registers during ISR
       isrStatus
       isrFSR
 endc
SaveContext macro
; Save register context for isr.  Swaps swap high and low halves of f
with the result going either
; back to f or to w.  Swap is used here because they affect no status
bits.
       movwf   isrW            ; Save W
       swapf   status,w        ; get status in W (including bank
select bits) swapping hi/lo halves
       bcf     status,rp0      ; force to bank 0
       movwf   isrStatus       ; and save swapped status
       movf    fsr,0           ; Get fsr in w
       movwf   isrFSR          ; and save it
       endm
RestoreContext macro
       movf    isrFSR,0        ; get old fsr
       movwf   fsr             ; and restore it
       swapf   isrStatus,w     ; get old status (including bsr
bits) in w, swapping back to normal
       movwf   status          ; restore it
       swapf   isrw,1          ; swap halves in isrw making
them backwards
       swapf   isrw,0          ; swap back to forward and in
W without affecting status
       endm
Bank1   macro
       bsf     status,rp0      ; Set bank select bit
       endm
Bank0   macro
       bcf     status,rp0      ; Clear bank select bit
       endm



Harold

1998\01\20@170718 by Najemy, Daniel

flavicon
face
Excellent, and thanks! These macro's will come in very handy.

Daniel Najemy - Numaliine Power Systems

> {Original Message removed}

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