Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

problem with delay function pic16f1508

Status
Not open for further replies.

maryem

Member
hello,
i have problem with delay function in interrupt , i put it also in the main but it still not working , just i need pin rc6 still high after the interruption a few seond thanks


void interrupt (void){
unsigned char dummy;
bit oldstate;


if ((PORTA.F0==1)&& (INTCON.TMR0IF==1))
{ PORTC.F3 = 1;
PORTC.F4 = 0;
dummy = PORTA;
dummy = PORTB;
INTCON.TMR0IF =0 ; }


else if ( (PORTA.F1==1) &&(INTCON.TMR0IF==1) )
{ PORTC.F3 = 0;
PORTC.F4 = 1;
dummy = PORTA;
dummy = PORTB;
INTCON.TMR0IF =0 ;
}

else if ((INTCON.TMR0IF==1)&&(Button(& PORTA, 2, 1, 1)))

{oldstate = 1;
INTCON.TMR0IF =0 ;
}
else if ((INTCON.TMR0IF==1)&& (Button(&PORTA, 2, 1, 0))&& (oldstate==1))

{


PORTC.F6=1;
dummy = PORTA;
dummy = PORTB;
INTCON.TMR0IF =0 ;
oldstate=0;
Delay_ms(1000);
PORTC.F6=0;

}
}

void main() {
int cnt ;
bit oldstate;
ANSELA = ANSELB = ANSELC= 0; //all pins I/o are cofigurred as digital
C1ON_bit = C2ON_bit = 0; //Désactivation de deux comparateurs
INTCON.GIE =1 ; // Gener al interrupt enabled




TMR0 = 0;
INTCON.TMR0IE=1;
INTCON.TMR0IF=0;
OPTION_REG = 00000100 ;
//OPTION_REG.TMR0CS=1;
// OPTION_REG.INTEDG:=1;
OPTION_REG.TMR0CS=0;
OPTION_REG.PSA=0;



TRISA=0b11111111; // PortA input
TRISB=0b00010000; //RB4 input , others output
TRISC=0b00000111 ; //portC RC0,RC1,RC2 input , others output






PORTC.F7=0;
PORTC.F4=0;
PORTC.F3=0;
PORTC.F6=0;

do {


}while (1);
}
 
First oldstate would need to be static or global as it won't be remembered for the next run.. You have declared it in both functions, but it would be better as a volatile bit in global space..

Declare it before any code..

volatile bit oldstate;
 
i changed the interruption to inteurrption with timer and it works but the problem how to implement priority in pic 16 f
 
There's no priorities in PIC16F. However, once you get to your ISR, you can check for the interrupt sources in certain order - higher importance first etc.

BTW: If none of your conditions is met, you will never clear TNR0IF, so your ISR will be called again and again, but whatever you have in the main code won't execute at all.

It's better to do it like this:

C:
if (INTCON.TMR0IF) {
  // test all the conditions here
  INTCON.TMR0IF = 0;
}

This will ensure that TMR0IF is always cleared in your interrupt.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top