Author Topic: PIC16F1703 microcontroller - input pins always reads 0  (Read 1906 times)

0 Members and 1 Guest are viewing this topic.

Offline JoePTopic starter

  • Contributor
  • Posts: 37
  • Country: gb
PIC16F1703 microcontroller - input pins always reads 0
« on: October 26, 2018, 06:39:52 am »
Datasheet: http://www.farnell.com/datasheets/2137994.pdf?_ga=2.11177268.1643568016.1539016190-2008006305.1520009189

The input pins of my microcontroller seems to always be 0, regardless of the input voltage. Here is my code:
Code: [Select]
#pragma config FOSC = INTOSC
#include <xc.h>

void main()
{
    OPTION_REG = 0b00000011;
    OSCCON = 0b01111010;
    TRISC = 0x00;
    PORTC = 0x00;
    TRISA = 0xFF;
    while(1)
    {
    CLRWDT();
    if(PORTAbits.RA4)
        PORTC = 0xFF;
    else
        PORTC = 0x00;
    }
   
}
The LED on port C remains off, whether I connect the RA4 pin to the ground or VDD. However, using RA5 instead does work. What could be causing this? Let me know if there are any tests I should try.


« Last Edit: October 26, 2018, 06:57:05 am by JoeP »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2548
  • Country: us
Re: PIC16F1703 microcontroller - input pins always reads 0
« Reply #1 on: October 26, 2018, 07:38:40 am »
It appears to me that all the pins that have ADC capabilities are set as analog input by default.  Set register A to be all digital inputs (i.e. ANSELA=0).
 
The following users thanked this post: JoeP

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: PIC16F1703 microcontroller - input pins always reads 0
« Reply #2 on: October 26, 2018, 07:43:46 am »
Quote
1.1.6 ANALOG CONTROL
The ANSELA register (Register 11-4) is used to
configure the Input mode of an I/O pin to analog.
Setting the appropriate ANSELA bit high will cause all
digital reads on the pin to be read as ‘0’
and allow
analog functions on the pin to operate correctly.

Quote
REGISTER 11-4: ANSELA: PORTA ANALOG SELECT REGISTER
U-0 U-0 U-0 R/W-1/1 U-0 R/W-1/1 R/W-1/1 R/W-1/1

Analog inputs are enabled at power on and reset. To digital read RA4 you have to set ANSA4 low.
 
 
The following users thanked this post: JoeP

Offline JoePTopic starter

  • Contributor
  • Posts: 37
  • Country: gb
Re: PIC16F1703 microcontroller - input pins always reads 0
« Reply #3 on: October 27, 2018, 11:14:17 am »
Excellent, it's working now, thanks.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf