Projekte
BirgerT
nibo2_Birger_01
blib_utils.c
Projekte
Forum
Doku
Öffentliche Projekte
Startseite
Beispielprogramme
Projekte von anderen
Welcome
Username
Passwort
Eingeloggt bleiben
Zugangsdaten vergessen?
Registrieren
Projektverwaltung
⇨ Please choose! ⇦
——————————————————
✎ Create new project...
★ Browse existing projects...
——————————————————
⚬ MotorTest#1
⚬ C Tutorial 8#1
⚬ NIBO2 C Project#1
⚙ C Tutorial 15#1
⚬ 2010_11_18_el_test001#1
nibo2_Birger_01
blib_utils.c
blib_utils.h
BSD_license.h
nibo2_global.h
nibo2_main.c
nibo2_main_01.h
nibo2_pwm_leds.c
nibo2_pwm_leds.h
nibo2_sensors.c
nibo2_sensors.h
Project details
Compiler settings
Nachrichten
Sie sind nicht eingeloggt.
Neuigkeiten
★
NiboRoboLib 3.6
2017-01-17: Neue Version 3.6
★
NiboRoboLib 3.4.1
2016-04-16: Neue Version 3.4.1
★
Coding Tutorial
2015-11-22: Jetzt auch für den NIBO burger!
Site-Statistic
7426 private projects
385 public projects
16180353 lines compiled
58212 builds
NIBO
@
nibo2_birger_1/blib_utils.c [read only]
////////////////////////////////////////////////////////////////////////// // // BT LIB UTILS == AVR MEGA Makros, Typdefs und allgem. Funktionen // // (c) Birger Töpelmann toepelmann(A)web.de Version 141101a // // // // Dokumentation in bt_lib_utils.h // // // TODO // // ////////////////////////////////////////////////////////////////////////// // // BSD License see "license.h" // #include "BSD_license.h" // #include "nibo2_global.h" //#include "bt_lib_utils.h" // Sammlung von Makros und Typedefs //#include "bt_lib_uart.h" // UART Kommunikation mit FIFOs //#include "bt_lib_terminal.h" // Mensch Mikrocontroller Kommunikation #ifdef __cplusplus extern "C" { #endif // ////////////////////////////////////////////////////////////////////////// // // Variablen/Zahlen konvertieren und ausgeben // ////////////////////////////////////////////////////////////////////////// // char itoa_buffer[10]; static char* itoa_outptr = 0; static char itoa_vorz, itoa_fill; static char itoa_digit = ' '; static void itoa_putch(char ch){ if (ch == 0) { *itoa_outptr = ch; // Stringende Zeichen ablegen itoa_outptr = 0; // Buffer Zeiger Reset itoa_vorz = 0; // Vorzeichen vergessen itoa_fill = itoa_digit; // Führende Zeichen } else { if ((ch == '+') || (ch == '-')) { if (itoa_fill == '0') { *itoa_outptr++ = ch; } else { itoa_vorz = ch; // Vorzeichen merken } } else if (ch > '0') { itoa_fill = '0'; if (itoa_vorz == '-') { *itoa_outptr++ = itoa_vorz; itoa_vorz = 0; // Vorzeichen vergessen } *itoa_outptr++ = ch; } else { *itoa_outptr++ = itoa_fill; } } } // ////////////////////////////////////////////////////////////////////////// // void itoa_i16d(char* str, int16_t val){ itoa_outptr = str; if (val < 0) { itoa_putch('-'); if (val == 0x8000) { // Sonderfall -32768 itoa_putch('3'); itoa_putch('2'); itoa_putch('7'); itoa_putch('6'); itoa_putch('8'); itoa_putch(0); // Stringende und putch Reset return; } else { // Absolutwert 2*(-1) = +1 val = 0-val; } } else { itoa_putch('+'); } itoa_u16d(str, (uint16_t)val); } // ////////////////////////////////////////////////////////////////////////// // void itoa_u16d(char* str, uint16_t val){ if (itoa_outptr == 0) { itoa_outptr = str; } char digit = '0'; if (val >= 256) { // Zehntausender Stelle if (val >= 40000) { val -= 40000; digit += 4; } if (val >= 20000) { val -= 20000; digit += 2; } if (val >= 10000) { val -= 10000; ++digit; } itoa_putch(digit); // Tausender Stelle digit = '0'; if (val >= 8000) { val -= 8000; digit += 8; } else if (val >= 4000) { val -= 4000; digit += 4; } if (val >= 2000) { val -= 2000; digit += 2; } if (val >= 1000) { val -= 1000; ++digit; } itoa_putch(digit); // Hunderter Stelle digit = '0'; if (val >= 800) { val -= 800; digit += 8; } else if (val >= 400) { val -= 400; digit += 4; } if (val >= 200) { val -= 200; digit += 2; } if (val >= 100) { val -= 100; ++digit; } itoa_putch(digit); // Zehner und Einer = die letzten beiden Stellen 0..99 itoa_99d(str, (uint8_t)val); } // Zahlen kleiner 256 else { itoa_putch(digit); // digit == '0' itoa_putch(digit); itoa_u8d(str, (uint8_t)val); } } // ////////////////////////////////////////////////////////////////////////// // void itoa_i8d(char* str, int8_t val){ itoa_outptr = str; if (val < 0) { itoa_putch('-'); if (val == 0x80) { // Sonderfall -128 itoa_putch('1'); itoa_putch('2'); itoa_putch('8'); itoa_putch(0); // Stringende und putch Reset } else { // Absolutwert 2*(-1) = +1 itoa_u8d(str, (uint8_t)(0-val)); } } else { itoa_putch('+'); itoa_u8d(str, (uint8_t)val); } } // ////////////////////////////////////////////////////////////////////////// // void itoa_u8d(char* str, uint8_t val){ if (itoa_outptr == 0) { itoa_outptr = str; } char digit = '0'; // Hunderter Stelle if (val >= 200) { val -= 200; digit += 2; } else if (val >= 100) { val -= 100; ++digit; } itoa_putch(digit); // Zehner und Einer = die letzten beiden Stellen 0..99 itoa_99d(str, (uint8_t)val); } // ////////////////////////////////////////////////////////////////////////// // void itoa_99d(char* str, uint8_t val){ if (itoa_outptr == 0) { itoa_outptr = str; } // >100 dann Text "ON" if (val >= 100) { itoa_putch('O'); itoa_putch('N'); itoa_putch(0); // Stringende und putch Reset } else { char digit = '0'; // Zehner Stelle if (val >= 80) { val -= 80; digit += 8; } else if (val >= 40) { val -= 40; digit += 4; } if (val >= 20) { val -= 20; digit += 2; } if (val >= 10) { val -= 10; ++digit; } itoa_putch(digit); // Einer Stelle = Rest von val itoa_putch('0' + val); itoa_putch(0); // Stringende und putch Reset } } // ////////////////////////////////////////////////////////////////////////// // char bin2asc(uint8_t bin){ bin &= 0x0f; if(bin <= 9) return bin + '0'; else return bin + 'A' -10; } // ////////////////////////////////////////////////////////////////////////// // void itoa_u16h(char* str, uint16_t val){ itoa_outptr = str; uint8_t byte = HIBYTE(val); itoa_putch(bin2asc(byte/16)); itoa_putch( bin2asc(byte)); itoa_u8h(str, LOBYTE(val)); } // ////////////////////////////////////////////////////////////////////////// // void itoa_u8h(char* str, uint8_t val){ if (itoa_outptr == 0) { itoa_outptr = str; } itoa_putch(bin2asc(val/16)); itoa_putch(bin2asc(val)); itoa_putch(0); // Stringende und putch Reset } // ////////////////////////////////////////////////////////////////////////// // void print_b8(char* str, uint8_t val){ itoa_outptr = str; uint8_t mask = 0x80; do { if ((val & mask)==0) { itoa_putch('0'); } else { itoa_putch('1'); } } while ((mask >>= 1) != 0); itoa_putch(0); // Stringende und putch Reset } // //////////////////////////////////////////////////////////////////////// // #ifdef __cplusplus } // extern "C" #endif // EOF
Compiler results:
Werbung
Online
melinda99616083108
raymundo21y8345223044
warrenhinder6456