diff --git a/lambda/Makefile b/lambda/Makefile index 5eee898..d3350b2 100644 --- a/lambda/Makefile +++ b/lambda/Makefile @@ -14,7 +14,7 @@ ## If you've split your program into multiple .c / .h files, ## include the additional source (in same directory) here -LOCAL_SOURCE = USART.c adc.c sensors.c integers.c +LOCAL_SOURCE = USART.c adc.c sensors.c integers.c lcdroutines.c ## Here you can link to one more directory (and multiple .c files) EXTRA_SOURCE_DIR = diff --git a/lambda/lambda.c b/lambda/lambda.c index 6db5350..f9632f4 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -35,6 +35,7 @@ #include "adc.h" #include "sensors.h" #include "integers.h" +#include "lcdroutines.h" /** * Initializes the USART transmitter and receiver, sets up the ADC @@ -45,6 +46,7 @@ */ int main(void) { initUSART(); + lcd_init(); setupADC(); setupSleepMode(); diff --git a/lambda/lcdroutines.c b/lambda/lcdroutines.c new file mode 100644 index 0000000..ea6942e --- /dev/null +++ b/lambda/lcdroutines.c @@ -0,0 +1,179 @@ +// Ansteuerung eines HD44780 kompatiblen LCD im 4-Bit-Interfacemodus +// http://www.mikrocontroller.net/articles/HD44780 +// http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/LCD-Ansteuerung +// +// Die Pinbelegung ist über defines in lcd-routines.h einstellbar + +#include +#include "lcdroutines.h" +#include + + +//////////////////////////////////////////////////////////////////////////////// +// Erzeugt einen Enable-Puls +static void lcd_enable( void ) +{ + LCD_PORT |= (1 << LCD_EN); + _delay_us( LCD_ENABLE_US ); // kurze Pause + LCD_PORT &= ~(1 << LCD_EN); // Enable auf 0 setzen +} + +//////////////////////////////////////////////////////////////////////////////// +// Sendet eine 4-bit Ausgabeoperation an das LCD +static void lcd_out( uint8_t data ) +{ + if (data & 1<<4) LCD_PORT |= (1 << LCD_DB4); else LCD_PORT &= ~(1 << LCD_DB4); + if (data & 1<<5) LCD_PORT |= (1 << LCD_DB5); else LCD_PORT &= ~(1 << LCD_DB5); + if (data & 1<<6) LCD_PORT |= (1 << LCD_DB6); else LCD_PORT &= ~(1 << LCD_DB6); + if (data & 1<<7) LCD_PORT |= (1 << LCD_DB7); else LCD_PORT &= ~(1 << LCD_DB7); + lcd_enable(); +} + +//////////////////////////////////////////////////////////////////////////////// +// Initialisierung: muss ganz am Anfang des Programms aufgerufen werden. +void lcd_init( void ) +{ + // verwendete Pins auf Ausgang schalten + LCD_DDR |= (1 << LCD_EN); + LCD_DDR |= (1 << LCD_RS); + LCD_DDR |= (1 << LCD_DB4); + LCD_DDR |= (1 << LCD_DB5); + LCD_DDR |= (1 << LCD_DB6); + LCD_DDR |= (1 << LCD_DB7); + + // initial alle Ausgänge auf Null + // ist default + + // warten auf die Bereitschaft des LCD + _delay_ms( LCD_BOOTUP_MS ); + + // Soft-Reset muss 3mal hintereinander gesendet werden zur Initialisierung + lcd_out( LCD_SOFT_RESET ); + _delay_ms( LCD_SOFT_RESET_MS1 ); + + lcd_enable(); + _delay_ms( LCD_SOFT_RESET_MS2 ); + + lcd_enable(); + _delay_ms( LCD_SOFT_RESET_MS3 ); + + // 4-bit Modus aktivieren + lcd_out( LCD_SET_FUNCTION | LCD_FUNCTION_4BIT ); + _delay_ms( LCD_SET_4BITMODE_MS ); + + // 4-bit Modus / 2 Zeilen / 5x7 + lcd_command( LCD_SET_FUNCTION | + LCD_FUNCTION_4BIT | + LCD_FUNCTION_2LINE | + LCD_FUNCTION_5X7 ); + + // Display ein / Cursor aus / Blinken aus + lcd_command( LCD_SET_DISPLAY | + LCD_DISPLAY_ON | + LCD_CURSOR_OFF | + LCD_BLINKING_OFF); + + // Cursor inkrement / kein Scrollen + lcd_command( LCD_SET_ENTRY | + LCD_ENTRY_INCREASE | + LCD_ENTRY_NOSHIFT ); + + lcd_clear(); +} + +//////////////////////////////////////////////////////////////////////////////// +// Sendet ein Datenbyte an das LCD +void lcd_data( uint8_t data ) +{ + LCD_PORT |= (1<