Problem in serial interrupt.

sarang1_in

New Member
Hi all,
I am facing a problem while debugging the code. The following error is comming and it is jumping to disassembly
Error message is
*** 65: access voilation at 0X001B: no 'execute/read' permission
This location is Timer 1 interrupt routine.

My code is as follows
Code:
/*------------------------------------------------------------------------------*/
/*include header files*/
/*------------------------------------------------------------------------------*/
#include<stdio.h>
#include<reg52.h>
#include<math.h>
/*------------------------------------------------------------------------------*/
/*function declerarion*/
/*------------------------------------------------------------------------------*/
//void chkproto(*char);
//void sendserial(unsigned char transmitchar)
/*------------------------------------------------------------------------------*/
/*variable declearation*/
/*------------------------------------------------------------------------------*/
data char recv,Dir,mode,Stat;
bit run,stop,query,queryp,setp;
data char recv_cnt,Step_mode,Steps_no1,Steps_no2,Steps_no3,Vel_1,Vel_2;
unsigned int data Delay;
data int Steps,Vel,Iref,Iidle,ramp_up,Delay_Row,ramp_dn,ramp_step;
code int DLY[4][3]={{5000,2000,200},
					{2000,1000,100},
					{1000,500,50},
					{500,100,10}};
code char stepbit1[]={9,8,10,4,6,3,1}; 
code char stepbit2[]={8,4,3,1};
char data pos_ack[]={':','0','1','R','P','X','E'};
data char Querr_device_no,Profil_no,sencnd,sendchr,send_q;
data char rec_buf[17],send_buf[17];
static char i;
sbit DE =P3^2;
void SerialInt(void)interrupt 4 using 1
{
	if(RI)
  	{	RI = 0;
   		recv = SBUF;
		if( recv == ':')
		{
			recv_cnt = 0;
			rec_buf[recv_cnt] = recv;
		}
		else 
		{
			recv_cnt++;
			if ( recv_cnt >= 16)
			{
				recv_cnt = 0;
			}
			else 
			{
				rec_buf[recv_cnt] = recv;
				if ( recv == 'E'&& rec_buf[(recv_cnt)-1] == 'X')
				{
					if (recv_cnt == 15)
					{
						if ( rec_buf[0] == ':'&& rec_buf[3] == 'R')
 						{	run	= 1;
							Dir = rec_buf[4];
 						    Step_mode = rec_buf[5];
							Steps_no1 = rec_buf[6] * 1000;
							Steps_no2 = rec_buf[7] * 100;
							Steps_no3 = rec_buf[8] * 10;
							Steps = Steps_no1+ Steps_no2+ Steps_no3+ rec_buf[9];
							Vel_1 = rec_buf[10] * 100;
							Vel_2 = rec_buf[11] * 10;
							Vel = Vel_1+ Vel_2+ rec_buf[12];
							Profil_no = rec_buf[13];
						
						}

					}
					else if (recv_cnt == 6)
					{
						if ( rec_buf[0] == ':'&& rec_buf[3] == 'S')
						{
													
						}
 				
					}

					else if (recv_cnt == 6)
					{
						if ( rec_buf[0] == ':'&& rec_buf[3] == 'Q')
						{	
							Querr_device_no = rec_buf[1];
							send_q = 1;
						}
					}
								else if (recv_cnt == 13)
					{
						if ( rec_buf[0] == ':'&& rec_buf[3] == 'P')
						{//i++;
						}

					}
					else if (recv_cnt == 7)
					{
						if ( rec_buf[0] == ':'&& rec_buf[3] == 'Y')
						{//i++;
						}
					}
			 	}
			}
		}
	}
 	if(TI)
	{
		TI = 0;
		sencnd++;
		if ( sencnd == sendchr)
		{
			DE = 0;
		}
		else {
			SBUF = send_buf[sencnd];
		}

	}
}
void Timer0(void)interrupt 1 using 2
{
	switch(Stat)
	{case 1:
			if(mode=='F')
			{if(Dir=='C')
			 {if (ramp_up != 0)
			   {	
			   		P1 = (P1 && 0xF0) || stepbit1[i]; 
					i++;
					if(i == 8)
			   		i = 0;
			    }
			  }
			 else if(Dir=='A')
			{if(ramp_up != 0)	
				{P1 = (P1 && 0xF0) || stepbit1[i];
				 i++;
				 if(i==8)
				 i = 0;
			 	}
			 }
			 }
			else if(mode=='H')
			{if(Dir=='C')
			{
			if (ramp_up != 0)
			   {
			   		P1 = (P1 && 0xF0) || stepbit1[i];
					i++;
					if(i == 4)
			   		i = 0;
			  }
			  }
			 else if(Dir=='A')
			{if (ramp_up != 0)
			   {
				P1 = (P1 && 0xF0) || stepbit1[i];
				i++;
				if(i==0)
				i = 0;
				}
			 }
			 }
			Steps = Steps-1;
			ramp_up = ramp_up-1;
			if(ramp_up==0)
				Stat = 2;
			else 
			   {Delay = Delay - DLY[Delay_Row][3];
				if(Delay < DLY[Delay_Row][2])
				Delay_Row = Delay_Row + 1;
				}
				TL0 = (Delay & 0xFF);
				TH0 = ((Delay >> 8) & 0xFF);
				break;
		case 2: if(mode=='F')
				{if(Dir=='C')
				   {if(Steps<= ramp_step)
			   		{	
			   		  P1 = (P1 && 0xF0) || stepbit1[i]; 
					  i++;
					  if(i == 8)
			   		  i = 0;
				     }
			  		}
			 	 else if(Dir=='A')
					{if(Steps<= ramp_step)
					   {	
						 P1 = (P1 && 0xF0) || stepbit1[i];
						 i++;
						 if(i==8)
						 i = 0;
			 			}
					}
			 }
			else if(mode=='H')
			{if(Dir=='C')
			{if(Steps<= ramp_step)
			   {	
			   		P1 = (P1 && 0xF0) || stepbit1[i];
					i++;
					if(i == 4)
			   		i = 0;
			  	}
			  }
			 else if(Dir=='A')
			{if(Steps<= ramp_step)
				{
				  	P1 = (P1 && 0xF0) || stepbit1[i];
				  	i++;
				  	if(i==0)
				  	i = 0;
			     }
			 }
			}
				Steps = Steps-1;
				if(Steps <= ramp_step)
				{Stat = 3;
				 ramp_dn = ramp_step;
				 }
				 
				//timer0 = Delay;
				break;
		case 3: 
				 if(mode=='F')
				{if(Dir=='C')
				   {if(ramp_step != 0)
			   		{	
			   		  P1 = (P1 && 0xF0) || stepbit1[i]; 
					  i++;
					  if(i == 8)
			   		  i = 0;
				     }
			  		}
			 	 else if(Dir=='A')
					{if(ramp_step !=0)
					   {	
						 P1 = (P1 && 0xF0) || stepbit1[i];
						 i++;
						 if(i==8)
						 i = 0;
			 			}
					}
			 }
			else if(mode=='H')
			{if(Dir=='C')
			{if(ramp_step !=0)
			   {	
			   		P1 = (P1 && 0xF0) || stepbit1[i];
					i++;
					if(i == 4)
			   		i = 0;
			  	}
			  }
			 else if(Dir=='A')
			{if(ramp_step != 0)
				{
				  	P1 = (P1 && 0xF0) || stepbit1[i];
				  	i++;
				  	if(i==0)
				  	i = 0;
			     }
			 }
			}
				ramp_dn = ramp_dn-1;
				Delay = Delay + DLY[Delay_Row][3];
				if( Delay > (DLY[Delay_Row][1]))
					Delay_Row = Delay_Row - 1;
				//timer0 = Delay;
				Steps = Steps-1;
				if(Steps <= 0)
				{Stat = 4;
				 //set timer2 =5000;
				 TR0 = 0;						
				 }
				 break;
			default: break;
}
}
void Timer2 (void) interrupt 5 using 3
{ 	if(run == 1)
	{TR2 = 0;
	ramp_step = 20;
    if((ramp_step*2) < Steps)
		ramp_step = (Steps/2);
		ramp_up = ramp_step;
		//set timer with delay
		Delay_Row =1;
		Stat = 1;
	  }
	  if(Stat == 4)
	  { TR2 = 0;
	  	Iref = 0x7f;
	   }
}
/***************************Timer Isr Ends Here*********************************/
void sendserial(char);
void init_run(void);
//void init_stop(void);
//void send_response(void);
void main(void)
{	
 	P1   = 0x00	;	//Initialise P1.0 to P1.3 used as output & 
			//Initialise P1.4 to P1.7 used as input
	SP   = 0x50;
 	SCON = 0x50;       //Set Serial IO to receive.And select mode1 
 	TMOD = 0x21;       //configure timer for the correct baud rate 
	TH0  = 0x00;
	TL0  = 0xF7;
 	TH1  = 0xFD;       //TH1:  reload value for 9600baud @11.059MHz  
 	TL1  = 0xFD;       //TH1:  reload value for 9600baud @11.059MHz  
 	TCON = 0x00;       //Set timer to not running
    T2CON= 0x00;
	T2MOD= 0x02;
// 	TI   = 0;	//clear transmit interrupt flag
// 	RI   = 0;	//clear receive interrupt flag
// 	TR0  = 1; 	//start timer 0               
 	TR1  = 1;	//start timer to Receive 
	TR2  = 0;
	IE	 = 0xFA; 
  	ET0  = 1;       //enable timer 0 interrupt    
//	ET1	 = 1;
  	EA   = 1;   	//Enable global interrupt  
  	ES   = 1;	//Enable  serial interrupt 
 	PS=1;
 	DE=0;

	while(1)
	{ 
		if(run)
		{	
			sendserial('R');
			init_run();
		}
		if(stop)
		{	
			sendserial('S');
			//init_stop();
		 }
		if(query)
		{
			sendserial('Q');
			//send_response();
		 }
   	 }
}

void sendserial(char command)
{
	int j;
	*(pos_ack+3) = command;
	sencnd = 0;
	sendchr = 7;
	for(j=0; j < 7; j++)
	{
		*(send_buf+j) = pos_ack[j];
		DE = 1;
		TI = 0;
	 }
}

void init_run(void)
{
	run=0;
	TH2=0x13;
	TL2=0x88;
	Iref=0xff;
	Delay=5000;
	TR2=1;
	Stat=1;
}

/*void init_stop(void)
{

}

void send_response(void)
{

}*/
Please tell me where I am wrong as I am stuck to it solving from last so many days and not getting any solution.
Thanks in advance.
 
Have you created a project or are you directly compiling the file?

You need to create a new project frpm project menu and specify the processor that you are using. Add the C file to this project and then try to compile.

I don't see any mistakes in your code. I haven't checked for logical working but syntax wise everything seems fine.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…