hi,
not sure if this is the right sub to post;
basically I can't make a simple counter from external interrupt...
i can make a counter and a interrupt, I can make a delay, but now I need to make an external interrupt that will start a timer then keep increment 'ing that 'counter' until external stimulus changes...
the problem is that i'm not only very newbie but also very stupid since it seems to be the easiest thing ever just not for me ...
honestly don't understand what i'm doing wrong because my interrupt stops the entire PIC and I feel like I want to die.
I wanted to make a simple program without interrupt but it is a must ... so idk what to do I tried getting help from IRL teachers and colleges but they either trolling me or they don't know either since nothing has helped me so far.
I'm NOT looking for some one to make my work... I really need help I want to understand this ...
The code is not complete I didn't make the supposed counter on the main void yet I know,
but the code is not working as intended anyway...
so I need it to accept interrupt on at external pin, start a timer... an keep counting until the external pin that started the timer is changed.
but what it does is a simple delay to the entire PIC...
not sure if this is the right sub to post;
basically I can't make a simple counter from external interrupt...
i can make a counter and a interrupt, I can make a delay, but now I need to make an external interrupt that will start a timer then keep increment 'ing that 'counter' until external stimulus changes...
the problem is that i'm not only very newbie but also very stupid since it seems to be the easiest thing ever just not for me ...
honestly don't understand what i'm doing wrong because my interrupt stops the entire PIC and I feel like I want to die.
I wanted to make a simple program without interrupt but it is a must ... so idk what to do I tried getting help from IRL teachers and colleges but they either trolling me or they don't know either since nothing has helped me so far.
I'm NOT looking for some one to make my work... I really need help I want to understand this ...
Code:
#include <xc.h>
int count = 0;
int aux = 0;
int aux2 = 0;
int tempoL; // utiliza 4 bytes(tipo INT);
int tempoH;
void setup () {
ANSELAbits.ANSA2 = 0;
OSCCONbits.IRCF = 0b1110; // 8Mhz INTOSC
INTCONbits.GIE = 1; // HABILITA INTERRUPÇÃO GLOBAL
INTCONbits.PEIE=1; // HABILITA INTERRUPÃO POR PERIFERICOS
INTCONbits.IOCIE = 1; //HABILITA INTERRUPÇÃO POR MUDANÇA DE FLANCO
IOCAPbits.IOCAP2 = 1; //INTERRUPÇÃO NO FLANCO POSITIVO
IOCANbits.IOCAN2 = 1;
T1CONbits.T1CKPS0 = 1; // TIMER1 PRESCALER 1:8
T1CONbits.T1CKPS1 = 1;
PIE1bits.TMR1IE = 1;
T1CONbits.TMR1ON = 0;
TMR1L = 0x00; //CARREGA TIMER1 COM O VALOR 3035
TMR1H = 0x00;
}
void main(void) {
TRISC = 0b00000101;
PORTC = 0b00000000;
TRISA = 0b00000100;
int setx = 0;
while(1)
{
if (aux==1)
{
PORTCbits.RC1=1;
}
if (PORTCbits.RC0==0)
{
PORTCbits.RC1=0;
}
if ((setx==0))
{
setx=1;
setup();
}
}
return;
}
void interrupt a(){
if(IOCAFbits.IOCAF2 == 1){ // TESTA A FLAG DE MUDANÇA DE ESTADO RA2
IOCAFbits.IOCAF2 = 0; //BAIXA FLAG
if(aux == 0){ //
count = 0;
tempoL = 0;
tempoH = 0;
aux++;
TMR1L = 0xDB; //CARREGA TIMER1 COM O VALOR 3035
TMR1H = 0x0B;
T1CONbits.TMR1ON = 1;// ARRANCA TIMER1
}else {
if(aux==1){ //
tempoL = TMR1L; // O VALOR NO TIMER1 FICA NA VARIAVEL TEMPO (VALOR QUE CONTOU DESDE O ULTIMO REARME)
tempoH = TMR1H;
T1CONbits.TMR1ON = 0;// STOP TIMER1
aux =0 ; //REINICIA AUX
aux2 = 1;
}
}
}
if(PIR1bits.TMR1IF == 1){ // TESTA FLAG DE ESTOURO TIMER0
PIR1bits.TMR1IF = 0; //BAIXA A FLAG
count++; //INCREMENTA CONTADOR
TMR1L = 0xDB;
TMR1H = 0x0B; //REINICIA TIMER1 COM O VALOR 3035
}
}
but the code is not working as intended anyway...
so I need it to accept interrupt on at external pin, start a timer... an keep counting until the external pin that started the timer is changed.
but what it does is a simple delay to the entire PIC...