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

📄 zprint.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
📖 第 1 页 / 共 2 页
字号:
				if( max )
					max++;
				if( max <= length )
					max = length+1;
			}
		}

		if( !(format & 0x40) )		/* right alignment	*/
		{
			while( (min > max) && (min > length) )
			{
			     	CommPutChar( (format & 0x20) ? '0' : ' ', UartOut_NO );
				min--;
			}
		}

		if( (format & 0x10) && (ch != 'o') )
		{
		      	CommPutChar( '0', UartOut_NO );	/* leading 0 */
			CommPutChar( ch, UartOut_NO );	/* and 'x' */
		}

		while( max-- > length )
		{
		       	CommPutChar( '0', UartOut_NO );
			if( min )
				min--;
		}

	}
	/* now print the ascii value, padded with spaces */
	CommPutString( format, min, 0, buf, UartOut_NO);
}

/*
  ===============================================================
  Description:	 used to create all different formatting routines 
                 for _printf().No Support Float Format                    
                                                                         
  NOTE	:        One thing in this formatter  is the printing of
                 pointer values '%p' will print a 'huge' pointer (ANSI)
  ===============================================================
*/
void DoPrint( INT8U UartOut_NO, const char *fmt, va_list ap )
{


	register int min;		/* minimum length of output field */
	register int max;		/* maximum length of output field */


	register unsigned char ch;	/* character in format string	  */
	register unsigned char format;	/* b6 - left alignment		  */
					/* b5 - zero fill		  */
					/* b4 - alternate print		  */
					/* b3,b2 - 0x04 --> always sign	  */
					/*       - 0x08 --> sign or space */
					/* b1,b0 - 0x01 --> short	  */
					/*       - 0x02 --> long	  */
					/*       - 0x03 --> double	  */
	unsigned char mxflg = 0;	/* Flag if a maximum length */
					/* specifier is found */

	//unsigned int characters = 0;	/* no characters written yet	  */

	for( ;; )
	{
		ch = *fmt++;
		if( !ch )
		{
		       return ;
		}
		else if( ch == '%' )
		{
			if( *fmt != '%' )
				goto nxt;
			fmt++;
		}
		CommPutChar( ch, UartOut_NO );
		continue;

		nxt:


		format = min = max = 0;



		while( 1 )
		{
			ch = *fmt++;
			if( ch == '-' )
				format |= 0x40;	/* left alignment */
			else if( ch == '+' )
				format = (format & 0xF3) | 0x04;
			else if( ch == ' ' )
			{
				/* do not overrule '+'	*/
				if( !(format & 0x0C) )
					format |= 0x08;	/* sign or space */
			}
			else if( ch == '0' )
				format |= 0x20;	/* zero fill */
			else if( ch == '#' )
				format |= 0x10;	/* alternate print */
			else
				break;
		}

		if( ch == '*' )
		{	/* next argument is minimum field width specifier */
			min = va_arg( ap, int );
			if( min < 0 )
			{
				format |= 0x40;
				min = -min;
			}
			ch = *fmt++;
		}
		else
		{
			while( ch >= '0' && ch <= '9' )
			{	/* get minimum field width */
				min = min * 10 + ch - '0';
				ch = *fmt++;
			}
		}
		if( ch == '.' )
		{	/* next argument is maximum field width specifier */
			format &= ~0x20u;	/* zero fill must be disabled */
			mxflg = 1;		/* read a value for 'max' */
			if( (ch = *fmt++) == '*' )
			{
				max = va_arg( ap, int );
				if( max < 0 )
				{
					format |= 0x40;
					max = -max;
				}
				ch = *fmt++;
			}
			else
			{
				while( ch >= '0' && ch <= '9' )
				{	/* get maximum field width */
					max = max * 10 + ch - '0';
					ch = *fmt++;
				}
			}
		}


		do
		{
			if( ch == 'l' )
			{
				format |= 0x02;
			}
			else if( ch == 'h' )
			{
				format |= 0x01;
			}
			else if( ch == 'L' )
			{
				format |= 0x03;
			}
			else
				continue;

			ch = *fmt++;
		} while( 0 );

		if( ch == 'c' || ch == 'd' || ch == 'i' || ch == 'o' ||
		    ch == 'x' || ch == 'X' || ch == 'u' )
		{
			/* character			*/
			/* signed decimal integer	*/
			/* unsigned octal int		*/
			/* unsigned hexadecimal int	*/
			/* unsigned decimal int		*/
			/* int, single character	*/

			CommPutNumber( min, max, ch, format,
				    (format & 0x03) == 0x02 ?
					(void *)&va_arg( ap, long ) :
					(void *)&va_arg( ap, int ),
				    UartOut_NO );

		}
		else if( ch == 's' )
		{
			/* string */

			CommPutString( format, min, max, va_arg( ap, char * ),
				    UartOut_NO);

		}
		else if (ch == 'S')
		{      /* Hex String*/

		       CommPutStringHex( format, min, max, va_arg( ap, char * ),
				    UartOut_NO);
		}
		else if( ch == 'f' || ch == 'e' || ch == 'E' ||
			 ch == 'g' || ch == 'G' )
		{
			/* floating point	*/
        		/* Only supported on 'LARGE' formatter */
			if( !mxflg )
				max = 6;
			//_doflt(	min, max, ch, format, (double *)&va_arg( ap, double ), 
			//	UartOut_NO);

		}
		else if( ch == 'p' )
		{
                 	/* Print as '<_far>%01X:%04X' or '<_far>%04X' */
		      //	if ( !(format & 0x03) )
		     //	{
				format |= 0x03;	/* huge pointer */
		     //	}

			/* At this point, (format & 0x03) represents : 	*/
			/*	0x01 -> Near pointer (%p or %hp)	*/
			/*	0x02 -> Far pointer  (%p or %lp)	*/
			/*	0x03 -> Huge pointer (%Lp)		*/

			/* misuse 'max' */
			max =	(format & 0x03) == 0x01 ? PTR_LENGTH_NEAR :
			        (format & 0x03) == 0x02 ? PTR_LENGTH_FAR  :
			                                  PTR_LENGTH_HUGE ;
			if( !(format & 0x40) )
			{	/* right alignment ?	*/
				for( ; min>max; --min )
				{
				      	CommPutChar( ' ', UartOut_NO );
				}
			}


			CommPutStringSmall( (format & 0x03) == 0x01 ? "<_near>" :
				(format & 0x03) == 0x02 ? "<_far>" :
							  "<_huge>", 
				UartOut_NO	);

			/* <_near>XXXX, <_far>XX:XXXX, <_huge>XX:XXXX */
//#if _MODEL == 'm' || _MODEL == 'l' || _MODEL == 'c' || _MODEL == 'h'

			if ( (format & 0x03) != 0x01 )
			{
			    CommPrintHex( (*(char **)ap)[2], UartOut_NO );
			    CommPutChar( ':', UartOut_NO );
			}
//#endif
			for( ch = 2; ch-- != 0; )
			{	/* ch = 1, ch = 0 */
			    CommPrintHex( (*(char **)ap)[ch], UartOut_NO);
			};

			for( ; min>max; --min )
			{
				CommPutChar( ' ', UartOut_NO );
			}



			//if( (format & 0x03) == 0x01 )
			//	va_arg( ap,  void * );
		   //else if( (format & 0x03) == 0x02 )
		//		va_arg( ap, void * );
			//else
				va_arg( ap,  char * );

		}
		else if( ch == 'n' )
		{
		    ; 
		}
		else
		{
		    return ;
		}     
	}
}



