⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex3_utility.c

📁 基于摩托罗拉S12标准源程序 包括:SCIO,Timer
💻 C
📖 第 1 页 / 共 2 页
字号:
	
	*i_ptr=0;

	while(loop == ENABLE)
	{
	  echo=rx_char0();
	  if((echo==ESC)||(echo==DOT)||(echo==CR)) 
	    loop = DISABLE;			//break the while loop		
      if (echo==BS || echo==DEL)
      {
       	if(count>0) 			//del 4 bit data in buffer
       	{
       	  count--;
       	  *i_ptr=*i_ptr>>4;
	      tx_char0(echo);		//send bs the char on screen
	      tx_char0(' ');		//send space to clear the char
	      tx_char0(echo);		//send bs again to move back the cursor
	    }
      }
      if (count<4)				//update 4 bit data to buffer
      {
	    if((echo<='f') && (echo>='0')) 
	    {
	      if (echo>='a')  echo-=(0x20); 	//covert upper case
	      if ((echo>='0') && (echo<='9'))
	  	    cdata=echo-0x30; 
	      else
	        cdata=echo-0x37;
	      count++; 
	      tx_char0(echo);			//send echo to screen
	  	  *i_ptr=(*i_ptr<<4);
	      *i_ptr+=cdata;
	    }	
	  }
	}  

	if(count!=0 && echo==CR) 
	  return(OK);
	else 
	  return(NOTOK);
}

/*******************************************************************
* Input byte (hex) subroutine
* Description : Get the data(byte) from user  
*             : 
*			  :
* Example     : N/A 
* Input 	  : N/A
* Output	  : *c_ptr
* Modify      : N/A
* Return      : status [OK for ('0'-'z') or NOTOK for others chars]
*********************************************************************/ 
byte input_byte(byte *c_ptr) 
{
	byte		echo,cdata,loop=ENABLE;	
	int			count=0;
	
	*c_ptr=0;

	while(loop == ENABLE)
	{
	  echo=rx_char0();
	  if((echo==ESC)||(echo==DOT)||(echo==CR)) 
	    loop = DISABLE;			//break the while loop		
      if (echo==BS || echo==DEL)
      {
       	if(count>0) 			//del 4 bit data in buffer
       	{
       	  count--;
       	  *c_ptr=*c_ptr>>4;
	      tx_char0(echo);		//send bs the char on screen
	      tx_char0(' ');		//send space to clear the char
	      tx_char0(echo);		//send bs again to move back the cursor
	    }
      }
      if (count<2)				//update 4 bit data to buffer
      {
	    if((echo<='f') && (echo>='0')) 
	    {
	      if (echo>='a')  echo-=(0x20); 	//covert upper case
	      if ((echo>='0') && (echo<='9'))
	  	    cdata=echo-0x30; 
	      else
	        cdata=echo-0x37;
	      count++; 
	      tx_char0(echo);			//send echo to screen
	  	  *c_ptr=(*c_ptr<<4);
	      *c_ptr+=cdata;
	    }	
	  }
	}  
	
	if (echo==DOT||echo ==ESC){
	   *c_ptr=echo;
	   return(OK);
	   }

	if(count!=0 && echo==CR)
	  return(OK);
	else 
	  return(NOTOK);
}

/*******************************************************************
* Input String (ASCII) subroutine
* Description : Get the data(byte) from user  
*             : 
*			  :
* Example     : N/A 
* Input 	  : N/A
* Output	  : *c_ptr
* Modify      : N/A
* Return      : status [OK for ('0'-'z') or NOTOK for others chars]
*********************************************************************/ 
byte input_string(byte *c_ptr, byte *n) 
{
	byte	echo,loop=ENABLE;	
	byte	count=0;

	while(loop == ENABLE)
	{
	  echo=rx_char0();
	  if((echo==ESC)||(echo==DOT)||(echo==CR)) 
	    loop = DISABLE;			//break the while loop		
      if (echo==BS || echo==DEL)
      {
       	if(count>0) 			//del 4 bit data in buffer
       	{
       	  count--;
       	  c_ptr--;
	      tx_char0(echo);		//send bs the char on screen
	      tx_char0(' ');		//send space to clear the char
	      tx_char0(echo);		//send bs again to move back the cursor
	    }
      }
      if ((count<0x80)&&(echo!=DEL)&&(echo!=BS))				//update 4 bit data to buffer
      {
	      count++; 
	      tx_char0(echo);			//send echo to screen
	      *c_ptr++=echo;
	  }
	}  
	
	if (echo==DOT||echo ==ESC){
	   *c_ptr++=echo;
	   *c_ptr='\r';
       *n=count;
	   return(OK);
	   }

	if(count!=0 && echo==CR)
	{
	  tx_char0('\n');			//send echo to screen
      *c_ptr='\r';
      *n=count;
	  return(OK);
	}
	else 
	  return(NOTOK);
}

