Pic interrupt

Discussion in 'General Electronics Chat' started by srpott40, Feb 27, 2013.

  1. srpott40

    Thread Starter New Member

    Feb 27, 2013
    4
    0
    I am currently writing the program for a PIC16F84A, and i have got stuck on how to program a interrupt. I would like the PIC to be interrupted when PortA 4 is high (input 4), and then place all of PortB high (output ports),

    Hope somebody is able to help
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    There is no interrupt capability on that pin. As a work around(since this can be the clock source for TMR0), you can preload TMR0 with 0xFF and us the input as the clock for TMR0(positive edge-triggered), each time the pin goes HI, the timer will overflow , generating an interrupt, but you'd need to load TMR0 with 0xFF each time.

    To be any more specific than that, we need to know what compiler you are using...
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    RA4 is not an Interrupt-on-change pin. RA4 can be selected to be the clock input to the TMR0 timer/counter. It may be that you can use that in some way. Pre loading TMR0 with 0xff. And then let a rising edge on this pin causing an overflow that trigger an interrupt. This is from the top of head. But you can look into it
     
    srpott40 likes this.
  4. srpott40

    Thread Starter New Member

    Feb 27, 2013
    4
    0
    Well i suppose it does not have to be that pin, as i could easily change the circuit diagram, which pin normally has the INTERRUPT stuff on? And i am writing the code on notepad++ then transferring it to MPLab which it then transferring it to the chip
     
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    If you'll look at the datasheet, page 3 shows RB0 as having external interrupt capabilities[INT], PORTB also typically has an interrupt-on-change,, but this will be generated for any pin in PORTB changing.
     
  6. srpott40

    Thread Starter New Member

    Feb 27, 2013
    4
    0
    I am currently using all the pins in PORTB as outputs (got 8 outputs)
     
  7. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Sounds like you've got a problem!:p

    You can output on part of B and part of A....
     
  8. srpott40

    Thread Starter New Member

    Feb 27, 2013
    4
    0
    How can that be done?
     
  9. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    ...something like this will do it...
    uses PORTA<0:3> as the low nibble and PORTB<4:7> as the upper nibble
    Code ( (Unknown Language)):
    1.  
    2. unsigned char data;
    3. ...
    4. PORTB &= 0x0F; //clear upper nibble
    5. PORTA &= 0xF0;//clear lower nibble
    6. PORTB |= (data & 0xF0); //write upper nibble
    7. PORTA |= (data & 0x0F); //write lower nibble
    8.  
    9.  
     
    srpott40 likes this.
Loading...