Gracias por sus respuestas elreypic2, remi04 y KILLERJC; Si, estoy usando lenguaje C con el compilador XC8, y uso el Timer1 como temporizador, empleo un cristal de 10 MHz como oscilador externo. Como me comentas remi04, podria probar T1OSCEN y TMR1ON para ver como se comporta la aplicación, haré unas pruebas; por otro lado, entendiendo un poco mas como lograr lo que deseo hacer, al parecer no sería necesario detener el timer1, se puede dejarlo correr y mas bien trabajar con la visualizacion empleando una variable que envie por el puerto D (puerto usado para enviar 4 bits bcd y 4 bits de control de switcheo con transistores), esta variable debe alojar el valor instantaneo y es ésta que debe reiniciarse/parase/limpiarse, ¿que les parece ese razonamiento? ; les comparto el codigo que he escrito, aun no estan implementados los botones START y STOP, pero la logica a plasmar sería como lo comenté lineas arriba, considerar que utilizo el decodificador bcd a 7 segmentos cd4511, saludos.
/*
*CRONOMETRO DE 4 DISPLAYS DE 7 SEGMENTOS, CUENTA 0 - 9999
*CONFIGURACION DE BITS PARA MICROCONTROLADOR PIC DE 8 BITS 16F876A, DECODIFICADOR DE BCD A 7 SEGMENTOS CD4511
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
//CRISTAL DE 10Mhz (10000000 Hz)
#define _XTAL_FREQ 10000000
/*Configuration Bits*/
#include <xc.h>
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//VARIABLES GLOBALES
char BCDNumeros[] = {0,1,2,3,4,5,6,7,8,9};
char contint = 0;
char _unidades = 0;
char _decenas = 0;
char _centenas = 0;
char _millares = 0;
char temp;
//PROTOTIPO DE FUNCIONES
void IniciarTimer1(void);
void interrupt Timer1(void);
void ControlCuenta(void);
void Contador(void);
//PROGRAMA PRINCIPAL
int main(int argc, char** argv) {
//PUERTO D COMO SALIDA
TRISD = 0;
//INICIALIZACION DE SALIDA EN CERO
PORTD = 0;
//DECLARACION DE VARIABLES LOCALES
char _switch = 0x10; //CHAAR EN BITS -> 0001 0000
char *bcd = NULL; //INICIALIZACION DE PUNTERO A TIPO DE DATO CHAR
//bcd ES UN PUNTERO A LA POSICION DEL PRIMER ELEMENTO DEL ARREGLO BCDNumeros
bcd = &BCDNumeros;
//INICIAR TIMER1
IniciarTimer1();
while(1){
//USANDO LOS 8 BITS DEL PUERTO D, LOS 4 BITS MAS SIGNIFICATIVOS CONTROLAN LOS TRANSISTORES DE CONMUTACION
//LOS 4 BITS MENOS SIGNIFICATIVOS SON LOS NUMEROS BCD
temp = *(bcd + _unidades) + _switch;
PORTD = temp;
_switch = _switch<<1;
__delay_ms(10);
temp = *(bcd + _decenas) + _switch;
PORTD = temp;
_switch = _switch<<1;
__delay_ms(10);
temp = *(bcd + _centenas) + _switch;
PORTD = temp;
_switch = _switch<<1;
__delay_ms(10);
temp = *(bcd + _millares) + _switch;
PORTD = temp;
_switch = 0x10;
__delay_ms(10);
//CONTROL DE LA CUENTA
ControlCuenta();
}
return (EXIT_SUCCESS);
}
//INICIALIZA EL TIMER1
void IniciarTimer1(void){
T1CONbits.T1CKPS0 = 1; //Preescaler 1:8
T1CONbits.T1CKPS1 = 1; //Preescaler 1:8
T1CONbits.TMR1CS = 0; //Timer1 como temporizador
T1CONbits.T1OSCEN = 0; //BIT DE CONTROL DEL OSCILADOR DEL TIMER1 EN 0, NO SE USARA EL OSCILADOR
T1CONbits.TMR1ON = 1; //Interrupcion por debordamiento del Timer1 habilitado
INTCONbits.GIE = 1; //HABILITACION DE INTERRUPCIONES GLOBALES
INTCONbits.PEIE = 1;
PIR1bits.TMR1IF = 0; //INICIALIZA EN 0 EL FLAG DE INTERRUPCION DEL TIMER1
PIE1bits.TMR1IE = 1; //Habilitar interrupcion desbordamiento timer1
//carga valor inicial a TMR1 (cargado 3036 para lograr 0.25seg)
TMR1L = 0xDC; //REGISTRO LOW DEL TIMER1
TMR1H =0x0B; //REGISTRO HIGH DEL TIMER1
}
//INTERRUPCION POR DESBORDAMIENTO DEL TIMER1
void interrupt Timer1(void){
if(PIR1bits.TMR1IF){ //CUANDO TIMER1 SE DESBORDA LOGRA EL EQUIVALENTE A 0.25 SEGUNDOS SE LLAMA A LA FUNCION CONTADOR()
Contador();
}
}
//CONTROL DE LA CUENTA
void ControlCuenta(void){
switch(_unidades){
case 10: _unidades = 0; _decenas++; break;
}
switch(_decenas){
case 10: _decenas = 0; _centenas++; break;
}
switch(_centenas){
case 10: _centenas = 0; _millares++; break;
}
switch(_millares){
case 10: _millares = 0; break;
}
}
//CUENTA
void Contador(void){
PIR1bits.TMR1IF = 0;
TMR1L = 0xDC; //carga valor inicial a TMR1 (cargado 3036 para lograr 0.25seg)
TMR1H =0x0B;
contint++;
//1 SEGUNDO CUMPLIDO(contint=4)
switch(contint){
case 4: contint = 0; _unidades++; break;
}
}