16F1826 cannot get MCLR to act as an INPUT


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2009
    Posts
    50

    Default 16F1826 cannot get MCLR to act as an INPUT

    Here is my initialization code for 16F1826 . I want RA5 to act as an INPUT. However, when I check PortA.5 no matter if it is HI or LO, it does not seem to function as an INPUT.
    I have a 100k ohm resistor to +5VDC from pin4. I simply short the pin to GND to simulate the port as LO.

    Code:
    #CONFIG
     __config _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
     __config _CONFIG2, _PLLEN_OFF & _LVP_OFF & _STVREN_OFF
    #ENDCONFIG
    
    '_MCLRE_OFF = MCLR pin functions as INPUT RA5, MCLR internally tied to VDD
    
    DEFINE OSC 4
    DEFINE ADC_BITS 10       ' 10 bit A/D Conversion
    DEFINE ADC_CLOCK 4       ' 4MHz Clock
    DEFINE ADC_SAMPLEUS 50   ' 50 uS A/D sample time
    
    TRISA = %00101100       ' Set RA2, RA3 and RA5 as Inputs
    TRISB = %00000000       ' All PortB as Output
    
    'ADC Setup
    ADCON1 =%11000000       ' Right justified
    ANSELA =%00000010       ' AN2 on PortA.2 Analog
    ANSELB =%00000000       ' Digital inputs
    
    adval var word
    
    mainloop:
    if PortA.5= 1 then PortB.1 = 1 'turn ON an LED
    if PortA.5= 0 then PortB.1= 0 'turn OFF an LED
    goto mainloop
    I do not get it. Help! Thanks!
    Last edited by SOTASOTA; - 10th February 2014 at 20:03.

  2. #2
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    I assuming what you mean by doesn't work is that the LED doesn't blink or stay on steady. If so, you might want to try some pauses in your mainloop. Such as

    mainloop:
    if PortA.5= 1 then PortB.1 = 1 'turn ON an LED
    Pause 500
    if PortA.5= 0 then PortB.1= 0 'turn OFF an LED
    pause 500
    goto mainloop

    You may also have too big of a resistor in series with your LED. If you're using 5VDC supply to a 2.2VDC LED with a max current of 20mA then you'll need 140ish ohm resistor in series with it. Check LED orientation and connection especially if using a proto board.

    But as important to all of that I think you need to set your oscillator config. If I RFDS correctly your config of FOSC_HS needs an external oscillator. For an internal oscillator it probably should read FOSC_INTOSC. That is a guess but I also guess you need to set the OSCCON to your desired oscillator speed.

    As always, I hope it helps.

  3. #3
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    The LED is working if I set PortB.1=1 manually in code.
    I have an external 4MHz crystal.

    DEFINE OSC 4 should set the frequency. All other code commands work fine like the ADCIN.

    If I short out PortA.5 and hold it LOW, then the code should read a LOW on the port and turn on the LED.

    Mind boggling.

  4. #4
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    166


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    I am not sure if this is the cause of your problem but 100k for a pull up resistor seems a bit too high.
    Try using the weak pull up associated with RA5 instead of the external pull up resistor - see page 123 of the datasheet for details.

    Cheers
    Barry
    VK2XBP

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,819


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    Maybe stupid question, but are counting the pins correctly? Does seem strange... Also try 1K resistor, or directly Vdd/Vss connection.

    Are you programming the chip with ICSP or do you move the chip to a programmer and the move it back to your test board?

    Ioannis

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    Code:
    mainloop:
    Pause 10
    if PortA.5= 1 then PortB.1 = 1 'turn ON an LED
    if PortA.5= 0 then PortB.1= 0 'turn OFF an LED
    goto mainloop
    Reduce the value of your pullup resistor from 100k to 10k and add a delay in the loop as per the above example.

    Then it should work as you expected.

    Cheers

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    I think a write to the latch register might do it:

    Code:
    mainloop:
    Pause 10
    if PortA.5= 1 then LATB.1 = 1 'turn ON an LED
    if PortA.5= 0 then LATB.1= 0 'turn OFF an LED
    goto mainloop
    Louie

  8. #8
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    SOLVED!! I had a bad LED. All is working now. Sorry for the confusion.

  9. #9
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    In post # 3 you wrote:
    The LED is working if I set PortB.1=1 manually in code...........
    Which is in contradiction with your last post.

    Regards

    Al.
    All progress began with an idea

  10. #10
    Join Date
    Jan 2009
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: 16F1826 cannot get MCLR to act as an INPUT

    Quote Originally Posted by aratti View Post
    In post # 3 you wrote:


    Which is in contradiction with your last post.

    Regards

    Al.
    A poor solder joint that worked "sometimes". So, I replaced the LED thinking it was it initially. The re and re fixed the problem. I should have said a bad solder connection to the LED. But I only found this out after replacing the LED.

Similar Threads

  1. ICSP with MCLR as input
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th June 2013, 16:40
  2. Q: using MCLR for Input on 12F683
    By picster in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 31st January 2009, 15:25
  3. MCLR line input only
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th April 2008, 23:14
  4. Mclr As Input Pin?
    By omid_juve in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th December 2007, 06:33
  5. RA5/MCLR input in 16f88
    By kacho in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th April 2005, 17:21

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