Pin5/GP2 won't go high

Discussion in 'Embedded Systems and Microcontrollers' started by jpanhalt, Jun 20, 2009.

  1. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,677
    899
    I have been struggling for 2 days with a program for a PIC 12F509.
    Odd things were happening, so I wrote a simple test program:

    Code ( (Unknown Language)):
    1.  
    2. ;**********************************************************************
    3.  
    4.     list      p=12F509            ; list directive to define processor
    5.     #include <p12F509.inc>        ; processor specific variable definitions
    6.  
    7.     __CONFIG   _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
    8.  
    9. ;   __CONFIG 0FFA
    10.  
    11.  
    12.  
    13. ;***** VARIABLE DEFINITIONS
    14.  
    15. List   
    16. d1  equ 0x11
    17. d2  equ 0x0b
    18.  
    19. ;*******************************************************************
    20. RESET_VECTOR
    21.     ORG   0x3FF      ; processor reset vector
    22.  
    23. ; Internal RC calibration value is placed at location 0x3FF by Microchip
    24. ; as a movlw k, where the k is a literal value.
    25.    
    26. MAIN
    27.     ORG    0x000
    28.     movwf   OSCCAL              ; update register with factory cal value
    29.  
    30.  
    31. start  
    32.     movlw   b'001000'           ; sets all pins to output, except GPIO,3 (pin4)
    33.     tris    GPIO
    34. flash
    35.     movlw   b'110111'           ; sets all pins high
    36.     movwf   GPIO
    37.     call    dly_2E5
    38. ;   movlw   b'000000'           ; sets all pins low
    39. ;   movwf   GPIO
    40. ;   call    dly_2E5
    41.     goto    flash
    42.  
    43. dly_2E5
    44.     clrwdt
    45.     movlw   0x3f
    46.     movwf   d1
    47.     movlw   0x9d
    48.     movwf   d2
    49. delay
    50.     decfsz  d1,f
    51.     goto    $+2
    52.     decfsz  d2,f
    53.     goto   delay
    54.     retlw   0
    55.  
    56.     END                       ; directive 'end of program'
    57.  
    58.  
    Try as I may, I cannot get pin 5 (GP2) to go high. I have tried 4 dip chips (one was new), 3 SOIC chips (2 were new), two computers (one had a real serial port, the other used a USB to serial adapter cable), and 2 programmers (PicStart Plus and Inchworm --an MPLAB ICD2 emulator).

    Both computers and programmers, including the adapter cable, had worked in the recent past. Contact to the #5 pin have been checked and appear to be OK.

    I need a fresh brain and set of eyes to look at this for possible problems/solutions.

    Thanks.

    John
     
    Last edited: Jun 20, 2009
  2. gryskop

    Member

    Mar 1, 2008
    26
    0
    Code ( (Unknown Language)):
    1.     MOVLW   B'11000000' ; Weak Pullup resistors
    2.     OPTION          ; disabled
    3.     MOVLW   B'00001000' ; Set only GP<3> as Input
    4.     TRIS    GPIO        ; Set GP<5,4,2,1,0> as outputs
    5.  
    I used this in my code for a 12C509 application and it does allow GP2 to operate.

    BTW, how long is your delay loop suppose to be? It seems to be in a loop?
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    The obvious question that springs to mind is do you have a pull-up resistor connected between Vdd and pin4 (MCLR).
     
  4. jpanhalt

    Thread Starter AAC Fanatic!

    Jan 18, 2008
    5,677
    899
    @gryskop: Thanks loads. Great catch on the Option register.

    For several other programs that work, I set Option as needed, and pin 5 works as expected (like in my spot welder). In this case, since GP2 does not have a weak pullup, I assumed it wouldn't be affected and neglected to pay any attention to the Option register. I wonder where it is documented in the datasheet?

    @AlexR: Problem is solved. Yes, I had MCLR tied high.

    Thanks all.

    Edit: Delay loop is 200 mS (I use 2E5 to mean 2X10E5 microseconds); edit#2 fixed error in loop above

    John
     
    Last edited: Jun 20, 2009
Loading...