Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Reading PORTS of a PIC

Status
Not open for further replies.

srija

Member level 1
Joined
Oct 26, 2011
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Bangalore
Activity points
1,567
hi...

I have a small question about reading the ports of the PIC microcontoller??

I am using a breadboard for connecting the pic with external devices.
I am trying to read the data from one port and writing that to the other port.

for this i am using simple wires directly connecting the 5v(logic 1) and 0v(logic 0) to a port and blinking the leds on the other port to display same data.

But i am not getting the output...if i mention some value to the port in program i am getting the output.

is it a correct way of reading???
will the pic reads the data in this way???

Thanks in advance if any replies..........
 

are you doing the program in c or assembly language?
What is the program you did in micro-controller
 

There meight be couple of possiblities.....
Check and try the following -
1) you need to initialize the port correctly I mean input port and output port kind of staff
2) You need to also see the ports are digital or analog in PIC
3) When you are reading a input port port read bitwise and get the same bit assignment to output port bit
4) May debug mechanism using either UART or Using Programmer PIC Kit 2

Also, if possible put the code or send the code... I can help in it is in C language ....

Good Luck
 

I am using PIC18F4550 and Mplab C programming my code is
void main()
{
TRISD = 0x00;
TRISB = 0xFF;

LATD = PORTB;

while(1)
{
LATD = ~LATD;
Delay10KTCYx(100);
}

}
 

I think you are using PORTB as input port so first thing that you need to do is PORTB=0x00; and if you are using PORTD as an output you need to declear PORTD=0XFF;

Make this modification after TRISD = 0X00 and TRISB =0XFF line.....

it should work......

Good Luck
 

Yup, pis 0 through to 4 of PORTB are multiplexed with analog peripherals and default option is that these peripherals are on. You need to use ANSEL register to turn off analog features for AN8 through to AN12.

btw. I don't get why is that a default option. I've also pulled my hair off many times because of that 'feature'...
 

btw. I don't get why is that a default option. I've also pulled my hair off many times because of that 'feature'...
Noise and electrostatic protection! All unused pins must be configure as analog inputs. This is a rule.
 

Hi.

I am not pretty sure about your port logic high and logic 0 connection. Keep in mind every port pin has a limited sink and source current that must be considered therefore apposite resistors must be used for pull up and pull down.

If you directly connect the 5v to the port pin, certainly you will burn it out. Secondly put 0xFF value in the TRIS register of PORT B for making the PORT_B as input port similarly put 0x00 value in the TRIS register of PORT_D for making the PORT_D as output port.

For any further support feel free to contact me at amir.rashid7@gmail.com

Regards

Amir Rasheed
 

Hi everybody.........

I got the output of the designing.

Problem is I didnt made the ADCON1 = 0x0f; declaration.


Thanku to everyone.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top