MICROCHIP PIC MIDRANGE PIC18XX External Interrupt INT1

Configuring the external Interrupt INT1 in PIC18F25k80 is tricky way. The data sheet also may confuse you well.

Screenshot from 2015-06-24 22:53:21

From the pinout pin 22 or RB1 has multiple functions (RB1/AN8/C1INB/P1B/CTDIN/INT1)

These are the things to be noticed while configuring RB1 as external interrupt

Screenshot from 2015-06-24 23:42:47

The RB1 acts also as analog pin to be exact AN8.From the summary of registers associated with PortB we may misunderstand that ANSEL9 is the pin associated with RB1 but that’s wrong. If you look at ANCON1 resister

Screenshot from 2015-06-24 23:48:45

Screenshot from 2015-06-24 23:49:00

This is the most tricky part in configuring external interrupt.The other configurations are pretty straight forward in INTCONbits.

    TRISBbits.TRISB1 = 1;  
    ANCON1bits.ANSEL8 = 0;
    INTCONbits.GIE = 1;
    INTCONbits.PEIE = 1;
    INTCON3bits.INT1IE = 1;
    INTCON2bits.INTEDG1 = 1;
    INTCON3bits.INT1IP = 1;
    INTCON2bits.RBPU = 0;

The above snippet configures INT1 as external interrupt which responds to a rising edge.

Advertisements

Microchip PIC midrange PIC18xx Unable to drive Port C pin 1 as a digital output

Last day i tried to program Microchip PIC midrange controller. To be precise the controller i used was PIC 18F25K80. I was using the C18 compiler. I was unable to drive the PORT C pins as digital, after googling for some time i found out the solution.

Screenshot from 2015-06-24 22:53:21

I tried setting the TRISbits,PORTbits and LATbits but was of no use

 TRISCbits.TRISC1 = 0;/* Port C pin 1 configured for output */
 PORTCbits.RC1 = 1;
 LATCbits.LATC1 = 1;

The answer was that Port C pins 0 and 1 are also used as the input and output to the secondary oscillator.The secondary oscillator had to be set for digital output setting the configuration bits using the #pragma directive

#pragma config SOSCSEL=DIG

By adding this the pin turned digital and blinked

Happy Hacking 🙂