Cuando el pin RB5 cambia entre alto y bajo, se debe activar la interrupción. La interrupción se produce cuando el IC recibe alimentación y no se produce después cuando RB5 se conecta o desconecta de vdd. ¿Por qué?
Estoy usando PIC16F677-I / P
#include <xc.h>
#include <stdbool.h>
#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Selection bits (BOR enabled)
#pragma config IESO = OFF // Internal External Switchover bit (Internal External Switchover mode is disabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is enabled)
void main(void)
{
// Select 8 MHz internal oscillator
IRCF2 = 1;
IRCF1 = 1;
IRCF0 = 1;
// High Frequency Internal Oscillator is stable
HTS = 1;
// Use internal oscillator for system clock
SCS = 1;
// Global interrupt enable
GIE = 1;
// PORTA/B change interrupt enable
RABIE = 1;
RABIF = 0;
// RB5 as digital input
ANS11 = 0;
// RB5 as input
TRISB5 = 1;
// RB5 interrupt on change
IOCB5 = 1;
// RC6 as output
TRISC6 = 0;
RC6 = 0;
while (true)
{
}
}
void interrupt myintrout(void)
{
if (RABIF)
{
RC6 = RC6 ? 0 : 1;
RABIF = 0;
}
}