use timer to output data
This commit is contained in:
parent
515ecdfa3a
commit
486d80f00d
32
lib/vfd.c
32
lib/vfd.c
|
@ -477,6 +477,18 @@ void vfd_off(void)
|
||||||
gpio_set(VFD_PORT, VFD_STR); // disable HV output
|
gpio_set(VFD_PORT, VFD_STR); // disable HV output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* output data on the parts */
|
||||||
|
void vfd_refresh_on(void)
|
||||||
|
{
|
||||||
|
timer_enable_counter(VFD_TIMER); // start timer to periodically output that to the parts
|
||||||
|
}
|
||||||
|
|
||||||
|
/* stop outputting data on the parts*/
|
||||||
|
void vfd_refresh_off(void)
|
||||||
|
{
|
||||||
|
timer_disable_counter(VFD_TIMER); // stop timer to periodically output that to the parts
|
||||||
|
}
|
||||||
|
|
||||||
/* setup VFD */
|
/* setup VFD */
|
||||||
void vfd_setup(void)
|
void vfd_setup(void)
|
||||||
{
|
{
|
||||||
|
@ -522,11 +534,9 @@ void vfd_setup(void)
|
||||||
timer_reset(VFD_TIMER); // reset timer state
|
timer_reset(VFD_TIMER); // reset timer state
|
||||||
timer_set_mode(VFD_TIMER, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); // set timer mode, use undivided timer clock,edge alignment (simple count), and count up
|
timer_set_mode(VFD_TIMER, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); // set timer mode, use undivided timer clock,edge alignment (simple count), and count up
|
||||||
timer_set_prescaler(VFD_TIMER, (SYSTEM_CLOCK_FREQ/(1<<16))-1); // set the prescaler so this 16 bits timer overflows at 1Hz
|
timer_set_prescaler(VFD_TIMER, (SYSTEM_CLOCK_FREQ/(1<<16))-1); // set the prescaler so this 16 bits timer overflows at 1Hz
|
||||||
//timer_set_period(0xffff/(VFD_DIGITS+VFD_MATRIX)/150); // set the refresh frequency
|
timer_set_period(VFD_TIMER, 0xffff/(VFD_DIGITS+VFD_MATRIX)/150); // set the refresh frequency
|
||||||
timer_set_period(VFD_TIMER, 0xfffff);
|
|
||||||
timer_enable_irq(VFD_TIMER, TIM_DIER_UIE); // enable interrupt for timer
|
timer_enable_irq(VFD_TIMER, TIM_DIER_UIE); // enable interrupt for timer
|
||||||
nvic_enable_irq(VFD_TIMER_IRQ); // allow interrupt for timer
|
nvic_enable_irq(VFD_TIMER_IRQ); // allow interrupt for timer
|
||||||
timer_enable_counter(VFD_TIMER); // enable timer
|
|
||||||
|
|
||||||
vfd_clear(); // initialize values
|
vfd_clear(); // initialize values
|
||||||
}
|
}
|
||||||
|
@ -557,9 +567,21 @@ void tim4_isr(void)
|
||||||
void tim5_isr(void)
|
void tim5_isr(void)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
static uint8_t vfd_mux = 0; // which part to output
|
||||||
|
|
||||||
if (timer_get_flag(VFD_TIMER, TIM_SR_UIF)) { // overflow even happened
|
if (timer_get_flag(VFD_TIMER, TIM_SR_UIF)) { // overflow even happened
|
||||||
timer_clear_flag(VFD_TIMER, TIM_SR_UIF); // clear flag
|
timer_clear_flag(VFD_TIMER, TIM_SR_UIF); // clear flag
|
||||||
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
if (vfd_mux<LENGTH(vfd_digits)) {
|
||||||
|
if (vfd_digits[vfd_mux]!=0) { // skip unused digits
|
||||||
|
vfd_digit(vfd_mux,vfd_digits[vfd_mux]); // set digit
|
||||||
|
vfd_shift(); // shift out data
|
||||||
|
}
|
||||||
|
} else if (vfd_mux<LENGTH(vfd_digits)+LENGTH(vfd_matrixs)) {
|
||||||
|
if (vfd_matrixs[vfd_mux-LENGTH(vfd_digits)]!=0) { // skip unused matrix
|
||||||
|
vfd_matrix(vfd_mux-LENGTH(vfd_digits),vfd_matrixs[vfd_mux-LENGTH(vfd_digits)]); // set matrix
|
||||||
|
vfd_shift(); // shift out data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vfd_mux = (vfd_mux+1)%(LENGTH(vfd_digits)+LENGTH(vfd_matrixs)); // got to next segment
|
||||||
}
|
}
|
||||||
//gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,9 @@ void vfd_transmit(void);
|
||||||
void vfd_on(void);
|
void vfd_on(void);
|
||||||
/* switch VFD display off */
|
/* switch VFD display off */
|
||||||
void vfd_off(void);
|
void vfd_off(void);
|
||||||
|
/* output data on the parts */
|
||||||
|
void vfd_refresh_on(void);
|
||||||
|
/* stop outputing data on the parts*/
|
||||||
|
void vfd_refresh_off(void);
|
||||||
/* setup VFD */
|
/* setup VFD */
|
||||||
void vfd_setup(void);
|
void vfd_setup(void);
|
||||||
|
|
4
main.c
4
main.c
|
@ -93,6 +93,7 @@ int main(void)
|
||||||
vfd_shift();
|
vfd_shift();
|
||||||
|
|
||||||
bool vfd_flag = false;
|
bool vfd_flag = false;
|
||||||
|
bool refresh = true;
|
||||||
for (uint8_t i=0; i<LENGTH(vfd_digits); i++) {
|
for (uint8_t i=0; i<LENGTH(vfd_digits); i++) {
|
||||||
vfd_digits[i] = '0'+i;
|
vfd_digits[i] = '0'+i;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +112,8 @@ int main(void)
|
||||||
while (vfd_flag) {
|
while (vfd_flag) {
|
||||||
vfd_flag = false;
|
vfd_flag = false;
|
||||||
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
||||||
vfd_transmit();
|
refresh ? vfd_refresh_on() : vfd_refresh_off();
|
||||||
|
refresh = !refresh;
|
||||||
}
|
}
|
||||||
__WFI(); // go to sleep
|
__WFI(); // go to sleep
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue