#ifndef __LCD_H
#define __LCD_H
/*
**
** 05.02.2009 li Anpassung an ATMEGA8
** 06.02.2009 li Control Ports reihenfolge korr.
** 11.03.2009 li Anpassung an neue 10 Bit Schift Ausgabe
** 22.04.2009 li Frequenz Counter Belegung
**               nur 4 Port Bits sind notwendig ( PORT C )
**
**               1  2   3   4   5   6   7   8   9   10  
**               RS DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 frei
**
**               LCD_CP    = Clock Puls Shift Register, von 1 nach 0 200nsec 0 nach 1                 
**               LCD_EN    = Enable Puls
**               LCD_DA    = DATA Serial In Shift Register
**               LCD_LED   = eigener Port fuer Backlight ein/aus  
**
** 22.04.2009 li Anpassung an verschiedene Displays 
** 22.04.2009 li Licht des Panel eigener Port da Flackern beim cmd
** 28.05.2009 li Uebernahme von dcf77/frequenzcounter
** 14.09.2009 li A_TEST4LINE = testboard mit 4*20 display   
** 01.01.2010 li A_GASMESS und LCD_SHIFT=8 dazu
** 14.01.2010 li EA_DIP204_4 Display Anpassungen        A_GMESS
** 20.02.2010 li EA_DIP204_4 Display fuer Testboard     A_TESTNEU 
** 02.05.2011 li A_LCD204B = DisplayTech 4*20 mit 8 Bit Schift       
**/

                            // HD44780 LCD port connections 
#undef EA_DIP204_4
#undef LCD_SHIFT
#undef LCD_PWM_OC1B
#undef LCD_PWM_TIM0
#undef LCD_LED_PWM  

// ---------------------------------------------------------------  
#ifdef A_ANZEIGE                            // Control Bits
#define LCD_SHIFT     10  
#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT0    // shift clock 
#define LCD_EN        BIT1    // enable (strobe)
#define LCD_DA        BIT2    // shift input
#define LCD_LED       BIT3    // backlight LED   

#define LCD_CHARS      16     // chars per line
#define LCD_LINES       2     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_KAFFEE                 // 14.04.2012 2 zeilig grosse Anzeige 

#define LCD_PWM_OC1B
#define LCD_LED_PWM
//#define EA_DIP204_4           // Diverse Aenderungen erforderlich
//#define LCD_SHIFT     8
#define LCD_SHIFT     10

#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC
#define LCD_PWM_DDR   DDRB     
#define LCD_PWM_PORT  PORTB

//#define LCD_CP        BIT0    // shift clock 
//#define LCD_DA        BIT1    // DATA input / RS
//#define LCD_EN        BIT2    // enable (strobe)

#define LCD_CP        BIT0    // shift clock 
#define LCD_EN        BIT1    // enable 
#define LCD_DA        BIT2    // shift data input

#define LCD_LED       BIT2    // backlight LED   
                             
//#define LCD_CHARS      20     // chars per line
//#define LCD_LINES       4     // Zeilen
#define LCD_CHARS      16     // chars per line
#define LCD_LINES       2     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_KAFFEE_P               // 30.05.2012 Kaffee praxis 

#define LCD_PWM_OC1B
#define LCD_LED_PWM
//#define EA_DIP204_4           // Diverse Aenderungen erforderlich
#define LCD_SHIFT     8
// #define LCD_SHIFT     10

#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC
#define LCD_PWM_DDR   DDRB     
#define LCD_PWM_PORT  PORTB

#define LCD_DA        BIT0    // shift data input
#define LCD_CP        BIT1    // shift clock 
#define LCD_EN        BIT2    // enable 

#define LCD_LED       BIT2    // backlight LED
  
#define LCD_CHARS      16     // chars per line
#define LCD_LINES       2     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_DCF77
#define LCD_PWM_TIM0          // Timer 0 simuliert PWM
#define LCD_LED_PWM

#define LCD_SHIFT     10  
#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT2    // shift clock 
#define LCD_EN        BIT1    // enable (strobe)
#define LCD_DA        BIT0    // shift input
#define LCD_LED       BIT3    // backlight LED   

#define LCD_CHARS      16     // chars per line
#define LCD_LINES       2     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_MASTER

#define LCD_PWM_TIM0          // Timer 0 simuliert PWM
#define LCD_LED_PWM

#define LCD_SHIFT     10
#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT2    // shift clock 
#define LCD_EN        BIT3    // enable (strobe)
#define LCD_DA        BIT4    // shift input
#define LCD_LED       BIT5    // backlight LED   

#define LCD_CHARS      16     // chars per line
#define LCD_LINES       2     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_MASTER_TEST

#define LCD_PWM_TIM0          // Timer 0 simuliert PWM
#define LCD_LED_PWM

#define LCD_SHIFT     8
#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT0    // shift clock 
#define LCD_EN        BIT1    // enable 
#define LCD_DA        BIT2    // shift data input
#define LCD_LED       BIT3    // backlight LED   

