aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/main.c b/src/main.c
index 7978b16..264d56a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,8 +84,10 @@ void interrupt_setup() {
* 0 or 1 which indicates if the LED should be turned on (1) or off (0).
*/
void led_write(int num, int on) {
- GPIOB->ODR &= ~(1 << leds[num]);
- GPIOB->ODR |= (on << leds[num]);
+ int pin = leds[num];
+ GPIOB->ODR ^= (((GPIOB->ODR & (1 << pin)) >> pin) ^ on) << pin;
+ // GPIOB->ODR &= ~(1 << leds[num]);
+ // GPIOB->ODR |= (on << leds[num]);
}
/*
@@ -132,31 +134,34 @@ void timer_delay(unsigned short millis) {
while ((TIM3->SR & TIM_SR_CC1IF) == 0); // wait until c/c goes high
}
+void timer_display(unsigned int minutes, unsigned int seconds, bool colon) {
+ tm1637_segmentsend(0, tm1637_font[minutes / 10]);
+ tm1637_segmentsend(1, tm1637_font[minutes % 10] | (colon * TM1637_COLON));
+ tm1637_segmentsend(2, tm1637_font[seconds / 10]);
+ tm1637_segmentsend(3, tm1637_font[seconds % 10]);
+}
+
int main() {
shield_config();
tm1637_begin();
- timer_delay(2000);
+ timer_delay(100);
unsigned int minutes = 0;
unsigned int seconds = 0;
- TM1637Sequence seq;
- uint8_t dis_br_data[] = { 0b10001111 };
- seq.data = dis_br_data;
- seq.length = 1;
- _tm1637_send(seq);
-
- uint8_t dis_seg_data[] = { 0b11000001, 0b01111111 };
- seq.data = dis_seg_data;
- seq.length = 2;
- _tm1637_send(seq);
+ tm1637_dispcfg(7, 1);
while (1) {
- timer_delay(1e3);
+ timer_delay(500);
+ timer_display(minutes, seconds, false);
+ timer_delay(500);
+ timer_display(minutes, seconds, true);
+
seconds++;
if (seconds >= 60) {
seconds = 0;
minutes++;
+ if (minutes >= 100) minutes = 0;
}
}
}