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.

PIC port bits as input

Status
Not open for further replies.

Naumanpak

Member level 2
Member level 2
Joined
Nov 19, 2009
Messages
51
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Pakistan
Activity points
1,635
Hi,

I am trying to get my basics right for PIC microcontrollers, before going to interface to a keypad.


I need to know, how can I use a port pin as input. If I take output from an output port pin for eg,

TRISD.RD0=0;// declare output
PORTD.RD0=1//high

and use it as input to an input pin via wiring,

TRISD.RD1=1;//input

I don't get the results on performing any operation?


Please help me out experts!


cheers
 

Hi,

Yes, you can use most i/o pins as Digital Inputs or Digital Outputs in any combination.

You do not specify the chip you are using, but some i/o ports default to Analogue mode and must be Set to Digital mode before the Tris instruction.
The datasheet I/O Ports section details which i/o ports have an Analogue function.
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Hi, thank you for replying.

Currently I am using pic18f452,

I will check out the datasheet an respond again.


thanks again
 

IF your using a PIC Microcontroller have a look at the ADC section of the Data sheet. For PICs the Special function register to look at is: ADCON1. This regiser selects the pins as analogue or digital.
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Hi, thanks.

I have been trying for the last two days for nothing.

Can any one of you write me a simple code in c for 18f452 for portd(any 2 bits).

If input at bit7 is 1, bit6 goes high.

I just need to learn how to initialize pins as digital inputs.

I want to interface the keypad later, so I need to get my basics right.


thanks
 

syntax error in ur code.. this is the configuration ...
TRISD0=0; // PORTD pin 0 as OUTPUT

TRISD1=1; // PORTD pin 1 as INPUT...
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
I am using mikroc pic compiler and it works fine with the first syntax.

I need to know the port settings to accept digital input.

ANSEL and ITCON1 etc


thanks

Added after 1 hours 1 minutes:

ok, I have this code now.

It should toggle values of portd with changes in input at portb but.... it doesnt.

But portd remains high.



Code:
void main()
{
     ADCON1 = 0x0F;          // configure AN pins as digital
     TRISB  = 0xFF;          // set PORTB to be input
     TRISD  = 0x00;
     PORTD=0x00;
     PORTB=0x00;
     while(1)
     {

             if(PORTB==0x00)
             {
                 PORTD=0x00;
             }
             else
             {
                 PORTD=0xFF;
             }
     }
}

Please help me out....!!

Added after 24 minutes:

Hey! thanks all.

I finally got it working!

I wasn't using any pull resistor networks :)


thanks all again!! HELPED


Will you please help me out with this one as well??
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top