============================================ Eingangsnamen.c ================================================================ #include #include "Verteiler.h" #include // wird in aktuellen Versionen der avr-lib mit xx.h eingebunden uint8_t Eingang[8][16] EEMEM = {}; uint8_t Anfangsnamen[1] EEMEM ={}; void input_names (void) { uint8_t myByte; const uint8_t name[5]= {'E','i','n','g','.'}; uint8_t i,j; // i=Eingang j=einzelne Buchstaben uint8_t x; myByte = eeprom_read_byte(&Anfangsnamen[1]); // EEPROM schon beschrieben? // Ja -> nicht nochmal beschreiben if (myByte==0){ for(i=0;i<=7;i++){ for(j=0;j<=4;j++) // "Eing." ins EEPROM eeprom_write_byte(&Eingang[i][j],name[j]); x=49+i; // 49 wegen ASCII Code eeprom_write_byte(&Eingang[i][j],x); // danach 1..8 ins EEPROM x=' '; // restlichen 10 byte mit Leerzeichen füllen for(j=6;j<=15;j++){ eeprom_write_byte(&Eingang[i][j],x); } } } eeprom_write_byte(&Anfangsnamen[1], 1); } ============================================ Entprellung.c ================================================================= /************************************************************************/ /* */ /* Debouncing 8 Keys */ /* Sampling 4 Times */ /* With Repeat Function */ /* */ /* Author: Peter Dannegger */ /* danni@specs.de */ /* */ /************************************************************************/ #include #include #include #include "Verteiler.h" #include "Entprellung.h" //#include #define REPEAT_MASK (1<1: key press detect if( (key_state & REPEAT_MASK) == 0 ) // check repeat function rpt = REPEAT_START; // start delay if( --rpt == 0 ){ rpt = REPEAT_NEXT; // repeat delay key_rpt |= key_state & REPEAT_MASK; } } /////////////////////////////////////////////////////////////////// // // check if a key has been pressed. Each pressed key is reported // only once // uint8_t get_key_press( uint8_t key_mask ) { cli(); // read and clear atomic ! key_mask &= key_press; // read key(s) key_press ^= key_mask; // clear key(s) sei(); return key_mask; } /////////////////////////////////////////////////////////////////// // // check if a key has been pressed long enough such that the // key repeat functionality kicks in. After a small setup delay // the key is reported beeing pressed in subsequent calls // to this function. This simulates the user repeadiately // pressing and releasing the key. // uint8_t get_key_rpt( uint8_t key_mask ) { cli(); // read and clear atomic ! key_mask &= key_rpt; // read key(s) key_rpt ^= key_mask; // clear key(s) sei(); return key_mask; } /////////////////////////////////////////////////////////////////// // uint8_t get_key_short( uint8_t key_mask ) { cli(); // read key state and key press atomic ! return get_key_press( ~key_state & key_mask ); } /////////////////////////////////////////////////////////////////// // uint8_t get_key_long( uint8_t key_mask ) { return get_key_press( get_key_rpt( key_mask )); } ======================================================= lcd.c ============================================================== // Pinbelegung über defines einstellbar #include #include #include "LCD.h" #include #include #include "Verteiler.h" // LCD Befehle #define CLEAR_DISPLAY 0x01 #define CURSOR_HOME 0x02 #define ASCII48 48 // verschieben in ASCII Tabelle um dez 48 #ifndef eeprom #define eeprom 1 #endif #ifndef sram #define sram 2 #endif extern uint8_t Eingang[8][16] EEMEM ; extern uint8_t Anfangsnamen[1] EEMEM; const char Text1[] PROGMEM = {'E','I','N','G','A','N','G'}; const char Text2[] PROGMEM = {'W','Ä','H','L','E','N'}; const char Text3[] PROGMEM = {'E','I','N','S','T','E','L','L','U','N','G','E','N'}; const char Text4[] PROGMEM = {'U','M','B','E','N','E','N'}; const char Text5[] PROGMEM = {'U','H','R',' ','S','T','E','L','L','E','N'}; const char Text6[] PROGMEM = {'B','E','L','E','U','C','H','T','U','N','G'}; const char Text7[] PROGMEM = {'B','E','L','E','U','C','H','T','U','N','G',' ','E','I','N'}; const char Text8[] PROGMEM = {'B','E','L','E','U','C','H','T','U','N','G',' ','A','U','S'}; const char *pgmPointerText[] PROGMEM = { Text1,Text2,Text3,Text4,Text5,Text6,Text7,Text8 }; // sendet ein Datenbyte an das LCD void lcd_data(unsigned char temp1) { unsigned char temp2 = temp1; LCD_PORT |= (1<> 4; temp1 = temp1 & 0x0F; LCD_PORT &= 0xF0; LCD_PORT |= temp1; // setzen lcd_enable(); temp2 = temp2 & 0x0F; LCD_PORT &= 0xF0; LCD_PORT |= temp2; // setzen lcd_enable(); _delay_us(42); } // sendet einen Befehl an das LCD void lcd_command(unsigned char temp1) { unsigned char temp2 = temp1; LCD_PORT &= ~(1<> 4; // oberes Nibble holen temp1 = temp1 & 0x0F; // maskieren LCD_PORT &= 0xF0; LCD_PORT |= temp1; // setzen lcd_enable(); temp2 = temp2 & 0x0F; // unteres Nibble holen und maskieren LCD_PORT &= 0xF0; LCD_PORT |= temp2; // setzen lcd_enable(); _delay_us(42); } // erzeugt den Enable-Puls void lcd_enable(void) { LCD_PORT |= (1<=16) y=16; for(;y!=0;y--){ if (x==1) lcd_data(' '); else lcd_data(126); } } // ================================================================================ // Funktionsname: string_Ausgabe // // Beschreibung: string aus flash oder eeprom lesen und auf LCD ausgeben // // Übergabe: x,y: Position LCD Spalte,Zeile // n: eeprom / sram string aus array-Feld // lenght: Länge des Strings // Speicher: eeprom(1) oder sram(2) // void string_Ausgabe (uint8_t x,uint8_t y,uint8_t n,uint8_t lenght,uint8_t Speicher) { uint8_t j,byte; set_cursor(x,y); for(j=0;!(lenght==0);lenght--,j++) { if (Speicher==eeprom) byte = eeprom_read_byte(&Eingang[n][j]); else byte = pgm_read_byte(&pgmPointerText[n]); lcd_data(byte); } } // gibt zweistellige zahlen dezimal aus void lcd_dezimal(uint8_t Wert) { uint8_t x; if (Wert>=10){ for(x=0;!(Wert<=9);){ Wert=Wert-10; ++x; } lcd_data(x+ASCII48); lcd_data(Wert+ASCII48); } else { lcd_data('0'); lcd_data(Wert+ASCII48); } } ===================================================== Uhr.c =============================================================== /************************************************************************/ /* */ /* Precise 1 Second Timebase */ /* */ /* Author: Peter Dannegger */ /* danni@specs.de */ /* */ /************************************************************************/ // Target: Mega8, 2313 #include #include #include "LCD.h" #include "Verteiler.h" #include "Uhr.h" #ifndef DEBOUNCE #define DEBOUNCE 256L // debounce clock (256Hz = 4msec) #endif uint8_t prescaler; uint8_t volatile second; // count seconds uint8_t volatile minute; // count minutes uint8_t volatile hour; // count hours uint8_t volatile second_change; ISR(TIMER1_COMPA_vect) // SIGNAL (SIG_OUTPUT_COMPARE1A) original { /************************************************************************/ /* Insert Key Debouncing Here */ /************************************************************************/ #if F_CPU % DEBOUNCE // bei rest OCR1A = F_CPU / DEBOUNCE - 1; // compare DEBOUNCE - 1 times #endif if( --prescaler == 0 ){ prescaler = (uint8_t)DEBOUNCE; second++; // exact one second over second_change = 1; // Uhr nur aktualisieren bei veränderung der sekunden if (second==60){ second = 0; minute++;} if (minute==60){ minute = 0; hour++;} if (hour==24) hour = 0; #if F_CPU % DEBOUNCE // handle remainder OCR1A = F_CPU / DEBOUNCE + F_CPU % DEBOUNCE - 1; // compare once per second #endif } else second_change = 0; } // Uhrzeit auf das Display Zeile1 void Anzeige_Uhr (void) { lcd_home(); space_or_arrow(SPACE,4); // 4x Leerzeichen in Zeile1 lcd_dezimal(hour); lcd_data(':'); lcd_dezimal(minute); lcd_data(':'); lcd_dezimal(second); space_or_arrow(SPACE,4); // 4x Leerzeichen in Zeile1 } ========================================================= Verteiler.c ====================================================== #include #include "LCD.h" #include #include "Entprellung.h" #include #include #include #include #include "Eingangsnamen.h" #include "Uhr.h" #include "Verteiler.h" #ifndef OCR1A #define OCR1A OCR1 // 2313 support #endif #ifndef WGM12 #define WGM12 CTC1 // 2313 support #endif uint8_t menu_status; // Veränderung in Menupunkt -> Menupunkt neu laden uint8_t Menupunkt; uint8_t Unterpunkt; uint8_t j,lenght,n,Speicher; uint8_t x,y,z; uint8_t byte_char ; uint8_t byte_int ; extern uint8_t Eingang[8][16] EEMEM ; extern uint8_t Anfangsnamen[1] EEMEM; uint8_t eeFooByte EEMEM; int main(void) { LCD_DDR = 0xFF; // Ausgang ANALOG_DDR = 0xFF; // Ausgang KEY_DDR &= ~ALL_KEYS; // input KEY_PORT |= ALL_KEYS; // pull up PORTB = 1<