Estoy usando pic16f1823 y MPLab como IDE. Quiero tener una simple interrupción en RA2 y encender el LED cuando llegue. He escrito este código, ¡pero no funciona!
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
Y para la aplicación principal, tenemos:
#include <stdio.h>
#include <stdlib.h>
#include "main_10.h"
void interrupt tc_int(void)
{
//if (INTCONbits.INTF == 1)
if (INTCONbits.T0IF && INTCONbits.T0IE)
{
LATCbits.LATC1 = 1;
__delay_ms(1000);
LATCbits.LATC1 = 0;
__delay_ms(1000);
}
INTCONbits.INTF = 0;
}
/*
*
*/
void main (void)
{
OSCCON = 0x76;//Very Important,this will command micro to use internal oscillator
//prepare Interrupt on A2
TRISAbits.TRISA2 = 1; //make interrupt port as input.
OPTION_REGbits.INTEDG = 0; //make sense to falling edge.
INTCONbits.INTE = 1; //interrupt enable.
INTCONbits.GIE = 1; //Globally enable interrupts.
INTCONbits.INTF = 0; //make interrupt flag clear.
//prepare output on PORTC.bit1
LATCbits.LATC1 = 0; //initialization of portc.0
TRISCbits.TRISC1 = 0; //make portc.0 as output.
while(1)
{
}
}
Y tenemos una simulación de Proteus como esta:
¿dónde está el error? ¡Cualquier ayuda sería apreciada!