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.

[SOLVED] How to configure portc in pic 16f877a to input

Status
Not open for further replies.

Johnny Churne

Member level 5
Joined
Jun 5, 2015
Messages
83
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
554
Hello all my dear friend! I know can only make portA for input, but how to make PORTC for input?
 

Confused is me...

Easyrider83, you made a typo in post #2, it should have said "TRISC" not "TRISB" and in post #4 you have "PORTC" when it should be "TRISC" :|

The correct statement to make PORTC an input is "TRISC = 0xFF" or in assembler:
movlw 0xFF
movwf TRISC

Johnny Churne: when you say "it gives nothing", what do you mean? Making the port an input lets the PIC read data from it's pins in to the program, it shouldn't 'give' anything.

Brian.
 

my code:
Code:
 TRISC =0XFF
I will connect button to portc.
 

Hello all my dear friend! I know can only make portA for input, but how to make PORTC for input?

Which Compiler you are you using ? look here .

pic-microcontrollers-examples-in-assembly-language-chapter-03-fig3-1.gif


ook here for more information https://learn.mikroe.com/ebooks/picmicrocontrollersprogramminginassembly/chapter/io-ports/

Or

https://extremeelectronics.co.in/mi...purpose-digital-io-with-pic-microcontrollers/
 

I will connect button to portc.
Whichever way you connect it, make sure there is a resistor to pull the pin to the opposite state when the switch (button) is open. Simply disconnecting the pin through a switch wil not make it change to the opposite logic state.

Brian.
 
I am using proteus to simulate but it give not for input only portb can use for input.
 

If you really want to solve the problem, instead of saving words to give relevant details, you should consider posting both your code and your schematic.
 
here is my code
Code:
void main(){
 TRISC=0XFF;
 TRISB=0XFF;
 TRISD=0X00;
 PORTD=0;
 PORTC=0;
 PORTB=0;
 while(1){
 
    if(PORTC.RC0==0){
     PORTD=0X01;
    }
 
 }
}
the post not allow me to post the proteus, it said Invalid.
 

The "Proteus" project you mention is useless for most people who don't have it.
I would expect you realize that could add a snapshot of the circuit, instead.

- - - Updated - - -

Why are you setting on PORTC a default output value, just after defining it as input ? There are compilers that allow to dynamically change the corresponding TRIS values during program when used either as Input or Output without the need to explicitly do that in code.
 
Screen Shot 2016-07-27 at 10.39.57 PM.png
if portc allow to be input it would give the red pin but this is black
 

Unless adding a pullup resistor in parallel with the RC0 pin at the left side of the button, you'll read '0' in every read. Just tie it to the VCC bus, but this was already clearly explained on post #11.
 
Code:
 while(1){
 
    if(PORTC.RC0==0){
     PORTD=0X01;
    }
also consider what will happen if RC0 is not low. Are you expecting it to change the value on PORTD?

Convention is to use '0x' rather than '0X' to indicate a hexadecimal value, I'm not sure if all compilers will accept upper-case 'X'.

Brian.
 
Thanks for your kindness! I have to put pull low resistor then it works!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top