[SOLVED] several interrupts 8051 problem !!

Status
Not open for further replies.

#MAAM#

Full Member level 2
Joined
Nov 21, 2009
Messages
131
Helped
29
Reputation
58
Reaction score
27
Trophy points
1,308
Location
Egypt
Activity points
1,920
hi,

my code is too long so i put snapshot of my code



Code:
#include<..........>
.
.
.
.
.
main()
{
......
}

void down(void)//down
{

			ES=0; //disable serial ISR
			timer_flag=0;
			ph_sensor_error();
			motor_direction=ANTI_CLOCK_WISE;
			while(ph_sensor_down==OFF && timer_flag==0)
				motor_power=ON;
			motor_power=OFF;
			timer_flag=0;
			ES=1; //enable serial ISR
				
}

void ph_sensor_error(void)
{ 
	TR0 = 1;                      /* Start Timer 1 Running */	
}

/*** timer0 interrupt service routine ***/
void timer0_ISR (void) interrupt 1
{
	TR0 = 0;
	TF0 = 0;
	TH0 = 0x00;              
	TL0 = 0x00;
	counter++;   // Increment the overflow count 
	if(counter>=10)//0.71s
		{
			TR0 = 0;
			TF0=0;
			counter=0;
			timer_flag=1;
		}
	else
		TR0 = 1;

}

/*** serial interrupt ***/ 
void serial_ISR (void) interrupt 4  
{
	unsigned char moh=0;
	if (RI == 1)
    {
    	RI = 0;
		moh=SBUF;
		if(SBUF==0x31)
			down();
	
		    }*/
			
}

my problem is when i entered in serial_ISR and the SBUF=0x31 it mean the condition true,when i call down() function i can not from it enter to timer0_ISR never. how can i solve this problem?
 

hi...
the first that you need to do here is stop calling a function from whithin the ISR.....
use a flag to indicate match condition in the ISR and in the main loop check the flag to call down function....
by the way have u checked whether u are actually getting 0x31 in SBUF....

- - - Updated - - -

hi...
the first that you need to do here is stop calling a function from whithin the ISR.....
use a flag to indicate match condition in the ISR and in the main loop check the flag to call down function....
by the way have u checked whether u are actually getting 0x31 in SBUF....
 


thank you for your help but my problem solved with other way. I set priority for timer0_ISR higher than serial_ISR so in this case serial_ISR can be interrupted with timer0_ISR. I did it with this code
Code:
IPL0 = 0x02; //make serial interrupt lower priority than timer0 to be can interrupt
IPH0 = 0x00; //serial ISR with timer0 ISR
i used at89c51ed2.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…