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
 
Thread Tools Display Modes
Old 17th April 2008, 09:11 AM   (permalink)
Experienced Member
desijays is on a distinguished road
Default Weird anomalies

Code:
          org          000h
          goto        main

          org          200h
main
          nop
          
          banksel    trisb
          movlw      h'ff'
          movwf     trisb
          
          banksel    portb
          clrf     portb

          goto        $

          end
I just wanted to clear Portb before getting ready for receiving input.
I checked and double checked with the code and couldn't find anything I might have missed, but no matter what, I couldn't find out why the portb register is not setting all of its bits. I checked the data sheet to see if in case port b has any special requirements or something. Couldn't find anything there. Am I wrong somewhere?

Thank you
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 17th April 2008, 09:25 AM   (permalink)
Experienced Member
 
ericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to behold
Default

hi,
Whats the PIC type.?

How have you checked the PORTB port pins to know they are not cleared.?
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Nigel's: www.winpicprog.co.uk/
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline   Reply With Quote
Old 17th April 2008, 09:29 AM   (permalink)
Experienced Member
eng1 is a glorious beacon of lighteng1 is a glorious beacon of lighteng1 is a glorious beacon of lighteng1 is a glorious beacon of light
Default

You configured all pins of PORTB as inputs. The value of each bit of the PORTB register depends on the external voltage you apply to each pin.
Clearing the PORTB register does not affect the state of the output pins.
eng1 is offline   Reply With Quote
Old 17th April 2008, 09:38 AM   (permalink)
Experienced Member
desijays is on a distinguished road
Default

Quote:
Originally Posted by ericgibbs
hi,
Whats the PIC type.?

How have you checked the PORTB port pins to know they are not cleared.?
hello eric

Im using a PIC16f877a controller.

Im using the simulator available in MP-LAB. And when I step through the code, the port b register never seems to clear. Atleast that is what the simulator shows.
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 17th April 2008, 09:42 AM   (permalink)
Experienced Member
desijays is on a distinguished road
Default

Quote:
Originally Posted by eng1
You configured all pins of PORTB as inputs. The value of each bit of the PORTB register depends on the external voltage you apply to each pin.
Clearing the PORTB register does not affect the state of the output pins.
hello eng

Im not trying to effect any change on the portb output pins. I just want to clear the portb "latch register", so i can prepare it for receiving input.

Thank you
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 17th April 2008, 10:11 AM   (permalink)
Experienced Member
 
ericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to beholdericgibbs is a splendid one to behold
Default

Quote:
Originally Posted by desijays
hello eric

Im using a PIC16f877a controller.

Im using the simulator available in MP-LAB. And when I step through the code, the port b register never seems to clear. Atleast that is what the simulator shows.
hi,
It clears OK in my OSoft sim, I'll try it later in MPLAB.
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Nigel's: www.winpicprog.co.uk/
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline   Reply With Quote
Old 17th April 2008, 01:11 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

Quote:
Originally Posted by desijays
hello eng

Im not trying to effect any change on the portb output pins. I just want to clear the portb "latch register", so i can prepare it for receiving input.

Thank you
You don't need to clear the port B latch register. It is not like other processors where you have to write 1 to enable input. Just write 0xff to the TRIS register and the port will be input.

Mike.
Pommie is online now   Reply With Quote
Old 18th April 2008, 12:46 AM   (permalink)
Experienced Member
 
donniedj has a spectacular aura about
Default

Also the ports are not fully implemented in the simulator and hence you will not see change on the port. There is some method of designing a stimulus file but I never cared for it. Sure someone else can assist with this.
__________________
I can still log in! Delete my account and all my post now.
donniedj is offline   Reply With Quote
Old 18th April 2008, 03:39 AM   (permalink)
Experienced Member
kchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of light
Default

To simulate inputs in MPLAB Sim, you need to use the Stimulus Controller. You assign actions to the pins you want and click the "fire" button when you want the action to occur. I find the toggle option to be the most useful:
Attached Images
File Type: png Stim.PNG (47.7 KB, 12 views)
__________________
--- The days of the digital watch are numbered. ---
kchriste is offline   Reply With Quote
Old 18th April 2008, 08:17 AM   (permalink)
Experienced Member
desijays is on a distinguished road
Default

Quote:
Originally Posted by Pommie
You don't need to clear the port B latch register. It is not like other processors where you have to write 1 to enable input. Just write 0xff to the TRIS register and the port will be input.

Mike.
Lets assume all the bits in trisb are set and therefore portb is now input. But a few bits in my portb latch are already set from some insignificant previous instruction.

Wouldn't that be considered an input signal to the controller even though the signal did not originate externally?

I hope that was clear

Thank you
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 18th April 2008, 08:22 AM   (permalink)
Experienced Member
desijays is on a distinguished road
Default

Quote:
Originally Posted by donniedj
Also the ports are not fully implemented in the simulator and hence you will not see change on the port. There is some method of designing a stimulus file but I never cared for it. Sure someone else can assist with this.

what do you mean ports are not fully implemented in the simulator, may i ask?

Do you mean the simulator does not simulate the controller accurately and that MPLAB is an incomplete program?
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 18th April 2008, 08:39 AM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

Quote:
Originally Posted by desijays
Lets assume all the bits in trisb are set and therefore portb is now input. But a few bits in my portb latch are already set from some insignificant previous instruction.

Wouldn't that be considered an input signal to the controller even though the signal did not originate externally?

I hope that was clear

Thank you
When you read from a port, it always returns what is on the pins. Even if the port is set to output, reading it returns the value on the pin. This can sometimes cause a problem if the pin is highly loaded, it will read back as a zero even though the latch is set high. This is (sometimes) the cause of the RMW problem with the 16 series pic chips.

Mike.
Pommie is online now   Reply With Quote
Old 18th April 2008, 09:39 AM   (permalink)
Experienced Member
desijays is on a distinguished road
Default

Quote:
Originally Posted by Pommie
When you read from a port, it always returns what is on the pins. Even if the port is set to output, reading it returns the value on the pin. This can sometimes cause a problem if the pin is highly loaded, it will read back as a zero even though the latch is set high. This is (sometimes) the cause of the RMW problem with the 16 series pic chips.

Mike.
So conclusively, what you're saying is, if my tris register is configured for input, it doesn't matter whether portb latch bits are set or not, cos the input will always be read from the pins and not the latch bits.

Am I right mike?

Thank you
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Old 18th April 2008, 09:55 AM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

You are correct. But remember, if your port is configured as output it will still read the pins. A highly loaded output pin with it's latch bit set can still read back zero.

Mike.
Pommie is online now   Reply With Quote
Old 19th April 2008, 06:28 AM   (permalink)
Experienced Member
desijays is on a distinguished road
Default

Quote:
Originally Posted by Pommie
You are correct. But remember, if your port is configured as output it will still read the pins. A highly loaded output pin with it's latch bit set can still read back zero.

Mike.
I'll keep that in mind. Thanks mike
__________________
A scientist trys to see the world the way it is
An enginneer trys to see a world that has never been
desijays is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
weird reading on the multimeter. maor General Electronics Chat 3 14th July 2007 10:16 PM
weird pic code problem Fletcher Micro Controllers 9 13th October 2004 02:39 PM
Infrared receiver acting weird Lac General Electronics Chat 16 10th August 2004 02:36 PM
weird transformer smack_whore General Electronics Chat 0 1st April 2004 11:48 AM
Weird 12F629 GPIO setting? eirikr Micro Controllers 3 14th March 2004 04:08 AM



All times are GMT. The time now is 02:39 AM.


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