00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00027 #include <avr/io.h>
00028 #include <avr/signal.h>
00029 #include <avr/interrupt.h>
00030 #include <avr/pgmspace.h>
00031 #include <inttypes.h>
00032 #include "main/keys.h"
00033 #include "main/lcd.h"
00034 #include "main/rom.h"
00035 #include "net/link.h"
00036 #include "net/transport.h"
00037 #include "net/application.h"
00038 #include "net/presentation.h"
00039 #include "delay.h"
00040 #include "main/menu.h"
00041 #include "main/dcf77.h"
00042
00043 static uint8_t timer_flag, timer;
00044 static uint16_t backlight;
00045
00051 INTERRUPT(SIG_OUTPUT_COMPARE2)
00052 {
00053 timer++;
00054 timer_flag++;
00055 keys_sense_keys();
00056
00057
00058 if (keys_key_pressed()) {
00059 backlight = 10000;
00060 lcd_enable_backlight();
00061 }
00062 if (backlight > 0) {
00063 backlight--;
00064 if (backlight == 0) lcd_disable_backlight();
00065 }
00066 }
00067
00068 void print_hex(uint8_t value, uint8_t x, uint8_t y)
00069 {
00070 uint8_t buf[3];
00071 uint8_t hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
00072
00073 buf[0] = hex[value >> 4];
00074 buf[1] = hex[value & 0x0f];
00075 buf[2] = 0x00;
00076 lcd_print(x, y, 0, buf);
00077 }
00078
00079
00080
00081 void print_time(void)
00082 {
00083 struct snt_time_stamp t;
00084
00085 dcf_get_time(&t);
00086 print_hex(t.hour, 0, 0);
00087 print_hex(t.minute, 10, 0);
00088 print_hex(t.second, 20, 0);
00089 }
00090
00091
00097 int main(void)
00098 {
00099
00100 PORTE = 0x05;
00101 DDRD = 0xff;
00102 DDRE = 0x3e;
00103
00104
00105 sei();
00106 lcd_init();
00107 lnk_init();
00108 app_init();
00109 dcf_init();
00110
00111
00112
00113 OCR2 = 0x5d;
00114 TCCR2 = _BV(CTC2) | _BV(CS21) | _BV(CS20);
00115 sbi(TIMSK, OCIE2);
00116
00117 keys_set_leds(0xff);
00118
00119 lcd_activate();
00120 lcd_disable_backlight();
00121
00122 menu_init();
00123
00124 for (;;) {
00125 while (timer_flag) {
00126 timer_flag--;
00127 tsp_check_timeout();
00128 }
00129 lnk_process();
00130 tsp_process();
00131 app_process();
00132 menu_process();
00133 dcf_process();
00134
00135 if (timer == 0) print_time();
00136 }
00137 return 0;
00138 }