/** * Ansteuerung eines HD44780 kompatiblen LCD im 4-Bit-Interfacemodus * * Die Pinbelegung ist über defines in lcd.h einstellbar * * @copyright 2012 Institute Automation of Complex Power Systems (ACS), RWTH Aachen University * @license http://www.gnu.org/licenses/gpl.txt GNU Public License * @link http://www.mikrocontroller.net/articles/HD44780 * @link http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/LCD-Ansteuerung */ #include #include #include #include "lcd.h" /** * Erzeugt einen Enable-Puls */ static void lcd_enable() { LCD_PORT |= (1<>(4-LCD_DB)); // Maske löschen LCD_PORT |= (data>>(4-LCD_DB)); // Bits setzen lcd_enable(); } /** * Initialisierung: muss ganz am Anfang des Programms aufgerufen werden */ void lcd_init() { // verwendete Pins auf Ausgang schalten uint8_t pins = (0x0F << LCD_DB) | // 4 Datenleitungen (1< 100) return; lcd_setcursor(startx, starty); lcd_data(0b00111100); // < for (i=0; i < length-2; i++) { lcd_setcursor( startx+1+i , starty ); if (percent*(length-2)/100 <= i ) { lcd_data('-'); } else { lcd_data(0b11111111); } } lcd_setcursor(startx+length-1, starty ); lcd_data(0b00111110); // > } /** * Ausgabe einer Ganzzahl mit führenden Leerzeichen */ void lcd_int(int16_t number, uint8_t length) { char buffer[length+1]; bool vz = true; bool zf = true; bool neg = (number < 0); buffer[length] = '\0'; for (int8_t counter = length-1; counter >= 0; counter--) { if (zf) { buffer[counter] = '0' + (abs(number) % 10); number /= 10; zf = (bool) number; } else if (vz && neg) { buffer[counter] = '-'; vz = false; } else { buffer[counter] = ' '; } } lcd_string(buffer); }