From 992af39d0775345631bea73bfc60156345a707fb Mon Sep 17 00:00:00 2001 From: Stefanie Eckner Date: Fri, 30 Oct 2020 10:25:43 +0100 Subject: Initial Commit --- binTime.h | 330 ++++++++++++++++++++++++++++++++++++++++ main.c.c | 174 ++++++++++++++++++++++ setTime.h | 505 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1009 insertions(+) create mode 100644 binTime.h create mode 100644 main.c.c create mode 100644 setTime.h diff --git a/binTime.h b/binTime.h new file mode 100644 index 0000000..36a0128 --- /dev/null +++ b/binTime.h @@ -0,0 +1,330 @@ +/*****************************************************/ +/* Bausatz BIN_Hourglass ver.1.0 *********************/ +/* binTime.h *****************************************/ +/* Pollin Electronic GmbH ****************************/ +/* 85104 Pförring ************************************/ +/* www.pollin.de *************************************/ +/*****************************************************/ +/* Author: Leonhard Hesse ****************************/ +/*****************************************************/ + +#ifndef BINTIME_H_ +#define BINTIME_H_ + +#include +#include + + +void Time0() { + PORTB |= (1 << PB0); + PORTB |= (1 << PB1); + PORTB |= (1 << PB2); + PORTB |= (1 << PB3); + PORTB |= (1 << PB4); + PORTB |= (1 << PB5); + PORTB |= (1 << PB6); + PORTB |= (1 << PB7); +} +void Time1() { + PORTB &= ~(1 << PB0); +} +void Time2() { + PORTB &= ~(1 << PB1); +} +void Time3() { + PORTB &= ~(1 << PB0); + PORTB &= ~(1 << PB1); +} +void Time4() { + PORTB &= ~(1 << PB2); +} +void Time5() { + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB0); +} +void Time6() { + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); +} +void Time7() { + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time8() { + PORTB &= ~(1 << PB3); +} +void Time9() { + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB0); +} +void Time10() { + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB1); +} +void Time11() { + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time12() { + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); +} +void Time13() { + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB0); +} +void Time14() { + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); +} +void Time15() { + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} + +void Time16() { + PORTB &= ~(1 << PB4); +} +void Time17() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB0); +} +void Time18() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB1); +} +void Time19() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time20() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB2); +} +void Time21() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB0); +} +void Time22() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); +} +void Time23() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time24() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); +} +void Time25() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB0); +} +void Time26() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB1); +} +void Time27() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time28() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); +} +void Time29() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB0); +} +void Time30() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); +} +void Time31() { + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time32() { + PORTB &= ~(1 << PB5); +} +void Time33() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB0); +} +void Time34() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB1); +} +void Time35() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time36() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB2); +} +void Time37() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB0); +} +void Time38() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); +} +void Time39() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time40() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB3); +} +void Time41() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB0); +} +void Time42() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB1); +} +void Time43() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time44() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); +} +void Time45() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB0); +} +void Time46() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); +} +void Time47() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time48() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); +} +void Time49() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB0); +} +void Time50() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB1); +} +void Time51() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time52() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB2); +} +void Time53() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB0); +} +void Time54() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); +} +void Time55() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time56() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); +} +void Time57() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB0); +} +void Time58() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB1); +} +void Time59() { + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB0); +} +void Time255() { + PORTB &= ~(1 << PB0); + PORTB &= ~(1 << PB1); + PORTB &= ~(1 << PB2); + PORTB &= ~(1 << PB3); + PORTB &= ~(1 << PB4); + PORTB &= ~(1 << PB5); + PORTB &= ~(1 << PB6); + PORTB &= ~(1 << PB7); +} + +#endif /* BINTIME_H_ */ diff --git a/main.c.c b/main.c.c new file mode 100644 index 0000000..9ab0d74 --- /dev/null +++ b/main.c.c @@ -0,0 +1,174 @@ +/****************************************************************************/ +/* Bausatz BIN-Hourglass ver.1.0 ********************************************/ +/* main.c *******************************************************************/ +/* Pollin Electronic GmbH ***************************************************/ +/* 85104 Pförring ***********************************************************/ +/* www.pollin.de ************************************************************/ +/****************************************************************************/ +/* Author: Leonhard Hesse ***************************************************/ +/****************************************************************************/ + +#define F_CPU 2000000UL + +#include +#include +#include +#include +#include "binTime.h" +#include "setTime.h" + +volatile uint8_t tasterZaeler = 4; +volatile uint16_t clockDelay = 0; + +/****************************************************************************/ +/* interrupt routine user button 1 ******************************************/ +/****************************************************************************/ + +ISR(INT0_vect) { + if (tasterZaeler >= 2) { + tasterZaeler = 1; + hour++; + clockDelay = 0; + _delay_ms(200); + } +} + +/****************************************************************************/ +/* interrupt routine user button 2 ******************************************/ +/****************************************************************************/ + +ISR(INT1_vect) { + if (tasterZaeler >= 2) { + tasterZaeler = 1; + minute++; + clockDelay = 0; + _delay_ms(200); + } +} + +/****************************************************************************/ +/* interrupt routine for 16-Bit-Timer to count seconds **********************/ +/****************************************************************************/ + +ISR (TIMER1_COMPA_vect) { + second++; +} + +/****************************************************************************/ +/* implement methods to light the LEDs for ca. 0,1 ms ***********************/ +/****************************************************************************/ + +void showHour() { + for (int i = 0; i < 200; i++) { + hourOn(); + } + hourOff(); +} +void showMinute() { + for (int i = 0; i < 200; i++) { + minuteOn(); + } + minuteOff(); +} +void showSecond() { + for (int i = 0; i < 200; i++) { + secondOn(); + } + secondOff(); +} +void showTime() { + showHour(); + showMinute(); + showSecond(); +} + +/****************************************************************************/ +/* implement methods to switch off the LEDs for ca. 0,1 ms ******************/ +/****************************************************************************/ +void hideHour() { + for (int i = 0; i < 200; i++) { + hourOff(); + } +} +void hideMinute() { + for (int i = 0; i < 200; i++) { + minuteOff(); + } +} +void hideSecond() { + for (int i = 0; i < 200; i++) { + secondOff(); + } +} +void hideTime() { + hideHour(); + hideMinute(); + hideSecond(); +} + +int main(void) { + + /************************************************************************/ + /* initialize ports and external interrupts *****************************/ + /************************************************************************/ + + DDRB |= (1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) | (1 << PB4) + | (1 << PB5) | (1 << PB6) | (1 << PB7); + DDRD |= (1 << PD4) | (1 << PD5) | (1 << PD6); + DDRD &= ~((1 << PD0) | (1 << PD1)); + PORTD |= (1 << PD2) | (1 << PD3); + GIMSK |= (1 << INT0) | (1 << INT1); + MCUCR |= (1 << ISC11) | (1 << ISC10); + sei(); + + PORTB |= (1 << PD4) | (1 << PD5) | (1 << PD6); + PORTB |= ((1 << PB0) | (1 << PB1) | (1 << PB2) | (1 << PB3) | (1 << PB4) + | (1 << PB5) | (1 << PB6) | (1 << PB7)); + + for (;;) { + + /********************************************************************/ + /* show default time for ca. 0,5s and switch off LEDs for ca. 0,5s **/ + /********************************************************************/ + + if (tasterZaeler == 4) { + defaultTime(); + for (int t = 0; t < 200; t++) { + showTime(); + } + for (int t = 0; t < 200; t++) { + hideTime(); + } + } + + /********************************************************************/ + /* start clock after 10s without user input *************************/ + /* if there is an user input stop clock and reset second ************/ + /********************************************************************/ + + if (tasterZaeler >= 1) { + if (tasterZaeler <= 2) { + clockDelay++; + second = 0; + TIMSK &= ~(1 << OCIE1A); + tasterZaeler = 2; + } + } + if (clockDelay == 4000) { + TCCR1B = ((1 << WGM12) | (1 << CS10) | (1 << CS11)); + TIMSK = (1 << OCIE1A); + OCR1A = 31250; + clockDelay = 0; + tasterZaeler = 3; + } + resetTime(); + setSecond(); + showSecond(); + resetTime(); + setMinute(); + showMinute(); + resetTime(); + setHour(); + showHour(); + } +} diff --git a/setTime.h b/setTime.h new file mode 100644 index 0000000..b237259 --- /dev/null +++ b/setTime.h @@ -0,0 +1,505 @@ +/*****************************************************/ +/* Bausatz BIN_Hourglass ver.1.0 *********************/ +/* setTime.h *****************************************/ +/* Pollin Electronic GmbH ****************************/ +/* 85104 Pförring ************************************/ +/* www.pollin.de *************************************/ +/*****************************************************/ +/* Author: Leonhard Hesse ****************************/ +/*****************************************************/ + +#ifndef SETTIME_H_ +#define SETTIME_H_ + +#include +#include +#include "binTime.h" + +volatile uint8_t hour = 0; +volatile uint8_t minute = 0; +volatile uint8_t second = 0; + +void hourOn() { + PORTD &= ~(1 << PD4); +} +void hourOff() { + PORTD |= (1 << PD4); +} +void minuteOn() { + PORTD &= ~(1 << PD5); +} +void minuteOff() { + PORTD |= (1 << PD5); +} +void secondOn() { + PORTD &= ~(1 << PD6); +} +void secondOff() { + PORTD |= (1 << PD6); +} +void resetTime() { + Time0(); +} +void defaultTime() { + Time255(); +} + +void setHour() { + switch (hour) { + case 0: + Time0(); + break; + case 1: + Time1(); + break; + case 2: + Time2(); + break; + case 3: + Time3(); + break; + case 4: + Time4(); + break; + case 5: + Time5(); + break; + case 6: + Time6(); + break; + case 7: + Time7(); + break; + case 8: + Time8(); + break; + case 9: + Time9(); + break; + case 10: + Time10(); + break; + case 11: + Time11(); + break; + case 12: + Time12(); + break; + case 13: + Time13(); + break; + case 14: + Time14(); + break; + case 15: + Time15(); + break; + case 16: + Time16(); + break; + case 17: + Time17(); + break; + case 18: + Time18(); + break; + case 19: + Time19(); + break; + case 20: + Time20(); + break; + case 21: + Time21(); + break; + case 22: + Time22(); + break; + case 23: + Time23(); + break; + } + if (hour > 23) { + hour = 0; + } +} + +void setMinute() { + switch (minute) { + case 0: + Time0(); + break; + case 1: + Time1(); + break; + case 2: + Time2(); + break; + case 3: + Time3(); + break; + case 4: + Time4(); + break; + case 5: + Time5(); + break; + case 6: + Time6(); + break; + case 7: + Time7(); + break; + case 8: + Time8(); + break; + case 9: + Time9(); + break; + case 10: + Time10(); + break; + case 11: + Time11(); + break; + case 12: + Time12(); + break; + case 13: + Time13(); + break; + case 14: + Time14(); + break; + case 15: + Time15(); + break; + case 16: + Time16(); + break; + case 17: + Time17(); + break; + case 18: + Time18(); + break; + case 19: + Time19(); + break; + case 20: + Time20(); + break; + case 21: + Time21(); + break; + case 22: + Time22(); + break; + case 23: + Time23(); + break; + case 24: + Time24(); + break; + case 25: + Time25(); + break; + case 26: + Time26(); + break; + case 27: + Time27(); + break; + case 28: + Time28(); + break; + case 29: + Time29(); + break; + case 30: + Time30(); + break; + case 31: + Time31(); + break; + case 32: + Time32(); + break; + case 33: + Time33(); + break; + case 34: + Time34(); + break; + case 35: + Time35(); + break; + case 36: + Time36(); + break; + case 37: + Time37(); + break; + case 38: + Time38(); + break; + case 39: + Time39(); + break; + case 40: + Time40(); + break; + case 41: + Time41(); + break; + case 42: + Time42(); + break; + case 43: + Time43(); + break; + case 44: + Time44(); + break; + case 45: + Time45(); + break; + case 46: + Time46(); + break; + case 47: + Time47(); + break; + case 48: + Time48(); + break; + case 49: + Time49(); + break; + case 50: + Time50(); + break; + case 51: + Time51(); + break; + case 52: + Time52(); + break; + case 53: + Time53(); + break; + case 54: + Time54(); + break; + case 55: + Time55(); + break; + case 56: + Time56(); + break; + case 57: + Time57(); + break; + case 58: + Time58(); + break; + case 59: + Time59(); + break; + } + if (minute > 59){ + hour++; + minute = 0; + } +} + +void setSecond() { + switch (second) { + case 0: + Time0(); + break; + case 1: + Time1(); + break; + case 2: + Time2(); + break; + case 3: + Time3(); + break; + case 4: + Time4(); + break; + case 5: + Time5(); + break; + case 6: + Time6(); + break; + case 7: + Time7(); + break; + case 8: + Time8(); + break; + case 9: + Time9(); + break; + case 10: + Time10(); + break; + case 11: + Time11(); + break; + case 12: + Time12(); + break; + case 13: + Time13(); + break; + case 14: + Time14(); + break; + case 15: + Time15(); + break; + case 16: + Time16(); + break; + case 17: + Time17(); + break; + case 18: + Time18(); + break; + case 19: + Time19(); + break; + case 20: + Time20(); + break; + case 21: + Time21(); + break; + case 22: + Time22(); + break; + case 23: + Time23(); + break; + case 24: + Time24(); + break; + case 25: + Time25(); + break; + case 26: + Time26(); + break; + case 27: + Time27(); + break; + case 28: + Time28(); + break; + case 29: + Time29(); + break; + case 30: + Time30(); + break; + case 31: + Time31(); + break; + case 32: + Time32(); + break; + case 33: + Time33(); + break; + case 34: + Time34(); + break; + case 35: + Time35(); + break; + case 36: + Time36(); + break; + case 37: + Time37(); + break; + case 38: + Time38(); + break; + case 39: + Time39(); + break; + case 40: + Time40(); + break; + case 41: + Time41(); + break; + case 42: + Time42(); + break; + case 43: + Time43(); + break; + case 44: + Time44(); + break; + case 45: + Time45(); + break; + case 46: + Time46(); + break; + case 47: + Time47(); + break; + case 48: + Time48(); + break; + case 49: + Time49(); + break; + case 50: + Time50(); + break; + case 51: + Time51(); + break; + case 52: + Time52(); + break; + case 53: + Time53(); + break; + case 54: + Time54(); + break; + case 55: + Time55(); + break; + case 56: + Time56(); + break; + case 57: + Time57(); + break; + case 58: + Time58(); + break; + case 59: + Time59(); + break; + } + if (second > 59){ + minute++; + second = 0; + } +} + +#endif /* SETTIME_H_ */ -- cgit v1.2.3-70-g09d2