/*******************************************************************
* Input byte (dec) subroutine
* Description : Get the data(byte) from user  
*             : 
*			  :
* Example     : N/A 
* Input 	  : N/A
* Output	  : *c_ptr
* Modify      : N/A
* Return      : status [OK for ('0'-'z') or NOTOK for others chars]
*********************************************************************/ 
byte input_dec(byte *c_ptr) 
{
	byte		echo,cdata,loop=ENABLE;	
	int			count=0,i_data,i_data1,i_data2,i,j;
	
	i_data=0;
	*c_ptr=0;
	while(loop == ENABLE)
	{
	  echo=rx_char0();
	  if((echo==ESC)||(echo==DOT)||(echo==CR)) 
	    loop = DISABLE;			//break the while loop		
      if (echo==BS || echo==DEL)
      {
       	if(count>0) 			//del 4 bit data in buffer
       	{
       	  count--;
       	  i_data=i_data>>4;
	      tx_char0(echo);		//send bs the char on screen
	      tx_char0(' ');		//send space to clear the char
	      tx_char0(echo);		//send bs again to move back the cursor
	    }
      }
      if (count<3)				//update 4 bit data to buffer
      {
	    if((echo<='9') && (echo>='0')) 
	    {
//	      if ((echo>='0') && (echo<='9'))
	  	    cdata=echo-0x30; 
	      count++; 
	      tx_char0(echo);			//send echo to screen
	  	  i_data=(i_data<<4);
	      i_data+=cdata;
	    }	
	  }
	}  
	
	if (echo==DOT||echo ==ESC){
	   *c_ptr=echo;
	   return(OK);
	   }

	if(count!=0 && echo==CR)
	{
	  for (i=0;i<count;i++)
	  {
	     i_data1 = ((i_data)>>((unsigned char)(4*i))&0xf);
	     i_data2=1;
		 for(j=0;j<i;j++)
		   i_data2 *= 10;
	     *c_ptr+= i_data1*i_data2;
	  }
	  return(OK);
	}
	else 
	  return(NOTOK);
}

/*******************************************************************
* Display internal memory to screen subroutine
* Description : User inputs the internal memory start address 
*             : and end address  
*			  :
* Example     : start_add=0x1000; end_add=0x1200 
* Input 	  : start_add and end_add
* Output	  : N/A
* Modify      : register D 
* Return      : status (OK or NOTOK) 
*********************************************************************/ 
void data_display()
{
	unsigned int	*word,temp,start_add,end_add,i,j;
	unsigned int	itemp;
	byte			*ptr,add_status,lf;
	
	word=&temp;
	
	printf0("\n\r");	
	printf0("	Start Address = \r");
	if(input_word(word)==OK)
	{
	  start_add = *word;
	  add_status = OK;
	}
	else
	  add_status = NOTOK;
	  
	printf0("\n\r");	
	printf0("	End Address = \r");
	if(input_word(word)==OK)
	  end_add = *word;
	else
	  end_add = start_add+0x100;  

	itemp=end_add-start_add;
	if((itemp)>0)
	{  
	  ptr=(byte *)start_add;		//point to start address
	  j=16;
	  for (i=0; i<(end_add-start_add);i++)
	  {
	    if (j>=16)
	    {
	    	printf0("\n\r");
	     	temp=(int)ptr;
			hex_asc((byte)(temp>>8));
			hex_asc((byte)(temp));
		    printf0(" : \r");
	    	j=0;
	    }
	    hex_asc(*ptr++);
	    tx_char0(' ');
	    j++;
	    if(j>=16)
	    {
	      ptr-=16;
	  	  for(lf=0;lf<16;lf++)
	  	  {
	  	    if((*ptr>='0')&&(*ptr<'z'))
	  	      tx_char0(*ptr);
	  	    else if (*ptr==' ')
	  	      tx_char0(' ');
	  	    else
	  	      tx_char0('.');  
	  	    ptr++;
	      }
	    }
		if(check_user_abort()==OK)
		  i=(end_add-start_add);
	  }  
   	  printf0("\n\r");	
	}
}

/*******************************************************************
* init RAM subroutine
* Description : Display RAM /Flash data to terminal via RS232
*			  :
* Example     : N/A  
* Input 	  : Address
* Output	  : RAM / Flash content
* Modify      : N/A
* Return      : N/A
********************************************************************/ 
void init_RAM_start_address()
{
	unsigned int	*word,add;
	
	word=&add;
	printf0("\nRAM Start Address (0x1000-0x3fff) (\r");
	hex_asc((byte)(RAM_Add>>8));
	hex_asc((byte)(RAM_Add));
	printf0(") = \r");
	if(input_word(word)==OK) 
	{
    if((*word>0xfff) &&(*word<0x4000) )
    {  
	    RAM_Add = *word;
	    modify_ram();
    } 
    else 
    {
	    printf0("\nOut of Range\r");
      
    }
  }
}

/*******************************************************************
* Modify RAM subroutine
* Description : Modify RAM content via RS232
*			  :
* Example     : N/A  
* Input 	  : data to be changed
* Output	  : modified the specify data
* Modify      : N/A
* Return      : N/A
********************************************************************/ 
void modify_ram()
{
	unsigned int	ram;
	int			loop=ENABLE;
	byte		*ptr,*ptr1,c_add;

  printf0("\n\r");
  printf0("\nRAM  Data\n\r");

	ram=RAM_Add;
	while(loop==ENABLE)
	{
	  if((ram>0xfff) &&(ram<0x4000)) 
	  {  
      hex_asc((byte)(ram>>8));
	    hex_asc((byte)(ram));
	    tx_char0(' ');
	
	    ptr=(byte *)ram;		//point to start address
	    hex_asc((byte)(*ptr));
	    tx_char0(' ');

	    ptr1=&c_add;
	    if(input_byte(ptr1)==OK)
	    {
	      if (((*ptr1)==DOT)||((*ptr1)==ESC))
	       loop = DISABLE;
	      else
	      {   
	        ptr=(byte *)ram;
	        *ptr=*ptr1;      
	      }
	    }
	    ram++;
  	  printf0("\n\r");
	  } 
	  else 
      loop = DISABLE;
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -