Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 26th December 2007, 01:25 PM   (permalink)
Question PORTB strange behaviour

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
preview is offline  
Old 26th December 2007, 01:31 PM   (permalink)
Default

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.
Pommie is online now  
Old 26th December 2007, 02:42 PM   (permalink)
Default

Thx Mike !
preview is offline  
Old 26th December 2007, 02:57 PM   (permalink)
Default

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.
Pommie is online now  
Old 26th December 2007, 04:02 PM   (permalink)
Default

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
__________________
C:\WHUT ?
Beware the asterisk *
ClydeCrashKop is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Problem with LCD code? spondootre Micro Controllers 15 29th April 2008 10:15 AM
DS1302 with PIC16f877 program RasCreationKing Micro Controllers 28 3rd May 2007 01:03 PM
Validating Code Without PIC burg Micro Controllers 4 22nd April 2007 05:14 PM
Very strange problem with portb in 16F628 patroclus Micro Controllers 3 2nd December 2005 02:20 PM
MPLAB strange behaviour? RGBrainbow Micro Controllers 0 22nd June 2005 08:21 PM



All times are GMT. The time now is 03:50 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker