PIC16F676 I/O Problems.


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Question PIC16F676 I/O Problems.

    Hi,
    I am using a PIC16F676 and am having trouble with port A. I am using porta.1 as an input, or rather trying to. It always seems to be read as 0, no matter what state it is in.
    The data sheet mentions CMCON register, but I cant find any more information about it.

    Anyone know what to do?

    Regards

    Bob...

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The 676 has analog comparators & A/D which are all configured for analog on power-up.

    Place this in the top of your code.

    CMCON = 7 ' Turns off comparators
    ANSEL = 0 ' Turn off A/D
    TRISA.1=1 ' Make RA1 an input

    Now you can read the input on RA1.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks Bruce, but I need A/D on channel a0, all the other pins are I or O.

    Regards

    Bob

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    ANSEL configures port pins for A/D or digital.
    ANSEL = %00000001 ' RA0 = A/D, rest digital I/O.

    For ADCON0 & ADCON1 configuration options, see
    datasheet A/D section. It's very simple to setup.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Cool

    Thank you Bruce. I have figured it all out now, I think. Wont have time to test it for a day or two. I have:

    define OSC 20
    define adc_bits 10
    define adc_sampleus 50
    CMCON = 7 'turns off comparators
    ANSEL = 1 'channel 0 analog all others digital
    ADCON0 = 129 'right justified, vref = vdd, chan 0 active, A/D converter on
    ADCON1 = 96 'fosc/64 (20MHz osc)

    Once again thanks for your help.

    Regards
    Bob...

Similar Threads

  1. PIC12F683 Config Problems
    By Electroman87 in forum General
    Replies: 1
    Last Post: - 22nd April 2009, 08:18
  2. Replies: 4
    Last Post: - 17th April 2009, 08:56
  3. Input problems
    By ALFRED in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd July 2006, 21:02
  4. 16F877 universal PCB with I/O module
    By cupajoe in forum Schematics
    Replies: 12
    Last Post: - 3rd September 2005, 13:39
  5. USART problems
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 47
    Last Post: - 6th March 2005, 21:45

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