TODOPIC
Microcontroladores PIC => Todo en microcontroladores PIC => Mensaje iniciado por: Saulv_123 en 29 de Julio de 2021, 01:49:46
-
Ayuda con mi programa para mover la hora que yo quiera y cuando llegue a 23:59:59 se reinicie por favor ayuda
#include <xc.h>
#define k1 LATC0
#define k2 LATC1
#define k3 LATC2
#define k4 LATC3
#define k5 LATC4
#define k6 LATC5
#define _XTAL_FREQ 4000000
#pragma config FOSC = INTIO7
int uSec, uMin, dSec, dMin, uHrs, dHrs;
int number[10] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x67};
void clearClock(void);
void __interrupt() myISR(void){
if(INT0IF == 1){
clearClock();
INT0IF = 0;
}
if(INT1IF == 1){
uSec++;
if(uSec > 9){
uSec = 0;
dSec++;
}
INT1IF = 0;
}
if(INT2IF == 1){
if(uSec <= 0 ){
uSec = 0;
}
else{
uSec--;
}
INT2IF = 0;
}
if(TMR0IF == 1){
uSec++;
if(uSec > 9){
uSec = 0;
dSec++;
}
TMR0H = 0x0B;
TMR0L = 0xDC;
TMR0IF = 0;
}
}
void main(void) {
OSCCONbits.IRCF = 0x5;
OSCCONbits.SCS = 0x3;
TRISD = 0x00;
TRISC = 0x00;
ANSELC = 0x00;
ANSELD = 0x00;
ANSELB = 0x00;
/*------------configuración de interrupciones---------------*/
INT0IE = 1;
INT1IE = 1;
INT2IE = 1;
GIE = 1;
INT1IP= 1;
INT2IP = 1;
INTCON2bits.INTEDG0 = 0;
INTCON2bits.INTEDG1 = 0;
INTCON2bits.INTEDG2 = 0;
TMR0IE = 1;
TMR0IP = 1;
clearClock();
TMR0H = 0x0B;
TMR0L = 0xDC;
T0CON = 0b10000011;
while(1){
/*mostrar números en 7 segmentos y control de k's*/
k1 = 0;
k2 = 1;
k3 = 1;
LATD = number[uSec];
__delay_ms(20);
k1 = 1;
k2 = 0;
k3 = 1;
LATD = number[dSec];
__delay_ms(20);
k1 = 1;
k2 = 1;
k3 = 0;
LATD = number[uMin];
__delay_ms(20);
}
return;
}
-
¿Y que es lo que no funciona? Deberías explicar mas o menos de que se trata.
Parece que ocupas interrupciones externas para incrementar y decrementar las unidades de segundo de tu reloj de forma manual. Y un temporizador para modificar esas variables de manera automática.
Lo que parece que no tienes implementado es el incremento automático de los minutos y horas que deberías hacerlo en la rutina que debería llamar la interrupción del temporizador.