MCLR pin for IOC?

Discussion in 'Embedded Systems and Microcontrollers' started by oookey, Dec 28, 2014.

  1. oookey

    Thread Starter Member

    May 24, 2010
    62
    0
    Hi all,

    I tried to use the MCLR pin to function as IOC, it suppose to ON the output when a button being pressed, the button is hooked to Vcc via an 100 ohm, and the pin is pull down to 0V via 10k ohm, but now the output started work once power up the mcu.

    The pins 3;6 & 7 are to be assigned to other sensing usage.
    PIC12F615, mikroC to program.
    The source code is attached.
    Please advice.
    ioc.png

    Thx

    oookey
     
    • IOC.txt
      File size:
      1.1 KB
      Views:
      24
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    For IOC to work on GP3, you also have to disable MCLR in the configuration bits when programming the chip.

    In the interrupt routine after testing GPIF==1 you have to read (or write) the GPIO to clear the IOC mismatch, then you have to clear GPIF. Do this inside the brackets after testing GPIF==1. Your code clears GPIF outside the brackets which can cause missed interrupts.

    You do not have to manage GIE - GIE will be cleared automatically by any interrupt and re-enabled by the RETFIE instruction that the compiler generates to end an interrupt routine.

    When configuring interrupts, GIE should be the LAST thing turned on i.e. configure each peripheral, clear all interrupt flags then enable GIE. Doing it out of order can cause interrupts that you are not prepared for.

    Good luck.
     
  3. oookey

    Thread Starter Member

    May 24, 2010
    62
    0
    thx JohnInTX, i had disable MCLR pin function from the "edit project", also shifted the clear flag inside brackets, when power up, the LED light stay ON, there was no blinking, even the button is pressed.
    are there any steps i missed out? the amended code attached.
    please advice.
    thx
     
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    You still have to read GPIO on each IOC to clear the mismatch condition.

    How is the LED hooked up? (does the output sink or source to turn it on?).
    Are your PWM duty cycle settings OK? I don't have the MicroC manual handy. You might test it by just toggling the LED on and off, get that to work then fire up the PWM.

    A bigger question is why you are doing the delays etc in an interrupt routine. A better way would be to have the IOC set a flag in the interrupt routine that is checked and cleared in main() and let main() do the flashing.
     
Loading...