Problem with 16F688 and using PORTA as digital inputs - I'm pulling my hair out!


+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Problem with 16F688 and using PORTA as digital inputs - I'm pulling my hair out!

    I've been out of the loop for quite some time but I have a need for a small project. I'm using a 16F688 and trying to use PORTA to read digital values (button presses). I've read the data sheet and tried adjusting the code but nothing seems to work. I've stripped the code down to the bare minimum, even removing all of the analog stuff (I think), but it's still not working:

    Code:
    @ DEVICE PIC16F688, INTRC_OSC_NOCLKOUT,WDT_ON, PWRT_OFF, MCLR_OFF, BOD_ON,PROTECT_OFF           
          
    TRISA = 111111
    TRISC = 111111
    ANSEL =  000000
    CMCON0 = 000000    
    ADCON0 = 000000        
    DECREASEBUT VAR PORTA.3
    INCREASEBUT VAR PORTA.1
    ENTERBUT VAR PORTA.4       
    MODEBUT VAR PORTA.0
    LED VAR PORTC.1 
    
    Start:
    IF INCREASEBUT=0 THEN GOTO INCREASE
    GOTO START
    
    
    INCREASE:
    HIGH LED
    PAUSE 500
    LOW LED
    PAUSE 500
    GOTO START
    It's blinking the LED even though 5VDC is on A.1. The same goes for A.5, A.4 and A.0. When I press a button on A.3, the MCU resets as if the MCLR is enabled but I set MCLR to off. There is probably something simple I'm overlooking. Can anyone help me?
    Last edited by Christopher4187; - 14th June 2012 at 15:39.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,234

    Default Re: Problem with 16F688 and using PORTA as digital inputs - I'm pulling my hair out!

    Hi,
    To turn off the comparators on the 16F688 you should set CMCON0 to 7, not 0.
    That would explain RA0 and RA1 but not really RA4 & 5. ANSEL=0 should be correct.
    As for the MCLR/RA3 pin, make sure that your programmer isn't overriding your CONFIG settings.

    /Henrik.

  3. #3
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default Re: Problem with 16F688 and using PORTA as digital inputs - I'm pulling my hair out!

    And set your port C to output instead of input for your LED. Unless those are the two bits that get cut off.

    Test:
    TRISC 111100

    No, the two MSB get cut off with the editor if not in "source mode" A/A icon.
    Might as well set your C port to all outputs, unless you have some inputs on it.
    TRISC %00000000
    Last edited by ScaleRobotics; - 14th June 2012 at 16:00.
    http://www.scalerobotics.com

  4. #4
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Smile Re: Problem with 16F688 and using PORTA as digital inputs - I'm pulling my hair out!

    To turn off the comparators on the 16F688 you should set CMCON0 to 7, not 0.
    You're right. It solved the RA0 and RA1 problem. My issue was that I was playing with the ANSEL and CMCON0 commands at the same time and probably overlooked the fact that the CMCON0 problem was fixed but the ANSEL or some other command was still causing the problem so I moved right past it.

    As for the MCLR/RA3 pin, make sure that your programmer isn't overriding your CONFIG settings.
    That's exactly what it was. I moved all of my stuff to a new computer and there wasn't a check next to the "program configuration."

    That would explain RA0 and RA1 but not really RA4 & 5.
    RA4 was a miswire and RA5 didn't have a pullup resistor on it.

    Thanks for the help guys! I'm sure I'll be back with more questions as my project moves along

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts