#include "biosdem.h" /* a small printf for the lcd Arlotto 2004 */ /* Adaptation de printf qui accepte un seul format parmi d,x,X,o ,u. /* Appel avec deux paramètre : une seule chaîne comportant obligatiorement un format et un int (ou char) * printf for the lcd */ #include #include #include /* * doprnt for PIC. Supports: * * %d decimal * %u unsigned * %o octal * %x hex (lower case) * %X hex (upper case) * %s string * %c character * * On the 14 bit PICS only: * Field widths and precision are supported (precision is significant * only for %s), including variable width, e.g. %*s * * Optionally (on 14 bitters) * * %ld long decimal * %lx long hex (lower case) * %lX long hex (upper case) * %lo long octal * * Even more optionally: * * %f float (really double) - field with and precision supported * %e float - scientific format * */ #ifdef __FLOAT #define __LONG 1 /* float requires long */ #endif #ifdef __LONG #define INT long #else #define INT short #endif #define pputch(c) (++retval, lcd_putchar(c)) unsigned char lcd_small_printf( const char * f, int printedvalue) { #ifdef _PIC16 far char temp[16+1]; far char * where ; #else char temp[16+1]; char * where ; #endif char c; // va_list ap; unsigned char sign; unsigned char prec; unsigned INT i; unsigned char retval; #ifndef _PIC12 signed char width; #else #define width sign #endif where = temp; retval = 0; // va_start(ap, f); while(c = *f++) if(c != '%') pputch(c); else { prec=255; sign = 0; width = 0; /*loop:*/ switch(c = *f++) { case 0: if(where) *where = 0; return retval; case 'd': sign++; goto decimal; case 'x': case 'X': prec += 8; case 'o': prec -= 2; case 'u': decimal: { unsigned INT j; i = (int)printedvalue; if(sign & 1) { if((INT)i < 0) { i = -i; #ifndef _PIC12 width--; #endif } else sign = 0; } else { sign = 0; } prec -= 255-10; /*putint:*/ c = (unsigned INT)i % prec; *(unsigned INT *)&i /= prec; j = 1; while(j <= i) { j *= prec; #ifndef _PIC12 width--; #endif } #ifndef _PIC12 while(--width > 0) #if __FLOAT pputch(sign & 4 ? '0' : ' '); #else pputch(' '); #endif #endif if(sign & 1) pputch('-'); while(j /= prec) { width = (i/j)%prec; if(width > 9) width += 'A'-'0'-10; pputch(width+'0'); } if(c > 9) c += 'A'-'0'-10; pputch(c+'0'); #if __FLOAT if(sign & 2) { pputch('.'); i = frac; sign = 4; width = digs; prec = 10; goto putint; } #endif } break; /* case 'c': #ifndef _PIC12 while(width > 1) { pputch(' '); width--; } #endif c = (int)printedvalue; pputch(c); continue; case 's': { const char * x; x = (const char *)printedvalue; #ifndef _PIC12 c = 0; while(x[c]) c++; if(c < prec) prec = c; while(width > prec) { pputch(' '); width--; } while(prec--) { c = *x++; pputch(c); } #else while(c = *x++) pputch(c); #endif continue; } #ifndef _PIC12 case '.': if(*f == '*') { prec = (int)printedvalue; f++; } else { prec = *f++ - '0'; c = *f; if(c >= '0' && c <= '9') { prec = prec*10 + c - '0'; f++; } } goto loop; default: if(c >= '0' && c <= '9') { width = width * 10 + c - '0'; goto loop; } #else default: #endif pputch(c); continue;*/ } } if(where) *where = 0; return retval; }