Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

reset my ATmega32 in 2 external interrupt

Status
Not open for further replies.

meysam_abbasinia

Advanced Member level 4
Joined
Aug 14, 2007
Messages
105
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
IRAN
Activity points
2,136
hello

I am working with external interrupt 1 and external interrupt 2, I am connecting 2 sensor (SMT160) to these interrupt. but reset my AVR , I fund out that when uc is replay one external interrupt, another external interrupt happens ... uc reset! what must I do?
thank you.
 

There must be something wrong in your code, there is absolutely no problem to have two interrupts happen at the same time , they will either execute one after the other or if you have enabled interrupt recursiveness then the first will be paused until the second one finisher and then the first one will resume.

Can you post your two interrupt functions?
 

this is my code ,
Code:
#include <mega32.h>
#include <stdio.h>
#include <delay.h>
#include <lcd.h>
#include <stdlib.h> 
#include <math.h>
#include <string.h>



// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x1B
#endasm      
//************

unsigned int e,x,y;
int meysam[2];

//************
unsigned char sp[10];
unsigned char rep1,rep2,d,m,b,b1,c,z;
unsigned char sensor;
unsigned char result[200],str[20],load,str3[20],str4[20];   
//--------------------------- mobile
eeprom unsigned char mobile_num1[12];
eeprom unsigned char mobile_num2[12];
eeprom unsigned char mobile_num3[12];
eeprom unsigned char mobile_num4[12];  
unsigned char string_mobile_1[12],string_mobile_2[12],string_mobile_3[12],string_mobile_4[12];
unsigned char rsp[200],rsp5[200],rsp2[10];
//-------------  keypad ---------
unsigned char clumn,ROW,KEY,L;
unsigned char K[16]={10,11,12,13,1,2,3,4,5,6,7,8,9,0,14,15};
// 10='cancel'  11='ok'  12='up'  13='down'  14='menu'  15='F1'
//------------------password
eeprom unsigned char pass[5]={1,2,3,4,5};
eeprom unsigned long int sms_pass=12345;
unsigned long int sms_pass_temp_1,sms_pass_temp_2;
unsigned char temp[20],temp1[20];
unsigned int a;
unsigned int j,i,s,w,v;
unsigned char flag_pakage;
//-------------- temperature varb ------------
float temp_t;
unsigned char temperature_flag,prosses_flag,calc_flag,shab1_flag;
eeprom float t[2];
float DC,temperature,T1,T2;
char final_temperature[4];
unsigned char str1[10],str2[10];
//------------------- time sending sms
unsigned char time_temp;
eeprom unsigned char time;
unsigned long int shab,cnt_0,cnt_1;
//------------- flags
eeprom unsigned char mode_flag=3;
unsigned char sms_flag_0,sms_flag_1;
unsigned char if_flag,ex_finish;
//-------------------- functions -------------
unsigned char Echo_off(unsigned char show);
void Test(void);
void manage_panel(unsigned char L);
unsigned char getkey (void);
void calc_temp(void);
unsigned char check_send(unsigned char show);
unsigned char check_modem(unsigned char show);
//--------------------------------------------
interrupt [EXT_INT0] void ext_int0_isr(void)     
{
	PORTC=0x0F;
	DDRC=0xF0;

	if(PINC.0==0)    {ROW=0; goto soton;}
	else if(PINC.1==0) {ROW=4;goto soton;}
	else if(PINC.2==0)  {ROW=8;goto soton;}
	else if(PINC.3==0)  {ROW=12;goto soton;}


soton:
	PORTC=0xF0;
	DDRC=0x0F;


	delay_ms(150);

	if(PINC.4==0)     {clumn=0; goto out;}
	else if(PINC.5==0) {clumn=1;goto out;}
	else if(PINC.6==0) {clumn=2;goto out;}
	else if(PINC.7==0) {clumn=3;goto out;}

out:
	KEY=ROW+clumn;
	L=K[KEY];

	PORTC=0x0F;
	DDRC=0xF0;
        
	manage_panel(L);

}
// sensor #1           
interrupt [EXT_INT1] void ext_int1_isr(void)
{
         switch (temperature_flag)
        {
                case 0:
                        ex_finish=0; 
                        TCCR0=0x02;
                        TCCR2=0x02;
                        TCNT0=TCNT2=w=v=0;                        
                        // External Interrupt(s) initialization
                        // INT0: On
                        // INT0 Mode: Low level
                        // INT1: On
                        // INT1 Mode: Falling Edge
                        // INT2: Off
                        GICR|=0xC0;
                        MCUCR=0x08;
                        MCUCSR=0x00;
                        GIFR=0xC0;                   
                        temperature_flag=1;
                break;
                case 1:
                        TCCR2=0x00; //DC
                        // External Interrupt(s) initialization
                        // INT0: On
                        // INT0 Mode: Low level
                        // INT1: On
                        // INT1 Mode: Rising Edge
                        // INT2: Off
                        GICR|=0xC0;
                        MCUCR=0x0C;
                        MCUCSR=0x00;
                        GIFR=0xC0;                                             
                        temperature_flag=2;
                break;                     
                case 2:                
                        TCCR0=0x00;   // T
                	calc_temp();                	
                        temperature_flag=0;
                       
                break;        
        }
        
}
// sensor #0
interrupt [EXT_INT2] void ext_int2_isr(void)
{        
        switch (temperature_flag)
        {
                case 0:
                        ex_finish=0; 
                        TCCR0=0x02;
                        TCCR2=0x02;
                        TCNT0=TCNT2=w=v=0;                
                        // External Interrupt(s) initialization
                        // INT0: On
                        // INT0 Mode: Low level
                        // INT1: Off
                        // INT2: On
                        // INT2 Mode: Falling Edge
                        GICR|=0x60;
                        MCUCR=0x00;
                        MCUCSR=0x00;
                        GIFR=0x60;
                        temperature_flag=1;
                break;
                case 1:
                        TCCR2=0x00; //DC
                        // External Interrupt(s) initialization
                        // INT0: On
                        // INT0 Mode: Low level
                        // INT1: Off
                        // INT2: On
                        // INT2 Mode: Rising Edge
                        GICR|=0x60;
                        MCUCR=0x00;
                        MCUCSR=0x40;
                        GIFR=0x60;
                        temperature_flag=2;
                break;                     
                case 2:                
                        TCCR0=0x00;   // T
                	calc_temp();
                        temperature_flag=0;
                                               
                break;        
        }
        
}
//---------------------------------
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
	v++;
}

interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
	w++;

}


void InitMicro(void)
{
 
PORTA=0x00;
DDRA=0x00;

PORTB=0x00;
DDRB=0x00;

PORTC=0x0F;
DDRC=0xF0;  

PORTD=0x00;
DDRD=0xC0;       //PORTD.6 ---->output

TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: On
// INT1 Mode: Rising Edge
// INT2: On
// INT2 Mode: Rising Edge
GICR|=0x00;
MCUCR=0x00;
MCUCSR=0x00;
GIFR=0x00;

TIMSK=0x41;


UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x05;

ACSR=0x80;
SFIOR=0x00;

lcd_init(20);
//------------------------------ in this part we change mobile number to string for sending sms aim eeprom var. can not string
sprintf(string_mobile_1,"%d%d%d%d%d%d%d%d%d%d%d",mobile_num1[0],mobile_num1[1],mobile_num1[2],mobile_num1[3],mobile_num1[4],mobile_num1[5],mobile_num1[6],mobile_num1[7],mobile_num1[8],mobile_num1[9],mobile_num1[10]);
sprintf(string_mobile_2,"%d%d%d%d%d%d%d%d%d%d%d",mobile_num2[0],mobile_num2[1],mobile_num2[2],mobile_num2[3],mobile_num2[4],mobile_num2[5],mobile_num2[6],mobile_num2[7],mobile_num2[8],mobile_num2[9],mobile_num2[10]);
sprintf(string_mobile_3,"%d%d%d%d%d%d%d%d%d%d%d",mobile_num3[0],mobile_num3[1],mobile_num3[2],mobile_num3[3],mobile_num3[4],mobile_num3[5],mobile_num3[6],mobile_num3[7],mobile_num3[8],mobile_num3[9],mobile_num3[10]);
sprintf(string_mobile_4,"%d%d%d%d%d%d%d%d%d%d%d",mobile_num4[0],mobile_num4[1],mobile_num4[2],mobile_num4[3],mobile_num4[4],mobile_num4[5],mobile_num4[6],mobile_num4[7],mobile_num4[8],mobile_num4[9],mobile_num4[10]);
//---------------------------------------------------------------------------
}
void main (void)
{
            InitMicro();                          
            delay_us(200);            
                                     
            //-------------------------------------------------------------
            //************  check modem
            delay_ms(1000);
            lcd_clear();
            Test();
            rep1=check_modem(0);
            lcd_gotoxy(0,3);
            if (rep1==1)
            {
                    lcd_putsf("GSM MODEM IS OK");
            }       
            else {lcd_putsf("PLEASE CALL BFG Co.");}
            delay_ms(2500);
            lcd_clear();		
sensor = 0;
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: Off
// INT2: On
// INT2 Mode: Rising Edge
GICR|=0x60;
MCUCR=0x00;
MCUCSR=0x40;
GIFR=0x60;


            #asm("sei")    
            //delay_ms(3000);
            		
            		           
     	                 			             		           			             			             		     
      while (1)
      {      
            // ------- this part is waiting for coming an sms
            //when we receive sms, get  \r\n+CMTI: "MT",21\r\n
            //for find out that we receive a complete sms package we should receiv tow \n that in decimal is equal 10            
            	j=flag_pakage=0;
		do
            	{
                        rsp[j]=getchar();
             	        if (rsp[j]=='\n' && rsp[j-1]=='\r') {flag_pakage++;}
             	        j++;
        	}while (flag_pakage < 2);
                                    //------- just show what we receive from GSM
                                    /*for (i=0;i<j;i++)
                                    {
                        		sprintf(result,"%c",rsp[i]);
                               		lcd_puts(result);
                               		delay_ms(200);
                                    }*/ 
            #asm ("cli")
            lcd_gotoxy(0,3);
            sprintf (result,"NEW MESSAGE:%c%c      ",rsp[14],rsp[15]); // number of sms on memory of GSM
            lcd_puts(result);
            delay_ms(500);
            printf("AT+CMGR=%c%c%c",rsp[14],rsp[15],0x0D);    // read sms from memory
            j=flag_pakage=0;
            do
            {
                rsp[j]=getchar();
                     if (rsp[j]=='\n' && rsp[j-1]=='\r') {flag_pakage++;}
                     j++;
            }while (flag_pakage < 5);
                                    //---------- just show what we receive from GSM
                                    /*for (i=0;i<j;i++)
                                    {
                        		lcd_clear();
                        		sprintf(result,"%c",rsp[i]);
                               		lcd_puts(result);
                               		delay_ms(300);
                            	    }*/
            //----  mobile number of sms sender
            lcd_gotoxy(0,3);
            lcd_putsf("                    ");
            lcd_gotoxy(4,3);
            for (i=23;i<36;i++)
            {
                sprintf(result,"%c",rsp[i]);
                lcd_puts(result);
            }
            //---------------------------------
            delay_ms(1500);
            lcd_gotoxy(0,3);            
            lcd_putsf("                    ");
            lcd_gotoxy(0,3);
            //----  text of sms , I set 5 digit for password of system this part show first 5 digit of sms
            //-----------------------------------------------
            // in this part I check sms password 
            ltoa(sms_pass,str4);
            sprintf(str3,"%c%c%c%c%c",rsp[63],rsp[64],rsp[65],rsp[66],rsp[67]);
                                    // just show sms
                                    //lcd_clear();
                                    //lcd_puts(str3);
            rep2=strcmp(str3,str4);
            if (rep2==0)             // correct password
            {
                    	lcd_gotoxy(0,3);
                    	lcd_putsf("  CORRECT PASSWORD  ");
                    	printf("AT+CMGS=%c%c%c%c%c%c%c%c%c%c%c%c%c%c",rsp[23],rsp[24],rsp[25],rsp[26],rsp[27],rsp[28],rsp[29],rsp[30],rsp[31],rsp[32],rsp[33],rsp[34],rsp[35],0x0D);
              		for (j=0;j<3;j++) {rsp5[j]=getchar();}
              		printf("TEMP=%d%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,26);
                	rep1=check_send(0);
                	if (rep1==1) 
                	{
                		lcd_gotoxy(0,3);
                    		lcd_putsf("REPLAY SMS SENT     ");
                	}        	  
                	else if (rep1==0)
                	{
                	 	lcd_gotoxy(0,3);
                    		lcd_putsf("        ERROR       ");
                	}
            }
            else			// wrong password
            {
                    	lcd_gotoxy(0,3);
                    	lcd_putsf("   WRONG PASSWORD   ");
                    	printf("AT+CMGS=%c%c%c%c%c%c%c%c%c%c%c%c%c%c",rsp[23],rsp[24],rsp[25],rsp[26],rsp[27],rsp[28],rsp[29],rsp[30],rsp[31],rsp[32],rsp[33],rsp[34],rsp[35],0x0D);
            		for (j=0;j<3;j++) {rsp5[j]=getchar();}
              		printf("Your Password is Wrong.%c----------%cBFG Co. %cwww.bfgq.ir %c",0x0D,0x0D,0x0D,26);        	
                	rep1=check_send(0);
                	if (rep1==1) 
                	{
                		lcd_gotoxy(0,3);
                    		lcd_putsf("   REPLAY SMS SENT  ");
                	}        	  
                	else if (rep1==0)
                	{
                	 	lcd_gotoxy(0,3);
                    		lcd_putsf("        ERROR       ");
                	}
         	            	
            }                                                               
            	delay_ms(2000);
            	printf("AT+CMGD=32%c",0x0D);    
             	do 
     		{
     		        rsp2[j]=getchar();     		
     		        j++;
     		        
     		}while (j < 6);
             			// just show ok 
                    	        /*lcd_clear();    	                			
                     		for (i=0;i<j;i++)
                    		{
                			sprintf(result,"%c",rsp2[i]);
                       			lcd_puts(result);
                       			delay_ms(200);
                    		} */   
                        
            lcd_gotoxy(0,3);            
            lcd_putsf("                    "); 
            #asm("sei")
            
            
      }
}


//--------------  Echo off  -------------------------------------------
// Echo ra khamosh mikonad in ommand
unsigned char Echo_off(unsigned char show)
{
    unsigned char rsp[10];
 	unsigned char result[10];
 	printf("ATE0%c",0x0D);
 	rsp[0]=getchar();         //\r\nok\r\n
	rsp[1]=getchar();
	rsp[2]=getchar();
	rsp[3]=getchar();
	rsp[4]=getchar();
	rsp[5]=getchar();

 	if(show==1)
 	{
 		sprintf(result,"%c%c",rsp[2],rsp[3]);
 		lcd_puts(result);
       	}
 	if(rsp[2]=='O' && rsp[3]=='K') {return 1;}  // yani function  dorost anjam shode va 1 ra barmigardanad
 	else {return 0;}

}
//-------  calculation of temperature
void calc_temp(void)
{
      #asm ("cli")
      //T1=T1+((w*256)+TCNT2)*0.0904;
      //T2=T2+((v*256)+TCNT0)*0.0904;
      T1=T1+((w*256)+TCNT2)*0.7233;
      T2=T2+((v*256)+TCNT0)*0.7233;
      #asm ("sei")
      e++;
      if (e==300)
      {                                               
                #asm ("cli")
                //************************************
                   	
                //************************************
                e=0;
                T1/=300;
                T2/=300;
                DC=(T1/T2);
                temperature=(DC-0.32)/0.0047;
                //ftoa(temperature,1,str2);
                //ftoa(DC,2,str1);
                if (sensor == 0) {meysam[0]=floor(temperature);}
                else if (sensor == 1) {meysam[1]=floor(temperature);}
         	lcd_gotoxy(0,0);
         	lcd_putsf("    TEMPERATURE     ");
         	lcd_gotoxy(0,1);
         	sprintf(result," S1= %d   S2= %d   ",meysam[0],meysam[1]);
         	lcd_puts(result);
         	lcd_gotoxy(0,2);
         	lcd_putsf("--------------------");
 		if (abs (meysam [0]) > (abs (t[0]) + 3 ))
 		{
 		 	lcd_gotoxy(0,3);
         		lcd_putsf("                    ");
         		lcd_gotoxy(0,3);         	
         		lcd_putsf("WARNING SENSOR 1 ");
 		}
 		else 
 		{
 		 		lcd_gotoxy(0,3);
 				lcd_putsf("                    ");
                 		lcd_gotoxy(0,3);
                 		lcd_putsf("NORMAL TEMPERATURE");
                 		//sms_flag_0=0;
     		} 		 		 	 	
          	if (abs (meysam [1]) > (abs (t[1]) + 3 ))
 		{
 		 	lcd_gotoxy(0,3);
         		lcd_putsf("                    ");
         		lcd_gotoxy(0,3);         	
         		lcd_putsf("WARNING SENSOR 2 ");
 		}
 		else 
 		{
 		 		lcd_gotoxy(0,3);
 				lcd_putsf("                    ");
                 		lcd_gotoxy(0,3);
                 		lcd_putsf("NORMAL TEMPERATURE");
                 		//sms_flag_1=0;
     		}
          	T1=T2=0;              	
 		if (mode_flag == 1)
 		{
 		 	
         	       	if (abs (meysam[0]) > (abs (t[0]) + 3 ))
         		{         		 
				if (sms_flag_0 < 2)
				{
					
						printf("AT+CMGS=%s%c",string_mobile_1,0x0D);
						for (j=0;j<3;j++) {rsp5[j]=getchar();}                            		
                              			printf("S1=%d%csms number=1%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,0x0D,26);
                                		rep1=check_send(0);
                                		if (rep1==1) 
                                        	{
                                        		lcd_gotoxy(0,3);
                                            		lcd_putsf("   TIMING SMS SENT  ");
                                        	}        	  
                                        	else if (rep1==0)
                                        	{
                                        	 	lcd_gotoxy(0,3);
                                            		lcd_putsf("        ERROR       ");
                                        	}                                 		
             		       			delay_ms(1000);
             		       			//-----------------
             		       			printf("AT+CMGS=%s%c",string_mobile_2,0x0D);
						for (j=0;j<3;j++) {rsp5[j]=getchar();}                            		
                              			printf("S1=%d%csms number=1%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,0x0D,26);
                                		rep1=check_send(0);
                                		if (rep1==1) 
                                        	{
                                        		lcd_gotoxy(0,3);
                                            		lcd_putsf("   TIMING SMS SENT  ");
                                        	}        	  
                                        	else if (rep1==0)
                                        	{
                                        	 	lcd_gotoxy(0,3);
                                            		lcd_putsf("        ERROR       ");
                                        	}                                 		
             		       			delay_ms(1000);
             		       			//----------------
             		       			printf("AT+CMGS=%s%c",string_mobile_3,0x0D);
						for (j=0;j<3;j++) {rsp5[j]=getchar();}                            		
                              			printf("S1=%d%csms number=1%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,0x0D,26);
                                		rep1=check_send(0);
                                		if (rep1==1) 
                                        	{
                                        		lcd_gotoxy(0,3);
                                            		lcd_putsf("   TIMING SMS SENT  ");
                                        	}        	  
                                        	else if (rep1==0)
                                        	{
                                        	 	lcd_gotoxy(0,3);
                                            		lcd_putsf("        ERROR       ");
                                        	}                                 		
             		       			delay_ms(1000);
             		       			//-------------------
             		       			printf("AT+CMGS=%s%c",string_mobile_4,0x0D);
						for (j=0;j<3;j++) {rsp5[j]=getchar();}                            		
                              			printf("S1=%d%csms number=1%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,0x0D,26);
                                		rep1=check_send(0);
                                		if (rep1==1) 
                                        	{
                                        		lcd_gotoxy(0,3);
                                            		lcd_putsf("   TIMING SMS SENT  ");
                                        	}        	  
                                        	else if (rep1==0)
                                        	{
                                        	 	lcd_gotoxy(0,3);
                                            		lcd_putsf("        ERROR       ");
                                        	}                                 		
             		       			delay_ms(1000);
						sms_flag_0 ++ ;
				 }	
				else 
				{
					cnt_0++;
					if (cnt_0==3600)
					{
						cnt_0=0;
						sms_flag_0=0;
					}							         		
         		 		        
                 		 }
                 		 //------------
                 		 if (abs (meysam[1]) > (abs (t[1]) + 3 ))
         			{         		 
				if (sms_flag_1 < 2)
				{
					
						printf("AT+CMGS=%s%c",string_mobile_1,0x0D);
						for (j=0;j<3;j++) {rsp5[j]=getchar();}                            		
                              			printf("S1=%d%csms number=1%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,0x0D,26);
                                		rep1=check_send(0);
                                		if (rep1==1) 
                                        	{
                                        		lcd_gotoxy(0,3);
                                            		lcd_putsf("   TIMING SMS SENT  ");
                                        	}        	  
                                        	else if (rep1==0)
                                        	{
                                        	 	lcd_gotoxy(0,3);
                                            		lcd_putsf("        ERROR       ");
                                        	}                                 		
             		       			delay_ms(1000);
             		       			//-----------------
             		       			printf("AT+CMGS=%s%c",string_mobile_2,0x0D);
						for (j=0;j<3;j++) {rsp5[j]=getchar();}                            		
                              			printf("S1=%d%csms number=1%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,0x0D,26);
                                		rep1=check_send(0);
                                		if (rep1==1) 
                                        	{
                                        		lcd_gotoxy(0,3);
                                            		lcd_putsf("   TIMING SMS SENT  ");
                                        	}        	  
                                        	else if (rep1==0)
                                        	{
                                        	 	lcd_gotoxy(0,3);
                                            		lcd_putsf("        ERROR       ");
                                        	}                                 		
             		       			delay_ms(1000);
             		       			//----------------
             		       			printf("AT+CMGS=%s%c",string_mobile_3,0x0D);
						for (j=0;j<3;j++) {rsp5[j]=getchar();}                            		
                              			printf("S1=%d%csms number=1%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,0x0D,26);
                                		rep1=check_send(0);
                                		if (rep1==1) 
                                        	{
                                        		lcd_gotoxy(0,3);
                                            		lcd_putsf("   TIMING SMS SENT  ");
                                        	}        	  
                                        	else if (rep1==0)
                                        	{
                                        	 	lcd_gotoxy(0,3);
                                            		lcd_putsf("        ERROR       ");
                                        	}                                 		
             		       			delay_ms(1000);
             		       			//-------------------
             		       			printf("AT+CMGS=%s%c",string_mobile_4,0x0D);
						for (j=0;j<3;j++) {rsp5[j]=getchar();}                            		
                              			printf("S1=%d%csms number=1%c----------%cBFG Co. %cwww.bfgq.ir%c",meysam,0x0D,0x0D,0x0D,0x0D,26);
                                		rep1=check_send(0);
                                		if (rep1==1) 
                                        	{
                                        		lcd_gotoxy(0,3);
                                            		lcd_putsf("   TIMING SMS SENT  ");
                                        	}        	  
                                        	else if (rep1==0)
                                        	{
                                        	 	lcd_gotoxy(0,3);
                                            		lcd_putsf("        ERROR       ");
                                        	}                                 		
             		       			delay_ms(1000);
						sms_flag_1 ++ ;
						
				 }	
				else 
				{
					cnt_1++;
					if (cnt_1==3600)
					{
						cnt_1=0;
						sms_flag_1=0;
					}							         		
         		 		        
                 		 }
                            }
         		} 
 		}
 		else if (mode_flag==2)
 		{
         		shab ++;
         		if (shab == (500)*time) 
         		{         		 	        
         		 	        printf("AT+CMGS=%s%c",string_mobile_1,0x0D);
            				for (j=0;j<3;j++) {rsp5[j]=getchar();}
    					printf("S1=%d%cS2=%d%c----------%cBFG Co. %cwww.bfgq.ir %c",meysam[0],0x0D,meysam[1],0x0D,0x0D,0x0D,26);                              		
                                	rep1=check_send(0);
                                	if (rep1==1) 
                                	{
                                		lcd_gotoxy(0,3);
                                    		lcd_putsf("   REPLAY SMS SENT  ");
                                	}        	  
                                	else if (rep1==0)
                                	{
                                	 	lcd_gotoxy(0,3);
                                    		lcd_putsf("        ERROR       ");
                                	}                  			                     		
                     			delay_ms(1000); 
                     			//-----------------------
                     			printf("AT+CMGS=%s%c",string_mobile_2,0x0D);
            				for (j=0;j<3;j++) {rsp5[j]=getchar();}
    					printf("S1=%d%cS2=%d%c----------%cBFG Co. %cwww.bfgq.ir %c",meysam[0],0x0D,meysam[1],0x0D,0x0D,0x0D,26);                              		
                                	rep1=check_send(0);
                                	if (rep1==1) 
                                	{
                                		lcd_gotoxy(0,3);
                                    		lcd_putsf("   REPLAY SMS SENT  ");
                                	}        	  
                                	else if (rep1==0)
                                	{
                                	 	lcd_gotoxy(0,3);
                                    		lcd_putsf("        ERROR       ");
                                	}                  			                     		
                     			delay_ms(1000);                    			                     			                                                                                         
                     			shab=0;
         		}                                
         	}          	                
          	
       }               
       #asm ("sei")
}
//--------------------------------------------------------------------------
 
Last edited by a moderator:

The use of goto is not needed

This
Code:
 PORTC=0x0F;
    DDRC=0xF0;

    if(PINC.0==0)    {
        ROW=0;
        goto soton;
    }
    else if(PINC.1==0) {
        ROW=4;
        goto soton;
    }
    else if(PINC.2==0)  {
        ROW=8;
        goto soton;
    }
    else if(PINC.3==0)  {
        ROW=12;
        goto soton;
    }


soton:
    PORTC=0xF0;
    DDRC=0x0F;

is exactly the same as

Code:
 PORTC=0x0F;
    DDRC=0xF0;

    if(PINC.0==0)    {
        ROW=0;
    }
    else if(PINC.1==0) {
        ROW=4;
    }
    else if(PINC.2==0)  {
        ROW=8;
    }
    else if(PINC.3==0)  {
        ROW=12;
    }

    PORTC=0xF0;
    DDRC=0x0F;

and the same principle applies to the goto out

It is also a very bad practice to execute long code inside the interrupt.
In int0 you can manage_panel(L); which includes a delay_ms(100); and a very long code.


So what you are doing in int1 and int2 is to change the interrupt settings from inside the interrupt, I'm not sure if this is the problem (I have never done anything like that) but you can either set a flag variable and change the interrupt settings in the main or you can set the interrupt to trigger at both edges and then just detect in the start of the interrupt in it is a falling or rising edge by reading the int pin.

Also note that you call calc_temp(void) from the interrupt and in that function you are using #asm ("sei") which will execute any pending interrupt recursively and can mess things up.
 

thank you for your corrections.
I can not use interrupt to trigger at both edges because we can use "any change " just in Interrupt 1 not in both 1 and 2.

my code in manage_panel is scandal! I know. but I cant change it's architecture now. and this part is not my problem. I want calculate temperature in calc_temp() function so I don't have any interrupt so I used #asm ("sei").
now , I want to read both sensor with both external interrupt how can I switch between external interrupts ? I can not set a flag on external interrupt and use that on while (1) because if you see I use getchar() function in while (1) means I am polling here.
 

Maybe you can swap the int0 and int2 , then you can use int0 and int1 with any change settings and int2 for what int0 does but this would also require hardware changes.
 

I can not change my hardware, my friend.
in this code where can I turn off int2 and turn on int1 and after 300 sample turn on int2 and turn off int1.

such as this :
switch (sensor)
{
case 0:
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: On
// INT1 Mode: Rising Edge
// INT2: Off
GICR|=0xC0;
MCUCR=0x0C;
MCUCSR=0x00;
GIFR=0xC0;
sensor = 1;
break;
case 1:
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Low level
// INT1: Off
// INT2: On
// INT2 Mode: Rising Edge
GICR|=0x60;
MCUCR=0x00;
MCUCSR=0x40;
GIFR=0x60;
sensor = 0;
break;
}

I use this code in calc_temp() function but uc reset.
 

I don't know what exactly causes the problem , I usually set the interrupts once in the start of the code so I haven't faced anything similar.
 

because for detect duty cycle of a signal (SMT160 work with Duty Cycle) I set int2 in rising edge mode and start timer0 and timer2 when I received int2. after that I set it in falling edge and after received int2 I turn off timer2 and set int2 in rising edge another time , after I received int2 now turn off timer0 , now we can calculate duty cycle of signal.

I hope explain clear.

I think we can not have tow external interrupt . so I am testing with turn on or off sensor when I need read it.
 

The input capture unit of timer1 would be more appropriate I think to measure the duty of a signal but again this requires a hardware change that is not possible.
 

yes you are right if I can't do that with turn on/off sensor, I should use Input capture with less hardware destroyer!
thank you for your time friend , I will say you result of this idea.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top