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 voltage problem

Status
Not open for further replies.

haxan

New Member
Hi i am using PIC18F4520 and using C18 compiler. I am having problem with my PORTB voltage level.

When i use:

TRISB = 0xF0;
PORTB = 0x00;

I get voltage 1.32 on pins [RB0-RB3] and 0.32 on pins [RB4-RB7]

Should this be happening ? I want either 5v or 0v.

Also could this be due to some weak pull up or anything ?

I want to add a keypad on this port so the RB7-RB4 are input pins.

One more question, which is better to use LAT or PORT while manipulating with pins on microcontroller?
 
sorry wrong message
 
Last edited:
Hi, writing to PORT or LAT is the same thing as can be seen from the data sheet picture attached here. A Write on a PORTx or a LATx results in changing the output of the port pin physically ( if the pin is configured as an output). A read however on the LATx register will result in the last written value and not the actual logic present on the port pin. Read description in 10.1 of datasheet.

Now about you query regarding the voltage on pins, the voltage on the last nibble of PORTB is near 0 because you have configured them as outputs and are setting them LOW. For the 0.32 volts, have you got a 0.1u capacitor between the power lines? For the upper nibble part, they can not be written to since they have been configured as inputs, and also you have not turned on the pull ups. Its just an arbitrary voltage.


Have you configured them as digital pins for them to be used for the keypad?
 

Attachments

  • init..JPG
    init..JPG
    23.9 KB · Views: 147
Last edited:
Thank you wond3rboy, From what i understand, if i want to read values from pins, i should use PORT rather than LAT (as LAT returns last stored value). Yes i have a 0.1u cap between pin 11 and 12.

Why is the voltage on PIN near zero and not actually zero when i am setting them as outputs and giving them 0 logic level.
I thought PORTB was already digital pins (hhee now i looked it up).

Can you please tell me how to turn off PORTB pins from analogue to digital while using pin A0 as analogue?

This is what i am using so far:
Code:
ADCON0 = 0x00;
ADCON1 = 0x0E;
ADCON2 = 0b10001101;
ADCON0bits.ADON = 1;
 
It can be done using the ADCON1 register but you should keep in mind that you just cant make a pin digital and analog at your desire, The AD converter module refers to pins as AN0, AN1 and so on i-e channel 0, channel1 which in fact are not necessarily related to the pins(in order from PortA onwards and in numbers there off). For making all pins digital except A0, you have written correctly in the program snippet you gave above.

ADCON1=0x0E

Page 226 of Datasheet for this.

PS: PORTB is not all digital on Power UP.
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top