#define LCD_CHARS      16     // chars per line
#define LCD_LINES       2     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_TEST4LINE
#define LCD_SHIFT     10
#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT0    // shift clock 
#define LCD_EN        BIT1    // enable (strobe)
#define LCD_DA        BIT2    // shift input
#define LCD_LED       BIT3    // Beleuchtungs LED   

                              // Testboard LCD  
#define LCD_CHARS      20     // chars per line
#define LCD_LINES       4     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_GMESS
#define EA_DIP204_4           // Diverse Aenderungen erforderlich
#define LCD_SHIFT     8
#define LCD_CNTL_DDR  DDRA     
#define LCD_CNTL_PORT PORTA

#define LCD_CP        BIT7    // shift clock 
#define LCD_DA        BIT6    // DATA input / RS
#define LCD_EN        BIT5    // enable (strobe)
#define LCD_LED       BIT4    // Beleuchtungs LED   
                              
#define LCD_CHARS      20     // chars per line
#define LCD_LINES       4     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_GMESS_TEST           // gmess Testboard
#define EA_DIP204_4           // Diverse Aenderungen erforderlich
#define LCD_SHIFT     8
#define LCD_CNTL_DDR  DDRC    // PORT C  
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT0    // shift clock 
#define LCD_DA        BIT1    // DATA input / RS
#define LCD_EN        BIT2    // enable (strobe)
#define LCD_LED       BIT3    // Beleuchtungs LED   
                              
#define LCD_CHARS      20     // chars per line
#define LCD_LINES       4     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_TINY44               // Tiny44 Testboard
#define EA_DIP204_4           // Diverse Aenderungen erforderlich
#define LCD_SHIFT     8
#define LCD_CNTL_DDR  DDRA    // PORT A  
#define LCD_CNTL_PORT PORTA

#define LCD_LED       BIT0    // Beleuchtungs LED   
#define LCD_EN        BIT1    // enable (strobe)
#define LCD_DA        BIT2    // DATA input / RS
#define LCD_CP        BIT3    // shift clock 
                              
#define LCD_CHARS      20     // chars per line
#define LCD_LINES       4     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_TEST168              // Testboard atmega168  3.2.2011 ok
#define EA_DIP204_4           // Diverse Aenderungen erforderlich
#define LCD_SHIFT     8
#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT0    // shift clock 
#define LCD_DA        BIT1    // DATA input / RS
#define LCD_EN        BIT2    // enable (strobe)
#define LCD_LED       BIT3    // Beleuchtungs LED   
                              
#define LCD_CHARS      20     // chars per line
#define LCD_LINES       4     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_DCFUHR               // wie DCFUHR wie Testboard jedoch ohne probleme in clock.c
#define EA_DIP204_4           // Diverse Aenderungen erforderlich
#define LCD_SHIFT     8
#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT0    // shift clock 
#define LCD_DA        BIT1    // DATA input / RS
#define LCD_EN        BIT2    // enable (strobe)
#define LCD_LED       BIT3    // Beleuchtungs LED   
                              
#define LCD_CHARS      20     // chars per line
#define LCD_LINES       4     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_LCD204B              // 4*20 Zeichen, 8 Bit Schiftregister
#define LCD_SHIFT     8
#define LCD_CNTL_DDR  DDRC     
#define LCD_CNTL_PORT PORTC

#define LCD_CP        BIT0    // shift clock 
#define LCD_DA        BIT1    // DATA input / RS
#define LCD_EN        BIT2    // enable (strobe)
#define LCD_LED       BIT3    // Beleuchtungs LED   
                              
#define LCD_CHARS      20     // chars per line
#define LCD_LINES       4     // Zeilen
#endif

// ---------------------------------------------------------------
#ifdef A_MINI_WEB             // 4*20 Zeichen, 8 Bit Schiftregister
#define LCD_SHIFT     8
#define LCD_CNTL_DDR  DDRA     
#define LCD_CNTL_PORT PORTA

#define LCD_CP        BIT4    // shift clock 
#define LCD_DA        BIT5    // DATA input / RS
#define LCD_EN        BIT6    // enable (strobe)
#define LCD_LED       BIT7    // Beleuchtungs LED   
                              
#define LCD_CHARS      20     // chars per line
#define LCD_LINES       4     // Zeilen
#endif

// ---------------------------------------------------------------

typedef struct
{
   unsigned char xpos;
   unsigned char zeile;
   unsigned char lcd_backlight;  // rueckmeldung fuer das menu
   unsigned char chars_pl;       // Anzahl der char per line
   unsigned char zeilen;         // Anzahl der Zeilen
} S_LCD_ANZ;

void lcd_init( unsigned char pwm );   // nur wenn TIM0 benutzt
void lcd_home( void );
void lcd_clear( void );
void lcd_string(char *);
void lcd_beleuchtung( unsigned char );
void lcd_data(unsigned char);
void cursor_view( unsigned char on, unsigned char blinken );
void set_cursor(uint8_t x, uint8_t y);

#endif
