Announcement

Collapse
No announcement yet.

Cannot get MCLR to act as an input on 16F1826

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot get MCLR to act as an input on 16F1826

    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!

  • #2
    Well, I don't see any reason in the code for it not to work.

    The 100K pull-up seems a little high. Especially if the programmer is still plugged in.
    Try using a 10K resistor, or turn on the internal pull-up.

    Also, make sure your programmer is set to program the CONFIGs in the .HEX file.
    If it's using the default CONFIGs, the MCLR pin will still be Master Clear Reset.
    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
    Never download a PIC datasheet from anywhere but microchip.com

    Comment


    • #3
      Originally posted by Darrel Taylor View Post
      Well, I don't see any reason in the code for it not to work.

      The 100K pull-up seems a little high. Especially if the programmer is still plugged in.
      Try using a 10K resistor, or turn on the internal pull-up.

      Also, make sure your programmer is set to program the CONFIGs in the .HEX file.
      If it's using the default CONFIGs, the MCLR pin will still be Master Clear Reset.
      I take the IC out of the programmer and transfer to the board.
      The pull-up is working as there is 5V on the PortA.5 and when I simulate a LOW, I read 0.250V on PortA.5.
      Hex file is being read correctly.

      Just mind boggling. :<(

      Comment


      • #4
        Solved!!

        Originally posted by SOTASOTA View Post
        I take the IC out of the programmer and transfer to the board.
        The pull-up is working as there is 5V on the PortA.5 and when I simulate a LOW, I read 0.250V on PortA.5.
        Hex file is being read correctly.

        Just mind boggling. :<(
        SOLVED!!!!
        I had a bad LED. Sorry for the confusion. All working now.

        Comment


        • #5
          PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
          Never download a PIC datasheet from anywhere but microchip.com

          Comment


          • #6
            Originally posted by Darrel Taylor View Post
            Yup, I felt the same way!!
            Good to know. You cannot trust everything on the circuit and it is easier to blame the PIC code rather than hardware. :-)

            Comment

            Working...
            X