changes
This commit is contained in:
79
src/main.c
79
src/main.c
@ -165,6 +165,25 @@ int main() {
|
||||
DDRB &= ~(1 << PB2);
|
||||
PORTB |= (1 << PB1) | (1 << PB2);
|
||||
|
||||
// dark switch
|
||||
DDRD &= ~(1 << PD7);
|
||||
PORTD |= (1 << PD7);
|
||||
|
||||
// stepper
|
||||
DDRC |= (1 << PC4) | (1 << PC3) | (1 << PC2) | (1 << PC1) | (1 << PC0);
|
||||
DDRA |= (1 << PA0) | (1 << PA1);
|
||||
|
||||
PORTC &= ~(1 << PC3);
|
||||
PORTC &= ~(1 << PC2);
|
||||
PORTC &= ~(1 << PC1);
|
||||
PORTC &= ~(1 << PC0);
|
||||
|
||||
PORTA &= ~(1 << PA0);
|
||||
PORTA &= ~(1 << PA1);
|
||||
|
||||
PORTC &= ~(1 << PC4);
|
||||
_delay_ms(1);
|
||||
PORTC |= (1 << PC4);
|
||||
|
||||
sei();
|
||||
|
||||
@ -489,7 +508,7 @@ int main() {
|
||||
break;
|
||||
}
|
||||
|
||||
printf("% 4d:%02d:%02d VALID %02d:%02d:%02d %02d.%02d.%02d %d %d %02d %d %d %d %d %d\n",
|
||||
printf("% 4d:%02d:%02d %02d:%02d:%02d %02d.%02d.%02d %d %d %02d %d %d %d %d %d\n",
|
||||
opTime.hour, opTime.minute, opTime.second,
|
||||
clock.hour, clock.minute, clock.second,
|
||||
clock.day, clock.month, clock.year, clock.weekday,
|
||||
@ -498,7 +517,7 @@ int main() {
|
||||
state++;
|
||||
} else {
|
||||
|
||||
printf("% 4d:%02d:%02d INVALID %02d:%02d:%02d %02d.%02d.%02d %d %d %02d %d %d %d %d %d\n",
|
||||
printf("% 4d:%02d:%02d %02d:%02d:%02d %02d.%02d.%02d %d %d %02d %d %d %d %d %d\n",
|
||||
opTime.hour, opTime.minute, opTime.second,
|
||||
clock.hour, clock.minute, clock.second,
|
||||
clock.day, clock.month, clock.year, clock.weekday,
|
||||
@ -521,29 +540,57 @@ int main() {
|
||||
static uint8_t currentMinutePosition = 0;
|
||||
uint8_t minuteStepPosition = clock.minute * STEPS_PER_MINUTE;
|
||||
if (currentMinutePosition != minuteStepPosition) {
|
||||
printf("Minute: ");
|
||||
PORTA |= (1 << PA1);
|
||||
|
||||
printf("M: ");
|
||||
if (currentMinutePosition > minuteStepPosition) {
|
||||
printf("steps backward, ");
|
||||
printf("b ");
|
||||
currentMinutePosition--;
|
||||
PORTC |= (1 << PC2);
|
||||
} else {
|
||||
printf("f ");
|
||||
currentMinutePosition++;
|
||||
PORTC &= ~(1 << PC2);
|
||||
}
|
||||
currentMinutePosition++;
|
||||
printf("desired: %d, current: %d\n", minuteStepPosition, currentMinutePosition);
|
||||
printf("d: %d, c: %d\n", minuteStepPosition, currentMinutePosition);
|
||||
|
||||
PORTC |= (1 << PC3);
|
||||
_delay_us(50);
|
||||
PORTC &= ~(1 << PC3);
|
||||
} else {
|
||||
PORTA &= ~(1 << PA1);
|
||||
}
|
||||
|
||||
static uint8_t currentHourPosition = 0;
|
||||
uint8_t hourStepPosition = clock.hour * STEPS_PER_HOUR;
|
||||
if (currentHourPosition != hourStepPosition) {
|
||||
printf("Hour: ");
|
||||
PORTA |= (1 << PA0);
|
||||
|
||||
printf("H: ");
|
||||
if (currentHourPosition > hourStepPosition) {
|
||||
printf("steps backward, ");
|
||||
printf("b ");
|
||||
currentHourPosition--;
|
||||
PORTC |= (1 << PC0);
|
||||
} else {
|
||||
printf("f ");
|
||||
currentHourPosition++;
|
||||
PORTC &= ~(1 << PC0);
|
||||
}
|
||||
currentHourPosition++;
|
||||
printf("desired: %d, current: %d\n", hourStepPosition, currentHourPosition);
|
||||
printf("d: %d, c: %d\n", hourStepPosition, currentHourPosition);
|
||||
|
||||
PORTC |= (1 << PC1);
|
||||
_delay_us(50);
|
||||
PORTC &= ~(1 << PC1);
|
||||
} else {
|
||||
PORTA &= ~(1 << PA0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tack != 0) {
|
||||
tack = 0;
|
||||
|
||||
uint8_t light = PIND & (1 << PD7);
|
||||
switch (valid) {
|
||||
case 0:
|
||||
PORTB &= ~(1 << PB0);
|
||||
@ -554,11 +601,19 @@ int main() {
|
||||
PORTB &= ~(1 << PB0);
|
||||
} else {
|
||||
ledToggle = 1;
|
||||
PORTB |= (1 << PB0);
|
||||
if (light != 0) {
|
||||
PORTB |= (1 << PB0);
|
||||
} else {
|
||||
PORTB &= ~(1 << PB0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
PORTB |= (1 << PB0);
|
||||
if (light != 0) {
|
||||
PORTB |= (1 << PB0);
|
||||
} else {
|
||||
PORTB &= ~(1 << PB0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ void uartdrvInit() {
|
||||
// 8 data bit, no parity, 1 stop bit
|
||||
UCSRC = (1 << UCSZ1) | (1 << UCSZ0);
|
||||
// 115200 Baud @ 16MHz
|
||||
UBRRL = 8;
|
||||
UBRRH = 0;
|
||||
UBRRL = 0xa0;
|
||||
UBRRH = 0x01;;
|
||||
FILE *mystdout = fdevopen(uartdrvPutchar, NULL);
|
||||
stdout = mystdout;
|
||||
}
|
||||
|
Reference in New Issue
Block a user