Can't get RA0 to read inputs?!?


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Default Can't get RA0 to read inputs?!?

    I'm pretty sure I've gone over this problem many times now and just can't figure out what's wrong. I can't get a simple input to register a button press.


    I've got the button running straight from Vcc to the input with a 10k pull down on the output. I've put a scope probe right on the metal of the input pin itself and it's showing a very clean 5v on that pin when pressing the button so I know the circuit is good. The rest of the funtions (flash LED's) works fine also so I know the PIC is running.

    I want the program to do something different when I startup with a button already pressed. Here's what I'm doing to test and no matter what I do, it's just not working.

    The device is 16F684


    Code:
    define OSC 20       'Set PBP Osc clock to 20Mhz
    
    CMCON0 = 0     'Turn off comparators, force set to 0 (off)
    
    ANSEL = 0       'Turn off analog input for ports, set digital I/O
    
    TRISA.0 = 1     'RA0 as Input
    TRISA.1 = 1     'RA1 as Input
    TRISA.2 = 1     'RA2 as Input
    
    TRISC.0 = 1     'RC0 as Input
    TRISC.1 = 0     'RC1 as Output
    TRISC.2 = 0     'RC2 as Output
    TRISC.3 = 0     'RC3 as Output
    TRISC.4 = 0     'RC4 as Output
    TRISC.5 = 0     'RC5 as Output
    
    bpower VAR PORTA.0     'Power button RA0
    boption VAR PORTA.1    'Option button RA1
    
    Startup:
      PAUSE 1000
      IF PORTA.1=0 THEN
        HIGH powerled
      ENDIF
      IF PORTA.1=1 THEN
        HIGH linkled
      ENDIF

    No matter what I do, the powerled comes on, but Can't ever make the linkled come on (again it does work, later in the code I have it strobe between them and that works fine).

    I've tried the above code with PORTA.1, with extra spaces between the = sign, using "bpower" and "boption" instead of the actual port names.

    I've got the ANSEL set to 0 so they should be in digital mode. I've gone over all the other registers in the data sheet (noted in the I/O port section) and all of them seem to be where they should be.

    Very frustrating. Please help. It's always something dumb that cuases the biggest troubles.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    define OSC 20       'Set PBP Osc clock to 20Mhz   <----- use DEFINE not define
    CMCON0 = 0     'Turn off comparators, force set to 0 (off)
    Download and double-check your 16F684 datasheet (DS41202F, Section 8.2, Figure 8-5, Page 58, block in lower right corner).

    Common problem, trips me up about every other month on one project or another...

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Well according to my Datasheet CMCON=0 doesn't turn the Comparators OFF and it doesn't do much for setting those pins Digital either! Try a different mode... hint... Page 58 is a good place to look... bah - skimask wins...

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    EDIT: AH... everybody at the same time please
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    define OSC 20 'Set PBP Osc clock to 20Mhz <----- use DEFINE not define
    DEFINE is not case sensitive, but the text to it's right edge yes.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Piece of @#$#@!!!


    Well that was easy enough. Stupid pic.

    I was about 3 cuss words away from going out for cigarettes. I've been spinning my wheels on this problem since early yesterday morning. It seems having a note about this somehwere in the oh...... PORTA section would have been helpful. "Confure them as inputs this way, disable the ananlog ANSEL, yep, and oh by the way.... the comparators are installed to be in your way by default, make sure you set that register also". Blah!!


    Okay, thanks guys - and thanks so much for the quick response. I really was at my witts end here. I was starting to wonder if I had a bad batch of PIC's or something, or if I'd managed to zap them somehow.

    It's all good.


    BTW for anyone else reading this:

    CMCON0 = %00000111 'Turn off comparators (CMCON0.0:2 = 111)

    is the solution

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kevj View Post
    Piece of @#$#@!!!
    Well that was easy enough. Stupid pic.
    I was about 3 cuss words away from going out for cigarettes.
    If it was me, I'd go out for a smoke break anyways...whether the problem was fixed or not...and keep cussin', regardless...

    CMCON0 = %00000111 'Turn off comparators (CMCON0.0:2 = 111)
    Keep your eyes on that and the ANSEL as you move thru the various chips. They change a bit here and there.

Similar Threads

  1. Cleaning up code
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2009, 07:14
  2. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  3. Q: using MCLR for Input on 12F683
    By picster in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 31st January 2009, 15:25
  4. How to Read 6 Inputs anytime ?
    By iugmoh in forum General
    Replies: 9
    Last Post: - 20th February 2008, 12:37
  5. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 06:34

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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