Configuring 16F916 for digital I/O


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81

    Default Configuring 16F916 for digital I/O

    Hi, I'm using a 16F916 for the first time. Using A0 and A1 for analog inputs, but everything else as digital I/O.
    Problem is that PortC.0 is locked LOW and C.1 is locked HIGH. Can't see why.
    Also Port A.3 and A.4 read as LOW all the time, but A2 works correctly.
    Been trolling the data sheet and trying various registers with no luck.
    I really need to use Port A2-4 as inputs, and Port C4-7 as outputs (and 0-3 for LCD data).

    Here's the setups I have so far:
    define LCD_DREG PORTC ' LCD data port is C
    DEFINE LCD_DBIT 0 ' LCD start bit = 0

    DEFINE LCD_RSREG PORTA ' LCD register port A
    DEFINE LCD_RSBIT 7 ' LCD register bit 0

    DEFINE LCD_EREG PORTA ' LCD enable port B
    DEFINE LCD_EBIT 6 ' LCD enable bit 1

    DEFINE LCD_BITS 4 ' LCD 4 bit drive
    DEFINE LCD_LINES 2 ' LCD 2 line mode

    DEFINE OSC 8 ' define clock speed for code
    OSCCON = %01110001 ' set clock 8 Mhz
    '+1 = Internal oscillator is used for system clock
    ' set up on chip ADC
    DEFINE ADC_BITS 10 ' Set number of bits in result ( 8 or 10 bits )
    DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
    ADCON0 = %10100001 ' bit0 AD converter is ON, BIT5 1 = VREF+ pin, bit7 1 = Right justified
    ADCON1 = %00000000 ' AD conversion rate clock (default)
    ANSEL = %00000011 ' PortA0 and A1 used by ADC (0=digital 1=analog)

    LCDCON = 0 ' bit 7 = 0 disable LCD
    OPTION_REG = %10000000 ' bit 7 = 1 disables portB pull-ups
    INTCON = 0 ' disable all interrupts

    TRISA = %00011111 ' set I/O directions (0 = output, 1 = input)
    TRISB = %11100000 '
    TRISC = %00000000 ' all outputs


    Any help would be much appreciated.
    "Do or do not, there is no try" Yoda

  2. #2
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Configuring 16F916 for digital I/O

    Found the PortC output issue - was a dumb typo! AAGH!
    Still trying to configure PortA3 and 4 as input. They still read as 0...
    "Do or do not, there is no try" Yoda

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: Configuring 16F916 for digital I/O

    Try adding ...

    CMCON0 = 7
    DT

  4. #4
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Configuring 16F916 for digital I/O

    OH yeah, forgot about that one! Tried it, but Port A.3 is still reading as zero.
    I'm using a push button to ground and 10K pull-up.
    I have spent the usual HOURS reading the spec sheet, and this is making me nuts.
    "Do or do not, there is no try" Yoda

  5. #5
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Configuring 16F916 for digital I/O

    NEVERMIND!

    I had set the voltage ref to use A.3 accidentally. DUH. It's always something stupid isn't it.

    Thanks Darrell
    "Do or do not, there is no try" Yoda

Members who have read this thread : 1

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