#include <18F2550.h>
#device adc=8
#FUSES WDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOMCLR //Master Clear pin disabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1 //No PLL PreScaler
#use delay(clock=8000000, RESTART_WDT)
#fuses XT,NOWDT,NOPROTECT,PUT,NOLVP //ordenes para el programador
#fuses INTRC //oscilador interno
//#use delay (clock=4000000) //Fosc=4Mhz
#use standard_io(a)
#use fast_io(b)
//declaracion del puerto b
///DECLARACION DE FUNCIONES GLOBALES
#int_ext
void interrupcion(void){
disable_interrupts(int_ext);
disable_interrupts(global);
output_high(PIN_A0);
enable_interrupts(int_ext);
enable_interrupts(global);
} //funcion que ejecuta la iluminacion del porta dada la interrupcion
//int a;
///PROGRAMA
void main(void)
{
#byte TRISB = 0xFF; //portb entrada m
#byte TRISA = 0x00;
enable_interrupts(int_ext); //activar interrupcion rb4:7
enable_interrupts(global); //activar interrupciones
while(1){
}
}
//while(1)
//{
//if (a==1){
// output_high(PIN_B0);
// delay_ms(200);
// output_low(PIN_B0);
// delay_ms(200);
//}
//};
//}
// DIRECTIVAS DE PREPROCESADOR.
#include <18F2550.h>
#device adc=8
#FUSES WDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOMCLR //Master Clear pin disabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL1 //No PLL PreScaler
#use delay(clock=8000000, RESTART_WDT)
#byte PORTA= 0xF80
#byte PORTB= 0xF81
// VARIABLES GLOBALES.
int Cuenta = 0;
short Flag_LED = 0;
// PROCEDIMIENTO DE INTERRUPCIÓN POR FLANCO DESCENDENTE EN EL PIN B0.
#int_ext
void ISR_ext()
{
disable_interrupts(int_ext); // Habilita la interrupción externa.
disable_interrupts(global);
Cuenta++;
Flag_LED = 1;
enable_interrupts(int_ext); // Habilita la interrupción externa.
enable_interrupts(global); // Habilita en forma global las interrupciones.
}
// PROCEDIMIENTO PRINCIPAL.
void main()
{
enable_interrupts(int_ext); // Habilita la interrupción externa.
enable_interrupts(global); // Habilita en forma global las interrupciones.
ext_int_edge (0, H_TO_L); // La interrupción se produce cuando se produce un flanco descendente.
set_tris_a(0x00);
set_tris_b(0xFF);
do{
output_low(PIN_A1); //led off
delay_ms(500);
output_high(PIN_A1); //led on
delay_ms(500);
}while(1); {
if (Flag_LED){
output_high(PIN_A0); // Coloca en 1 la salida AN0 por medio segundo cuando pasa alguien y luego la vuelve a 0.
delay_ms(500);
output_low(PIN_A0);
Flag_LED = 0;
}
}
}
1.- Como he dicho antes, tuve que cambiar la rutina de inicialización, pues no funcionaba la que me mandaste, entonces, ¿es realmente importante esa rutina? o la modifico de todas formas?
2.- En el código también agregué ciertas cosas que pensé que faltaban como desactivar las interrupciones cuando entra a la interrupción y activarlas nuevamente cuando sale. También agregué los set_tris_x que no estaban antes y #BYTE PORTX=XXXX que también faltaban... he hecho bien???
3.- Y lo más importante: porqué aún no funciona la interrupción?? De que otra manera puede funcionar?? Que falta!?
#device adc=8#FUSES WDT //No Watch Dog Timer
do{
output_low(PIN_A1); //led off
delay_ms(500);
output_high(PIN_A1); //led on
delay_ms(500);
}while(1);
if (Flag_LED){
output_high(PIN_A0); // Coloca en 1 la salida AN0 por medio segundo cuando pasa alguien y luego la vuelve a 0.
delay_ms(500);
output_low(PIN_A0);
Flag_LED = 0;
}
}
}