Setting up PORTA as input..nightmare!!

Discussion in 'Embedded Systems and Microcontrollers' started by monkles, Aug 6, 2009.

  1. monkles

    Thread Starter New Member

    Aug 6, 2009
    9
    0
    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.
     
  2. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    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.
     
  3. monkles

    Thread Starter New Member

    Aug 6, 2009
    9
    0
    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
     
  4. n9352527

    AAC Fanatic!

    Oct 14, 2005
    1,198
    4
    You are setting TRISA to 0x11101111, it should be 0b11101111.
     
  5. monkles

    Thread Starter New Member

    Aug 6, 2009
    9
    0
    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: Aug 6, 2009
  6. monkles

    Thread Starter New Member

    Aug 6, 2009
    9
    0
    I did indeed.
     
  7. Ruptor

    Active Member

    Apr 26, 2009
    44
    0
    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.
     
  8. fanie

    Active Member

    Jan 20, 2007
    63
    0
    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: Aug 6, 2009
  9. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,644
    759
    It is b'11111111' or eventually B'11111111' (which I always use).
     
Loading...