//_____________________________________ // Read user input and act on it bool controlMode( char ch ) { static int arg = -1; int retval = false; if (isdigit( ch )) { if (arg < 0) arg = 0; arg = arg * 10 + (ch - '0'); return false; } switch ( ch ) { // 'N' triggers the NTP protocol manually case 'N': case 'n': triggerNtp() ; retval = true ; break ; // Left-arrow (Less-Than) slows down the clock for simulation runs case '<': case ',': slowDown() ; retval = true ; break ; // Right-arrow (Greater-Than) speeds up the clock for simulation runs case '>': case '.': speedUp() ; retval = true ; break ; // PLUS advances the digital clock minute case '+': case '=': incMinutes() ; retval = true ; break ; // MINUS decrements the digital clock minute case '_': case '-': decMinutes() ; retval = true ; break ; // H, M, S set hours, minutes, seconds case 'H': case 'h': if (arg >= 0) setHours(arg); retval = true ; break ; case 'M': case 'm': if (arg >= 0) setMinutes(arg); retval = true ; break ; case 'S': case 's': if (arg >= 0) setSeconds(arg); syncTime() ; retval = true ; break ; // 'Z' resets the digital clock seconds case 'z': case 'Z': setSeconds(0) ; syncTime() ; return true ; // A, B and C manually force the A/B output pulses but do not affect the internal clock // A and B add to the force count for the A and B signals. C adds to both signals. case 'A': case 'a': if (arg < 0) arg = 1 ; sendPulsesA(arg) ; break ; case 'B': case 'b': if (arg < 0) arg = 1 ; sendPulsesB(arg) ; break ; case 'C': case 'c': if (arg < 0) arg = 1 ; sendPulsesA(arg) ; sendPulsesB(arg) ; break ; case 'D': case 'd': if (arg < 0) arg = 1 ; sendPulsesD(arg) ; break ; case 'E': case 'e': sendPulsesE(1) ; break ; case 'f': setState(LOW); break ; case 'F': setState(HIGH); break ; case 'I': case 'i': if (arg < 0) arg = 60*60; clockHold(arg, arg) ; break ; case 'U': case 'u': if (arg < 0) arg = 60*60; clockHold(arg, 0) ; break ; case 'V': case 'v': if (arg < 0) arg = 60*60; clockHold(0, arg) ; break ; default: break; } arg = -1; return retval ; }
int main(void) { init_IO(); init_RTC(); while(1) { if (~PIND & BUTSHOW) { showTime(); } if (showTimeFlag) { showTimeFlag = 0; showTime(); } if (~PIND & BUTHOUR) { incHours(); showHours(); } if (~PIND & BUTMIN) { incMinutes(); showMinutes(); } } while(1) { // twiddle(); //readInput(); findZero(); findZero(); findZero(); _delay_ms(1000); showTime(); /* PORTC |= 1<<PC4; _delay_ms(200); PORTC &= ~(1<<PC4); _delay_ms(200); */ } }