/*
 ===================================================================
 Description:	Print Function Such as printf in dos
		support multiple mode
		%d %x %p %x %s %S(hex string)......  
		\t \r \n .....

 Note:	       1. intal uart before execute printu fucntion
 	       2. 0x0d(\r) 0x0a(\n)
	       3. example
	       INT8U TestVar = 0x10;
	       Printu("TestPrint TestVar:d:%d\tHex:%x\tPtr:%p\t%lx\r\n", TestVar, TestVar, &TestVar, &TestVar);
	       result:	TestPrint TestVar:d:16  Hex:10  Ptr:<_huge>00:83FA      83fa
 ===================================================================
*/
void Printu( const char *format, ... )
{
   #if STDOUT <=3
   va_list             ap;
     
   va_start( ap, format );
   DoPrint( STDOUT, format, ap );
   va_end( ap );
     #else
     format = format;
     #endif
   return ; 		
 
}
void Printu_Net(const char *format, ...)
{
  format = format;
 /*  va_list             ap;
     
   va_start( ap, format );
   DoPrint( STDOUT, format, ap );
   va_end( ap );
     */
   return ; 		

}

/*
 ===================================================================
 Description:	Print String Hex and Ascii
 ===================================================================
 */

void PrintString(INT8U Type,INT8U *Str, INT16U Len)
{
  Type = Type;
  Str = Str;
  Len = Len;
  if(NULL==Str) return ;
    if('c'==Type) 
       {
        while(Len--)
          Printu("%c",*Str++);
       }
     if('x'==Type) 
       {
        while(Len--)
           Printu("%x ",*Str++);
       }
    
}    




⌨️ 快捷键说明

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