NumberPrintingFunctions.c

00001 00031 #include <chipcon/hal.h> 00032 #include <chipcon/partCStack.h> 00033 00039 void sendByteToUart(unsigned char i) { 00040 byte b; 00041 /* if (digits > 2) 00042 putchar(i/100 % 10 + 48); 00043 if (digits > 1) 00044 putchar(i/10 % 10 + 48); 00045 if (digits > 0) 00046 putchar(i % 10 + 48); */ 00047 b= i >> 4; 00048 putchar((b < 10) ? (b + 48) : (b + 55)); 00049 b= i & 0xF; 00050 putchar((b < 10) ? (b + 48) : (b + 55)); 00051 } 00052 00058 void sendByteToUartBinary(unsigned char i) { 00059 byte j; 00060 for (j=0; j<8; j++) { 00061 putchar((i & 0x80) ? '1' : '0'); 00062 i*= 2; 00063 } 00064 } 00065 00066 00073 void sendSignedByteToUart(signed char i, byte digits) { 00074 if (i<0) { 00075 putchar('-'); 00076 i= -i; 00077 } else { 00078 putchar(' '); 00079 } 00080 if (digits > 2) 00081 putchar(i/100 % 10 + 48); 00082 if (digits > 1) 00083 putchar(i/10 % 10 + 48); 00084 if (digits > 0) 00085 putchar(i % 10 + 48); 00086 } 00087 00088 00095 void sendUshortToUart(unsigned short i) { 00096 byte a; 00097 a= 1; 00098 do { 00099 sendByteToUart(i >> (8*a)); 00100 } while (a--); 00101 } 00102 00109 void sendUlongToUart(ulong i) { 00110 byte a, b, print; 00111 a= 3; 00112 print= FALSE; 00113 do { 00114 b= i >> (8*a); 00115 if (b || a == 0) 00116 print= TRUE; 00117 if (print) 00118 sendByteToUart(b); 00119 } while (a--); 00120 } 00121 00126 void sendStringToUart(char *c) { 00127 while (*c) { 00128 putchar(*c); 00129 c++; 00130 } 00131 } 00132

Generated on Fri Aug 27 10:04:02 2004 for Cheap Sensor Network by doxygen 1.3.8