Programación de interrupciones por temporización usando timer0 en pic c pic16f887 y proteus
Programación de interrupciones por temporización usando timer0 en pic c pic16f887 y proteus
Objetivos:
- programar interrupciones por temporización, ( prender y apagar un led usando estas interrupciones)
- Saber calcular el tiempo de interrupción
Desarrolllo:
Donde: TODIV es el PRESCALER que puede ser 1,2,4,16,32,64,128,256
TMR0 es el valor 8 bits de registro TMR0 se configura con set_TIMER0( ); puede tener un valor maximo de 255
Fosc es la frecuencia del oscilador ya sea externo o interno
Diagrama en proteus

Codigo en PIC C
// microcontroladores.com.mx #include <16f887.h>//pic a utilizar #FUSES NOWDT //No Watch Dog Timer #FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD) #FUSES NOPUT //No Power Up Timer #FUSES MCLR //Master Clear pin enabled #FUSES NOPROTECT //Code not protected from reading #FUSES NOCPD //No EE protection #FUSES NOBROWNOUT //No brownout reset #FUSES IESO //Internal External Switch Over mode enabled #FUSES FCMEN //Fail-safe clock monitor enabled #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O #FUSES NODEBUG //No Debug mode for ICD #FUSES NOWRT //Program memory not write protected #FUSES BORV40 //Brownout reset at 4.0V #use delay (clock=8M) //Fosc=8Mhz #use fast_io(A) #use fast_io(B) //Interrupcion por TMR0. //La interrupcion ocurrira (256-TMR0)*256*4/Fosc=(256-0)*256*4/8MHz=32.768ms int1 bandera=0; #INT_TIMER0 // indicamos que seara una interrupcion por tiempo void TIMR0_ISR(){ bandera=!bandera; if(bandera==1){ output_high(PIN_B1); } else { output_low(PIN_B1); } set_TIMER0(81); //inicializa el timer0 } ///PROGRAMA Principal. void main(void){ set_tris_b(0x00); setup_adc_ports(NO_ANALOGS|VSS_VDD); //Todas las entradas del PIC Seran Digitales. setup_comparator(NC_NC_NC_NC); //Los comparadores Analogicos estaran apagados. setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); //La entrada de Reloj para TIMER0 sera interna. Se dividira el reloj interno entre 256. set_TIMER0(81); //inicializa el timer0 setup_timer_1(T1_DISABLED); //Desabilitamos el TIMER1. setup_timer_2(T2_DISABLED,0,1); //Desabilitamos el TIMER2. enable_interrupts(GLOBAL); //Habilitamos la interrupciones globales. enable_interrupts(INT_TIMER0); //Habilitamos la interrupcion por desborde del TIMER0. while(TRUE); }
