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.

Why does my PORTC change on its own?

Status
Not open for further replies.

kyru27

New Member
I've the following code:

Code:
#include "p18F4620.h"
 
 
#pragma config XINST=OFF
#pragma config OSC=INTIO67
 


 void main (void)
{

char tecla;

TRISC=0xAB;	

PORTC=0x40;

Nop();

if (PORTCbits.RC5==1)
{
tecla=2;
}

if (PORTCbits.RC3==1)
{
tecla=0;
}

if (PORTCbits.RC1==1)
{
tecla=8;
}

if (PORTCbits.RC0==1)
{
tecla=5;
}


	 
}

The problem is that with the register PORTC changes its value where it has their inputs from 0 to 1 seemingly as it feels like, despite the inputs being 0 all the time and having 0 measuring it with a polimeter.

I've also checked that if I kept measuring the input and GND continuosly the changes on this input are done right (it doesn't change as long as I don't make it to change). Anyone has an idea what this would be equivalent to?

Regards.
 
Do you have a pull-down resistor on each input, or have you left the inputs floating when no switch is pressed?

A floating input is likely to pick up mains hum, which would appear as a randomly changing input in your code.
 
Last edited:
When using single pins you'll find that " LATCbits.LATC2 = 1;", instead of "PORTC = 0x40;", will be more reliable.... In the datasheet look for "READ/MODIFY/WRITE"

You may need LATCbits.LATC4 and 6 aswell.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top