display numbers

This commit is contained in:
King Kévin 2017-05-06 16:45:17 +02:00
parent 11ccf9aacc
commit 6c117bc4c2
1 changed files with 35 additions and 23 deletions

58
main.c
View File

@ -81,6 +81,9 @@ volatile uint8_t frame_count = 0; /**< number of frames passed */
#define MUX_S2_PORT B /**< port to select multiplexer output */
#define MUX_S2_PIN 5 /**< pin to select multiplexer output */
/** episode, scene, take, video 1, audio 1, video 2, audio 2 number (does not have to be in this order) */
uint16_t numbers[7] = {0};
#define POWER_SWITCH_PORT B /**< port to switch power of all devices (including this micro-controller) */
#define POWER_SWITCH_PIN 8 /**< pin to switch power of all devices (including this micro-controller) */
#define POWER_BUTTON_PORT B /**< port to detect power switching activity (to keep alive) */
@ -438,6 +441,11 @@ void main(void)
nvic_enable_irq(NVIC_EXTI_IRQ(SQUARE_WAVE_PIN)); // enable interrupt
printf("OK\n");
// verify is external RTC is running
if (rtc_ds1307_oscillator_disabled()) {
printf("/!\\ RTC oscillator is disabled: the battery may be empty\n");
rtc_ds1307_oscillator_enable(); // enable oscillator again
}
// display date
uint8_t* rtc_ds1307_time = rtc_ds1307_read_time(); // get time/date from external RTC
if (rtc_ds1307_time==NULL) {
@ -446,41 +454,38 @@ void main(void)
rtc_seconds = rtc_ds1307_time[0]; // remember seconds of minute
printf("current date: 20%02u-%02u-%02u %02u:%02u:%02u\n", rtc_ds1307_time[6], rtc_ds1307_time[5], rtc_ds1307_time[4], rtc_ds1307_time[2], rtc_ds1307_time[1], rtc_ds1307_time[0]);
}
// verify is external RTC is running
if (rtc_ds1307_oscillator_disabled()) {
printf("/!\\ RTC oscillator is disabled: the battery may be empty\n");
rtc_ds1307_oscillator_enable(); // enable oscillator again
}
// setup analog multiplexer for TM1637 clock
printf("setup multiplexer: ");
rcc_periph_clock_enable(RCC_GPIO(MUX_EN_PORT));
gpio_set_mode(GPIO(MUX_EN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(MUX_EN_PIN));
rcc_periph_clock_enable(RCC_GPIO(MUX_EN_PORT)); // enable clock for GPIO port domain
gpio_set_mode(GPIO(MUX_EN_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(MUX_EN_PIN)); // to enable/disable the multiplexer
gpio_set(GPIO(MUX_EN_PORT), GPIO(MUX_EN_PIN)); // disable multiplexer
rcc_periph_clock_enable(RCC_GPIO(MUX_S0_PORT));
gpio_set_mode(GPIO(MUX_S0_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(MUX_S0_PIN));
rcc_periph_clock_enable(RCC_GPIO(MUX_S1_PORT));
gpio_set_mode(GPIO(MUX_S1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(MUX_S1_PIN));
rcc_periph_clock_enable(RCC_GPIO(MUX_S2_PORT));
gpio_set_mode(GPIO(MUX_S2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(MUX_S2_PIN));
rcc_periph_clock_enable(RCC_GPIO(MUX_S0_PORT)); // enable clock for GPIO port domain
gpio_set_mode(GPIO(MUX_S0_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(MUX_S0_PIN)); // to select output channel
rcc_periph_clock_enable(RCC_GPIO(MUX_S1_PORT)); // enable clock for GPIO port domain
gpio_set_mode(GPIO(MUX_S1_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(MUX_S1_PIN)); // to select output channel
rcc_periph_clock_enable(RCC_GPIO(MUX_S2_PORT)); // enable clock for GPIO port domain
gpio_set_mode(GPIO(MUX_S2_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(MUX_S2_PIN)); // to select output channel
printf("OK\n");
// setup TM1637 and MAX7219 7-segments displays
// setup TM1637 4-digit 7-segment displays to display the numbers
printf("setup 7-segment displays: ");
led_tm1637_setup(); // setup TM1637
for (uint8_t tm1637=0; tm1637<7; tm1637++) {
for (uint8_t tm1637=0; tm1637<LENGTH(numbers); tm1637++) {
mux_select(tm1637);
if (!led_tm1637_time(88,88)) { // test TM1637 display
printf("could not test TM1637 %u\n", tm1637);
}
}
// setup MAX7219 8-digit 7-segment displays to display date and time
led_max7219_setup(2); // setup MAX7219
led_max7219_intensity(15,8,0xff); // set brightness max and enable all digits
led_max7219_test(true,0xff); // test all MAX7219 displays
for (uint32_t i=0; i<5000000; i++) { // wait a bit to have the user check the display
__asm__("nop");
}
for (uint8_t tm1637=0; tm1637<7; tm1637++) {
// switch displays back off
for (uint8_t tm1637=0; tm1637<LENGTH(numbers); tm1637++) {
mux_select(tm1637);
if (!led_tm1637_off()) { // switch off display
printf("could not switch off TM1637 %u\n", tm1637);
@ -490,7 +495,17 @@ void main(void)
led_max7219_off(0xff); // switch displays off
printf("OK\n");
// display date and time on 7-segments
// display numbers on TM1637
for (uint8_t number=0; number<LENGTH(numbers); number++) {
mux_select(number);
if (0xffff==numbers[number]) {
led_tm1637_off();
} else {
led_tm1637_number(numbers[number]);
}
}
// display date and time on MAX7219
led_max7219_number(20000000+rtc_ds1307_time[6]*10000+rtc_ds1307_time[5]*100+rtc_ds1307_time[4], 0x14, 1); // display date on 2nd display
led_max7219_number(rtc_ds1307_time[2]*1000000+rtc_ds1307_time[1]*10000+rtc_ds1307_time[0]*100, 0x54, 0); // display time on 1nd display
led_max7219_on(0xff); // switch displays on
@ -589,6 +604,7 @@ void main(void)
while (frame_flag) { // a frame has passed
frame_flag = false; // reset flag
action = true; // action has been performed
// announce the scene and take using Morse code over the buzzer
if (announce) {
while (morse_i<LENGTH(morse)) {
@ -608,6 +624,7 @@ void main(void)
announce = false; // announce finished
}
}
// read button inputs (drive and read each row since they are multiplexed)
uint16_t buttons_new = 0;
gpio_set_mode(GPIO(BUTTONS_DRIVE_PORT), GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(BUTTONS_DRIVE_PIN0));
@ -643,6 +660,7 @@ void main(void)
printf("button pressed: %016b\n", buttons);
}
// display time and frame number
char time[] = "00000000"; // time to display
time[0] += (rtc_ds1307_time[2]/10)%10; // display hours
time[1] += (rtc_ds1307_time[2])%10; // display hours
@ -690,12 +708,6 @@ void main(void)
}
}
}
for (uint8_t tm1637=0; tm1637<7; tm1637++) {
mux_select(tm1637);
if (!led_tm1637_time(rtc_ds1307_time[1],rtc_seconds+tm1637)) { // test TM1637 display
printf("could not send time to TM1637 %u\n", tm1637);
}
}
}
while (keep_alive_flag) { // power switch is detecting movement to keep clapperboard running
keep_alive_flag = false; // clear flag