Setting up PORTA as input..nightmare!!

Thread Starter

monkles

Joined Aug 6, 2009
9
Hey guys,

Im using a PIC16f627 for a little project im doing. I need to use pins RA0-RA4 as inputs. I have TRISA, CMCON and PORTA set up correctly but its just not working. I switched my circuit around to see if it was a problem with my code but its not as it works perfectly on PORTB. I have four 10k resistors connected to the four pins. I have no idea where im going wrong. Any help would be greatly appreciated.
 

n9352527

Joined Oct 14, 2005
1,198
What value did you set CM<2:0> in CMCON to? 111? Are you writing to the correct CMCON's bank (bank 0)?

Posting the source code would be useful.
 

Thread Starter

monkles

Joined Aug 6, 2009
9
Well this is the bit of main that uses PORTA and my configuration settings.

__CONFIG(XT & UNPROTECT & DATUNPROT & WDTDIS & PWRTDIS & MCLRIO & BORDIS & LVPDIS);

void main ()
{

int i = 0;
int Delay;
int Cycles;
int DelayOff;



TRISB = 0b11111111;
T1CON = 0b00110001;
RBPU = 0;

CMCON = 0x07;
TRISA = 0x11101111;

while(1)
{


Cycles = PORTA & 0b00001111;
Cycles = Cycles ^ 0x0F;

while( i < Cycles )
{
//rest of main here
 

Thread Starter

monkles

Joined Aug 6, 2009
9
Yes sorry I wrote that wrong. But it still doesnt work! I'm using a thumbwheel on that port but for some reason its not working. I tried setting the pins on PORTA high and low manually and it works. It works on PORTB too.
 
Last edited:

Ruptor

Joined Apr 26, 2009
44
Just a thought and I don't know if it applies to your chip but the PICs have analogue inputs on port A and if you don't disable them correctly then you will get funny results on the pins.
 

fanie

Joined Jan 20, 2007
63
There was an issue with the 16F627, they changed something, I distinctly remember someone mentioned such an issue.

Why don't you use a newer pic ? They are so much better and cheaper as well.

If a pin is made an analog input on the pics, and it is allowed to rise higher than the supply voltage, the pic freezes. Always define all the ports and the pins pins, even the unused ones and make them outputs.

If I remember right binary is written as

TRISB = b'11111111

0X means it is a hex value
 
Last edited:
Top