📄 printf.c
字号:
/**************************************************************************
**
** Revision History
**
** when what who why
**
** 2002-03-15 1.0 Jesper initial release
** 2003-01-01 1.1 MIS added compatibility with new versions of GCC
**
*********************************************************************** */
#include "Constants.h"
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include <avr/pgmspace.h>
#include "types.h"
#include "yampp7lib.h"
void _p_puts(char const *p)
{
u08 b;
while (p && (b = PRG_RDB(p++)))
lcd_putchar(b);
}
int _p_vprintf(char const *format,va_list ap)
{
u08 scratch[16];
u08 format_flag;
u32 u_val=0;
u08 base;
u08 *ptr;
u08 width;
u08 fill;
while(1)
{
width = 0;
fill = ' ';
while ((format_flag = PRG_RDB(format++)) != '%')
{
if (!format_flag)
{
va_end (ap);
return (0);
}
lcd_putchar(format_flag);
}
// check for zero pad
format_flag = PRG_RDB(format) - '0';
if (format_flag == 0) // zero pad
{
fill = '0';
format++;
}
// check for width spec
format_flag = PRG_RDB(format) - '0';
if (format_flag > 0 && format_flag <= 9) // width set
{
width = format_flag;
format++;
}
switch (format_flag = PRG_RDB(format++))
{
case 'c':
format_flag = va_arg(ap,int);
//fall through
default:
lcd_putchar(format_flag);
continue;
case 'S':
case 's':
ptr = va_arg(ap,char *);
while (*ptr)
lcd_putchar(*ptr++);
continue;
case 'u':
base = 10;
goto CONVERSION_LOOP;
case 'x':
base = 16;
CONVERSION_LOOP:
u_val = va_arg(ap,unsigned int);
ptr = scratch + 16;
*--ptr = 0;
do
{
char ch = u_val % base + '0';
if (ch > '9')
ch += 'a' - '9' - 1;
*--ptr = ch;
u_val /= base;
if (width)
width--;
} while (u_val);
while (width--)
*--ptr = fill;
while (*ptr)
lcd_putchar(*ptr++);
}
}
}
int _p_printf(char const *format, ...)
{
va_list ap;
va_start (ap, format);
return _p_vprintf(format,ap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -