Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PORTB strange behaviour

Status
Not open for further replies.

preview

New Member
Hi all,

I am trying to use a glcd (ks1080) connected to a 16F887 (the board that is shipped with the pickit2).
After spending hours to find out why the code that is suppose to work doesn't work, I looked at the PORTB's behaviour :
if I do
(TRISB = 0)
bsf PORTB,5 ; this works, the pin5 = 1
bsf PORTB,6 ; pin6 = 1 BUT pin5 comes back to 0 !!!!

Anybody got any idea ?

Here is how it is connected to the glcd :
PORTD = D0..7
PORTB.1 = E
PORTB.2 = RW
PORTB.4 = RS
PORTB.5 = CS1
PORTE.0 = CS2
PORTE.1 = RST

Any idea ??

Thx and merry Xmas
 
This is the famous RMW (read modify write) "feature" of the 16 series pics. You can read an explanation of the problem in the data sheet. The crux of it is that if you set a pin using bsf, the port is read, the bit is set and the port is written back to. If another pin is in transition from a previous write (or the pin is heavily loaded) it gets read as zero. A simple solution is to write to a shadow register (ram) and transfer the ram copy to the port.

Mike.
 
Having thought a little longer, I think you may have a different problem. The CS lines should not load the pin enough to cause the problem you describe. Are you sure the pin (B5) is not shorted to ground or set to analogue (pins set as analogue read back as zero).

I have a current project that has a GLCD and an 886 that has similar connections and I haven't had any problems.

Mike.
 
Thanks Mike
That explains the problem I had with a bar graph.
This would not set PORTB,5
FiveLEDs
bsf PORTB,5
bsf PORTB,3
bsf PORTB,2
bsf PORTB,1
bsf PORTB,0
goto LEDsSet
But this did
FiveLEDs
bsf PORTB,3
bsf PORTB,2
bsf PORTB,1
bsf PORTB,0
bsf PORTB,5 ;Had to set bit 5 last WTF ???
goto LEDsSet
 
Status
Not open for further replies.

Latest threads

Back
Top