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.

Weird anomalies

Status
Not open for further replies.

desijays

New Member
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
 
hi,
Whats the PIC type.?

How have you checked the PORTB port pins to know they are not cleared.?
 
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.
 
ericgibbs said:
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.
 
eng1 said:
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
 
desijays said:
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.
 
desijays said:
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.
 
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.
 
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:
 

Attachments

  • Stim.PNG
    Stim.PNG
    47.7 KB · Views: 131
Pommie said:
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
 
donniedj said:
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?
 
desijays said:
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 said:
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
 
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 said:
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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top