diff --git a/examples/PrintArdui/PrintArdui.ino b/examples/PrintArdui/PrintArdui.ino new file mode 100644 index 0000000..76641d8 --- /dev/null +++ b/examples/PrintArdui/PrintArdui.ino @@ -0,0 +1,35 @@ +// TestSerial +void setup() { + Serial.begin(9600); +} +int16_t v16s; uint16_t v16; uint8_t v8; +void loop() { + Serial.println("Test TerSer"); + v8= 19; Serial.println(v8,BIN); + v16= 1000; Serial.println(v16,HEX); + v16s= 0; Serial.println(v16s); + v16s= 5; Serial.println(v16s); + v16s= 23124; Serial.println(v16s); + v16s= -200; Serial.println(v16s); + v16= 200; Serial.println(v16); + + for(;;); +} + +/* +PrintArdui vide 1426b 184v 1966b 205v +0 +5 +23124 +-200 +200 + + */ + +/* + Test Serial.h 1970b 204v Empty 1426b 184v +544b +20v +7F127127 +81129-127 +FF255-1 + + */ diff --git a/examples/TerSerMainTest/TerSer.h b/examples/TerSerMainTest/TerSer.h new file mode 100644 index 0000000..558b76c --- /dev/null +++ b/examples/TerSerMainTest/TerSer.h @@ -0,0 +1,275 @@ +// TerSer.h 4 modes 190323 +// ~280 lines ~7700 car +//add to main program #include "TerSer.h" SetupTerSer(); +// or from Arduino lib #include SetupTerSer(); +void SetupTerSer() { + UBRR0= 103; // 9600 + UCSR0B=0x18; // -- -- -- rxe txe -- -- -- + UCSR0C=0x06; // set mode: 8 data bits, no parity, 1 stop bit +} + +uint8_t moz=0; // Default value +#define Normal moz=0 +#define Spaces moz=1 +#define Zeros moz=2 +#define Compact moz=3 + +uint8_t Get() { // read blocking + while (!(UCSR0A&0x80)); // wait + return UDR0; +} + +void Car( uint8_t dd) { // write blocking + while(!(UCSR0A&0x20));// wait + UDR0=dd; // OK, send it now! +} + +void CR() { + Car(13);Car(10); // CR LF +} + +void Text(const char str[]) { + for (uint8_t i=0; i< strlen(str); i++) { Car(str[i]); } +} + +void Textln(const char str[]) { + for (uint8_t i=0; i< strlen(str); i++) { Car(str[i]); } + Car(13);Car(10); +} + +void TtBin8 (uint8_t bb) { // auxiliary function + for (uint8_t i=0;i<8;i++) { + if (bb&0x80) Car('1'); + else Car('0'); + bb <<= 1; + } +} +void Bin8 (uint8_t bb) { + TtBin8 (bb); Car(' '); +} +void Bin16 (uint16_t bb) { + TtBin8 (bb>>8); Car('.'); + TtBin8 (bb&0xFF); + Car(' '); +} + +char ConvNibble (uint8_t nn) { // 4 bit binary to Ascii + uint8_t cc; + if (nn<10) {cc = nn + '0';} + else {cc = nn-10 + 'A';} + return cc; +} + +void Hex8 (uint8_t hh) { + uint8_t cc; + cc = ConvNibble (hh >> 4); Car(cc); + cc = ConvNibble (hh & 0x0F) ; Car(cc); + Car(' '); // space +} +void Hex16 (uint16_t hh) { + uint8_t cc; + cc = ConvNibble (hh >> 12) ; Car(cc); + cc = ConvNibble ((hh >> 8)&0x0F) ; Car(cc); + cc=hh&0xFF; Hex8 (cc); + Car(' '); +} +void Hex32 (uint32_t hh) { + uint8_t cc; + cc = ConvNibble (hh >> 28) ; Car(cc); + cc = ConvNibble ((hh >> 24)&0x0F) ; Car(cc); + cc = ConvNibble ((hh >> 20)&0x0F) ; Car(cc); + cc = ConvNibble ((hh >> 16)&0x0F) ; Car(cc); + cc=hh&0xFFFF; Hex16 (cc); + Car(' '); +} + +// -- new Decimal functions with 4 modes (see above) + +uint8_t uni,diz,cen,mil,dim; +uint8_t tyn; // type number +uint8_t sig; + +void BinDec8 (uint8_t bb) { + uni=0;diz=0;cen=0; + tyn=0; if (bb==0) return; + uni=bb%10; bb=bb/10; if (bb==0){tyn=1;return;} + diz=bb%10; bb=bb/10; if (bb==0){tyn=2;return;} + cen=bb; tyn=3; +} + +void Af3Dig() { + switch (moz) { + case 0: // Normal signe devant le nombre + switch (tyn) { + case 0: + Car(' '); Car(' ');Car(' ');Car('0'); Car(' '); break; + case 1: + Car(' ');Car(' '); Car(sig); Car(uni+'0'); Car(' '); break; + case 2: + Car(' '); Car(sig); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // end case moz 0 + case 1: // Spaces + switch (tyn) { + case 0: + Car(' '); Car(' ');Car(' ');Car('0'); Car(' '); break; + case 1: + Car(sig);Car(' '); Car(' '); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car(' '); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // end case moz 1 + case 2: // Zeros + switch (tyn) { + case 0: + Car(' '); Car('0');Car('0');Car('0'); Car(' '); break; + case 1: + Car(sig);Car('0'); Car('0'); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car('0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // end case moz 2 + case 3: // Compact + switch (tyn) { + case 0: + Car('0'); Car(' '); break; + case 1: + Car(sig); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // endcase moz 3 + } // end switch moz +} +// this macro generate a warning depending on sign +#define Dec8(v) \ + do { typeof(v) _v = -1; \ + if (_v < 0) { Dec8s(v); } \ + else { Dec8u(v); } \ + } while(0); + +void Dec8u (uint8_t hh) { + sig=' '; + BinDec8 (hh); Af3Dig(); +} + +void Dec8s (int8_t hh) { + if (hh<0) { // négatif + sig='-'; hh = -hh; + } else { + sig='+'; + } + BinDec8 (hh); Af3Dig(); +} + +//----------------- +void BinDec16 (uint32_t bb) { + uni=0;diz=0;cen=0;mil=0;dim=0; + tyn=0; if (bb==0) return; + uni=bb%10; bb=bb/10; if (bb==0){tyn=1;return;} + diz=bb%10; bb=bb/10; if (bb==0){tyn=2;return;} + cen=bb%10; bb=bb/10; if (bb==0){tyn=3;return;} + mil=bb%10; bb=bb/10; if (bb==0){tyn=4;return;} + dim=bb; tyn=5; +} + +void Af5Dig() { + switch (moz) { + case 0: // Normal mode + switch (tyn) { + case 0: + Car(' '); Car(' '); Car(' ');Car(' ');Car(' ');Car('0'); Car(' '); break; + case 1: + Car(' '); Car(' '); Car(' ');Car(' ');Car(sig);Car(uni+'0'); Car(' '); break; + case 2: + Car(' '); Car(' '); Car(' ');Car(sig);Car(diz+'0');Car(uni+'0'); Car(' '); break; + case 3: + Car(' '); Car(' '); Car(sig);Car(cen+'0');Car(diz+'0');Car(uni+'0'); Car(' '); break; + case 4: + Car(' '); Car(sig); Car(mil+'0');Car(cen+'0');Car(diz+'0');Car(uni+'0'); Car(' '); break; + case 5: + Car(sig); Car(dim+'0'); Car(mil+'0');Car(cen+'0');Car(diz+'0');Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; + case 1: // Spaces + switch (tyn) { + case 0: + Car(' '); Car(' ');Car(' ');Car(' ');Car(' ');Car('0'); Car(' '); break; + case 1: + Car(sig);Car(' '); Car(' ');Car(' ');Car(' '); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car(' '); Car(' ');Car(' ');Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(' '); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 4: + Car(sig); Car(' ');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 5: + Car(sig); Car(dim+'0');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // case 1 + case 2: // Zeros + switch (tyn) { + case 0: + Car(' '); Car('0');Car('0');Car('0');Car('0');Car('0'); Car(' '); break; + case 1: + Car(sig); Car('0');Car('0');Car('0'); Car('0'); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car('0');Car('0');Car('0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car('0');Car('0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 4: + Car(sig); Car('0');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 5: + Car(sig); Car(dim+'0');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; + case 3: // Compact + switch (tyn) { + case 0: + Car('0'); Car(' '); break; + case 1: + Car(sig); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 4: + Car(sig); Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 5: + Car(sig); Car(dim+'0');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; + } // end switch moz +} + +// this macro generate a warning depending on sign +#define Dec16(v) \ + do { typeof(v) _v = -1; \ + if (_v < 0) { Dec16s(v); } \ + else { Dec16u(v); } \ + } while(0); + +void Dec16u (uint16_t hh) { + sig=' '; + BinDec16(hh); Af5Dig(); +} + +void Dec16s (int16_t hh) { + if (hh<0) { // négatif + sig='-'; hh = -hh; + } else { + sig='+'; + } + BinDec16(hh); Af5Dig(); +} +// end code + + diff --git a/examples/TerSerMainTest/TestTerSerMain.ino b/examples/TerSerMainTest/TestTerSerMain.ino new file mode 100644 index 0000000..7a5e6fd --- /dev/null +++ b/examples/TerSerMainTest/TestTerSerMain.ino @@ -0,0 +1,35 @@ +//TestTerSer.ino Terminal série et aff nombres +#include "TerSer.h" + +int16_t v16s; uint16_t v16; uint8_t v8; +int main() { + SetupTerSer(); + while(1) { // empty 174 bytes 0var + Textln("Test TerSer"); + v8= 19; Bin8(v8); CR(); + v16= 1000; Hex16(v16); CR(); + v16s= 0; Dec16(v16s);CR(); + v16s= 5; Dec16(v16s);CR(); + v16s= 23124; Dec16(v16s);CR(); + v16s= -200; Dec16(v16s);CR(); + v16= 200; Dec16(v16);CR(); + +for(;;); + + } // end while(1) +} // end main() + +/* +Size is 960 bites 24 var + +Test TerSer +00010011 +03E8 + 0 + +5 ++23124 + -200 + 200 + + + */ diff --git a/examples/TerSerTest/TerSer.h b/examples/TerSerTest/TerSer.h new file mode 100644 index 0000000..558b76c --- /dev/null +++ b/examples/TerSerTest/TerSer.h @@ -0,0 +1,275 @@ +// TerSer.h 4 modes 190323 +// ~280 lines ~7700 car +//add to main program #include "TerSer.h" SetupTerSer(); +// or from Arduino lib #include SetupTerSer(); +void SetupTerSer() { + UBRR0= 103; // 9600 + UCSR0B=0x18; // -- -- -- rxe txe -- -- -- + UCSR0C=0x06; // set mode: 8 data bits, no parity, 1 stop bit +} + +uint8_t moz=0; // Default value +#define Normal moz=0 +#define Spaces moz=1 +#define Zeros moz=2 +#define Compact moz=3 + +uint8_t Get() { // read blocking + while (!(UCSR0A&0x80)); // wait + return UDR0; +} + +void Car( uint8_t dd) { // write blocking + while(!(UCSR0A&0x20));// wait + UDR0=dd; // OK, send it now! +} + +void CR() { + Car(13);Car(10); // CR LF +} + +void Text(const char str[]) { + for (uint8_t i=0; i< strlen(str); i++) { Car(str[i]); } +} + +void Textln(const char str[]) { + for (uint8_t i=0; i< strlen(str); i++) { Car(str[i]); } + Car(13);Car(10); +} + +void TtBin8 (uint8_t bb) { // auxiliary function + for (uint8_t i=0;i<8;i++) { + if (bb&0x80) Car('1'); + else Car('0'); + bb <<= 1; + } +} +void Bin8 (uint8_t bb) { + TtBin8 (bb); Car(' '); +} +void Bin16 (uint16_t bb) { + TtBin8 (bb>>8); Car('.'); + TtBin8 (bb&0xFF); + Car(' '); +} + +char ConvNibble (uint8_t nn) { // 4 bit binary to Ascii + uint8_t cc; + if (nn<10) {cc = nn + '0';} + else {cc = nn-10 + 'A';} + return cc; +} + +void Hex8 (uint8_t hh) { + uint8_t cc; + cc = ConvNibble (hh >> 4); Car(cc); + cc = ConvNibble (hh & 0x0F) ; Car(cc); + Car(' '); // space +} +void Hex16 (uint16_t hh) { + uint8_t cc; + cc = ConvNibble (hh >> 12) ; Car(cc); + cc = ConvNibble ((hh >> 8)&0x0F) ; Car(cc); + cc=hh&0xFF; Hex8 (cc); + Car(' '); +} +void Hex32 (uint32_t hh) { + uint8_t cc; + cc = ConvNibble (hh >> 28) ; Car(cc); + cc = ConvNibble ((hh >> 24)&0x0F) ; Car(cc); + cc = ConvNibble ((hh >> 20)&0x0F) ; Car(cc); + cc = ConvNibble ((hh >> 16)&0x0F) ; Car(cc); + cc=hh&0xFFFF; Hex16 (cc); + Car(' '); +} + +// -- new Decimal functions with 4 modes (see above) + +uint8_t uni,diz,cen,mil,dim; +uint8_t tyn; // type number +uint8_t sig; + +void BinDec8 (uint8_t bb) { + uni=0;diz=0;cen=0; + tyn=0; if (bb==0) return; + uni=bb%10; bb=bb/10; if (bb==0){tyn=1;return;} + diz=bb%10; bb=bb/10; if (bb==0){tyn=2;return;} + cen=bb; tyn=3; +} + +void Af3Dig() { + switch (moz) { + case 0: // Normal signe devant le nombre + switch (tyn) { + case 0: + Car(' '); Car(' ');Car(' ');Car('0'); Car(' '); break; + case 1: + Car(' ');Car(' '); Car(sig); Car(uni+'0'); Car(' '); break; + case 2: + Car(' '); Car(sig); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // end case moz 0 + case 1: // Spaces + switch (tyn) { + case 0: + Car(' '); Car(' ');Car(' ');Car('0'); Car(' '); break; + case 1: + Car(sig);Car(' '); Car(' '); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car(' '); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // end case moz 1 + case 2: // Zeros + switch (tyn) { + case 0: + Car(' '); Car('0');Car('0');Car('0'); Car(' '); break; + case 1: + Car(sig);Car('0'); Car('0'); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car('0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // end case moz 2 + case 3: // Compact + switch (tyn) { + case 0: + Car('0'); Car(' '); break; + case 1: + Car(sig); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // endcase moz 3 + } // end switch moz +} +// this macro generate a warning depending on sign +#define Dec8(v) \ + do { typeof(v) _v = -1; \ + if (_v < 0) { Dec8s(v); } \ + else { Dec8u(v); } \ + } while(0); + +void Dec8u (uint8_t hh) { + sig=' '; + BinDec8 (hh); Af3Dig(); +} + +void Dec8s (int8_t hh) { + if (hh<0) { // négatif + sig='-'; hh = -hh; + } else { + sig='+'; + } + BinDec8 (hh); Af3Dig(); +} + +//----------------- +void BinDec16 (uint32_t bb) { + uni=0;diz=0;cen=0;mil=0;dim=0; + tyn=0; if (bb==0) return; + uni=bb%10; bb=bb/10; if (bb==0){tyn=1;return;} + diz=bb%10; bb=bb/10; if (bb==0){tyn=2;return;} + cen=bb%10; bb=bb/10; if (bb==0){tyn=3;return;} + mil=bb%10; bb=bb/10; if (bb==0){tyn=4;return;} + dim=bb; tyn=5; +} + +void Af5Dig() { + switch (moz) { + case 0: // Normal mode + switch (tyn) { + case 0: + Car(' '); Car(' '); Car(' ');Car(' ');Car(' ');Car('0'); Car(' '); break; + case 1: + Car(' '); Car(' '); Car(' ');Car(' ');Car(sig);Car(uni+'0'); Car(' '); break; + case 2: + Car(' '); Car(' '); Car(' ');Car(sig);Car(diz+'0');Car(uni+'0'); Car(' '); break; + case 3: + Car(' '); Car(' '); Car(sig);Car(cen+'0');Car(diz+'0');Car(uni+'0'); Car(' '); break; + case 4: + Car(' '); Car(sig); Car(mil+'0');Car(cen+'0');Car(diz+'0');Car(uni+'0'); Car(' '); break; + case 5: + Car(sig); Car(dim+'0'); Car(mil+'0');Car(cen+'0');Car(diz+'0');Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; + case 1: // Spaces + switch (tyn) { + case 0: + Car(' '); Car(' ');Car(' ');Car(' ');Car(' ');Car('0'); Car(' '); break; + case 1: + Car(sig);Car(' '); Car(' ');Car(' ');Car(' '); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car(' '); Car(' ');Car(' ');Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(' '); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 4: + Car(sig); Car(' ');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 5: + Car(sig); Car(dim+'0');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; // case 1 + case 2: // Zeros + switch (tyn) { + case 0: + Car(' '); Car('0');Car('0');Car('0');Car('0');Car('0'); Car(' '); break; + case 1: + Car(sig); Car('0');Car('0');Car('0'); Car('0'); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car('0');Car('0');Car('0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car('0');Car('0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 4: + Car(sig); Car('0');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 5: + Car(sig); Car(dim+'0');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; + case 3: // Compact + switch (tyn) { + case 0: + Car('0'); Car(' '); break; + case 1: + Car(sig); Car(uni+'0'); Car(' '); break; + case 2: + Car(sig); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 3: + Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 4: + Car(sig); Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + case 5: + Car(sig); Car(dim+'0');Car(mil+'0');Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; + } // end switch tyn + break; + } // end switch moz +} + +// this macro generate a warning depending on sign +#define Dec16(v) \ + do { typeof(v) _v = -1; \ + if (_v < 0) { Dec16s(v); } \ + else { Dec16u(v); } \ + } while(0); + +void Dec16u (uint16_t hh) { + sig=' '; + BinDec16(hh); Af5Dig(); +} + +void Dec16s (int16_t hh) { + if (hh<0) { // négatif + sig='-'; hh = -hh; + } else { + sig='+'; + } + BinDec16(hh); Af5Dig(); +} +// end code + + diff --git a/examples/TerSerTest/TerSerTest.ino b/examples/TerSerTest/TestTerSer.ino similarity index 82% rename from examples/TerSerTest/TerSerTest.ino rename to examples/TerSerTest/TestTerSer.ino index 3dd8fab..5fe3026 100644 --- a/examples/TerSerTest/TerSerTest.ino +++ b/examples/TerSerTest/TestTerSer.ino @@ -18,8 +18,7 @@ void loop(){ // empty 456 bytes 16 var for(;;); } /* -Size is 1014 bytes on my PC -0s Compare witz TestSerial -What you should see, size is 1032 bites on my PC -0s +Size is 1242 bytes on my PC -0s Test TerSer 00010011 03E8 diff --git a/src/TerSer.h b/src/TerSer.h index f33ea4a..558b76c 100644 --- a/src/TerSer.h +++ b/src/TerSer.h @@ -1,50 +1,50 @@ -// TerSer.h 4 modes 190318 -// 280 lines 7775 car -//add in main program #include "TerSer.h" SetupTerSer(); - +// TerSer.h 4 modes 190323 +// ~280 lines ~7700 car +//add to main program #include "TerSer.h" SetupTerSer(); +// or from Arduino lib #include SetupTerSer(); void SetupTerSer() { UBRR0= 103; // 9600 UCSR0B=0x18; // -- -- -- rxe txe -- -- -- UCSR0C=0x06; // set mode: 8 data bits, no parity, 1 stop bit } -byte moz=0; // Default value +uint8_t moz=0; // Default value #define Normal moz=0 #define Spaces moz=1 #define Zeros moz=2 #define Compact moz=3 -byte Get() { // read bloquant +uint8_t Get() { // read blocking while (!(UCSR0A&0x80)); // wait return UDR0; } -void Car( byte dd) { // write bloquant +void Car( uint8_t dd) { // write blocking while(!(UCSR0A&0x20));// wait UDR0=dd; // OK, send it now! } void CR() { - Car(13);Car(10); + Car(13);Car(10); // CR LF } void Text(const char str[]) { - for (byte i=0; i< strlen(str); i++) { Car(str[i]); } + for (uint8_t i=0; i< strlen(str); i++) { Car(str[i]); } } void Textln(const char str[]) { - for (byte i=0; i< strlen(str); i++) { Car(str[i]); } + for (uint8_t i=0; i< strlen(str); i++) { Car(str[i]); } Car(13);Car(10); } -void TtBin8 (byte bb) { // auxiliary function - for (byte i=0;i<8;i++) { +void TtBin8 (uint8_t bb) { // auxiliary function + for (uint8_t i=0;i<8;i++) { if (bb&0x80) Car('1'); else Car('0'); bb <<= 1; } } -void Bin8 (byte bb) { +void Bin8 (uint8_t bb) { TtBin8 (bb); Car(' '); } void Bin16 (uint16_t bb) { @@ -52,28 +52,29 @@ void Bin16 (uint16_t bb) { TtBin8 (bb&0xFF); Car(' '); } -char ConvNibble (byte nn) { // converti 4 bit hexa en Ascii - byte cc; + +char ConvNibble (uint8_t nn) { // 4 bit binary to Ascii + uint8_t cc; if (nn<10) {cc = nn + '0';} else {cc = nn-10 + 'A';} return cc; } -void Hex8 (byte hh) { - byte cc; +void Hex8 (uint8_t hh) { + uint8_t cc; cc = ConvNibble (hh >> 4); Car(cc); cc = ConvNibble (hh & 0x0F) ; Car(cc); Car(' '); // space } void Hex16 (uint16_t hh) { - volatile uint8_t cc; + uint8_t cc; cc = ConvNibble (hh >> 12) ; Car(cc); cc = ConvNibble ((hh >> 8)&0x0F) ; Car(cc); cc=hh&0xFF; Hex8 (cc); Car(' '); } void Hex32 (uint32_t hh) { - volatile uint8_t cc; + uint8_t cc; cc = ConvNibble (hh >> 28) ; Car(cc); cc = ConvNibble ((hh >> 24)&0x0F) ; Car(cc); cc = ConvNibble ((hh >> 20)&0x0F) ; Car(cc); @@ -81,14 +82,13 @@ void Hex32 (uint32_t hh) { cc=hh&0xFFFF; Hex16 (cc); Car(' '); } -// -- new functions with 4 modes - -volatile uint8_t uni,diz,cen,mil,dim; -volatile uint8_t tyn; // type number -volatile uint8_t sig; - - void Af5() {Car(dim+'0'); Car(mil+'0'); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' ');} +// -- new Decimal functions with 4 modes (see above) + +uint8_t uni,diz,cen,mil,dim; +uint8_t tyn; // type number +uint8_t sig; + void BinDec8 (uint8_t bb) { uni=0;diz=0;cen=0; tyn=0; if (bb==0) return; @@ -110,7 +110,7 @@ void Af3Dig() { case 3: Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; } // end switch tyn - break; // case moz 0 + break; // end case moz 0 case 1: // Spaces switch (tyn) { case 0: @@ -122,7 +122,7 @@ void Af3Dig() { case 3: Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; } // end switch tyn - break; // case moz 1 + break; // end case moz 1 case 2: // Zeros switch (tyn) { case 0: @@ -134,7 +134,7 @@ void Af3Dig() { case 3: Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; } // end switch tyn - break; // case moz 2 + break; // end case moz 2 case 3: // Compact switch (tyn) { case 0: @@ -146,10 +146,10 @@ void Af3Dig() { case 3: Car(sig); Car(cen+'0'); Car(diz+'0'); Car(uni+'0'); Car(' '); break; } // end switch tyn - break; // case moz 3 + break; // endcase moz 3 } // end switch moz } - +// this macro generate a warning depending on sign #define Dec8(v) \ do { typeof(v) _v = -1; \ if (_v < 0) { Dec8s(v); } \ @@ -183,7 +183,7 @@ void BinDec16 (uint32_t bb) { void Af5Dig() { switch (moz) { - case 0: // Normal signe devant le nombre + case 0: // Normal mode switch (tyn) { case 0: Car(' '); Car(' '); Car(' ');Car(' ');Car(' ');Car('0'); Car(' '); break; @@ -250,7 +250,7 @@ void Af5Dig() { } // end switch moz } - +// this macro generate a warning depending on sign #define Dec16(v) \ do { typeof(v) _v = -1; \ if (_v < 0) { Dec16s(v); } \