TODOPIC
Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: fidodido18 en 04 de Diciembre de 2012, 15:56:02
-
Hola amigos foreros!! nuevamente regresando a los PIC18!! :-/
pero ya tengo una duda: Estoy tratando de simular en Proteus la interrupcion del puerto B de mi PIC18f4620, sin embargo no he podido que entre en la interrupción!!
pensé que era algo del proteus, entonces decidí incluir la interrupción del timer1 y funcionó correctamente!!
Ya leí varios foros con el problema en los PIC16F, intente todo lo que decían y sugerían pero el problema persiste.
Mi código es el siguiente:
#include <18F46K20.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC //RC interno sin clck out
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV18
#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 prgming, B3(PIC16) or B5(PIC18) used for I/O
#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 NOPBADEN //PORTB pins are configured as digital I/O 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 LPT1OSC //Timer1 configured for low-power operation
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODELAYINTOSC
#use delay(clock=8000000)
#use fast_io(B)
int1 estado = 0;
#int_RB
void RB_isr(void)
{
if(estado)
{
estado = false;
}
else
{
estado = true;
}
output_b(input_b());
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
clear_interrupt(int_rb);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_OFF);
set_tris_b(0xff);
set_tris_c(0x00);
while(true)
{
if(estado == true)
{
output_c(0xFF);
}
else
{
output_c(0x00);
}
}
}
gracias por sus ayuda!!
-
Y el culpable del fallo es ................ supongo que un bug del CCS.
Probe su programa en el simulador del MPLAB y tendia el mismo problema, no iba a la interrupcion del PORTB,
revise un cacho la hoja de datos del micro en cuestion y dice que tiene bits individuales para habilitar estas interrupciones , estos bits se encuentran en el registro IOCB, mi version del CCS no habilita estos bits al momento de configurar la interrupcion, talvez tiene alguna funcion para hacerlo pero no la conozco, estos bits se puede habilitar de forma manual de todas formas.
Solucion: definir el registro IOCB usando:
#byte IOCB = 0xF7D
luego habilitamos los bits antes del while(1) haciendo
IOCB = 0xF0
adjunto el codigo corregido.
saludos
-
Y el culpable del fallo es ................ supongo que un bug del CCS.
Probe su programa en el simulador del MPLAB y tendia el mismo problema, no iba a la interrupcion del PORTB,
revise un cacho la hoja de datos del micro en cuestion y dice que tiene bits individuales para habilitar estas interrupciones , estos bits se encuentran en el registro IOCB, mi version del CCS no habilita estos bits al momento de configurar la interrupcion, talvez tiene alguna funcion para hacerlo pero no la conozco, estos bits se puede habilitar de forma manual de todas formas.
Solucion: definir el registro IOCB usando:
#byte IOCB = 0xF7D
luego habilitamos los bits antes del while(1) haciendo
IOCB = 0xF0
adjunto el codigo corregido.
saludos
Listo!!! gracias por el dato!!! funcionando!! :-/
Una pregunta no he encontrado ese registro en el datasheet. especificamente donde puedo conseguir mas informacion. gracias nuevamente sander!!
-
Listo!!! gracias por el dato!!! funcionando!! :-/
Una pregunta no he encontrado ese registro en el datasheet. especificamente donde puedo conseguir mas informacion. gracias nuevamente sander!!
La informacion esta en la seccion de I/O ports en la parte que describe el PORTB, en esa seccion tambien describe el funcionamento de la interrupcion on-change donde se habla del registro IOCB.
Otro lugar donde buscar cuando se tiene problemas con interrupciones es el diagrama de bloques de la logica de interrupcion , en el caso de la interrupcion on-change hay una nota donde indica que se debe habilitar individualmente los bits del registro IOCB.
Saludos