add matrix selector

This commit is contained in:
King Kévin 2016-01-20 10:53:08 +01:00
parent 7894df3bb3
commit e9a92f16b2
1 changed files with 22 additions and 3 deletions

25
main.c
View File

@ -214,7 +214,6 @@ static const uint8_t ascii_7segments[] = {
/* put digit into memory */ /* put digit into memory */
static void vfd_digit(uint8_t nb, char c) static void vfd_digit(uint8_t nb, char c)
{ {
(void)c;
// there are only 10 digits // there are only 10 digits
if (nb>9) { if (nb>9) {
return; return;
@ -246,6 +245,24 @@ static void vfd_digit(uint8_t nb, char c)
vfd_data[2] = 0; vfd_data[2] = 0;
} }
static void vfd_matrix(uint8_t nb, char c)
{
(void)c;
// there are only 12 matrix
if (nb>11) {
return;
} else if (nb<4) {
vfd_data[0] = 0;
vfd_data[1] = 1<<(3-nb); // select digit
} else {
vfd_data[0] = 1<<(35-nb); // select digit
vfd_data[1] = 0;
}
vfd_data[1] |= 0xff000000;
vfd_data[2] = 0xffffffff;
}
int main(void) int main(void)
{ {
SCB_VTOR = (uint32_t) 0x08002000; // relocate vector table because of the bootloader SCB_VTOR = (uint32_t) 0x08002000; // relocate vector table because of the bootloader
@ -267,6 +284,7 @@ int main(void)
bool vfd_transmit = false; bool vfd_transmit = false;
uint8_t digit = 0; uint8_t digit = 0;
uint8_t c = 0; uint8_t c = 0;
vfd_digit(0,0);
/* blink the LED with every transmitted character */ /* blink the LED with every transmitted character */
while (1) { while (1) {
while (usart_received) { // echo every received character while (usart_received) { // echo every received character
@ -280,10 +298,11 @@ int main(void)
vfd_transmit = true; vfd_transmit = true;
} }
while (vfd_transmit) { while (vfd_transmit) {
vfd_transmit = false;
c = digit+'0'; c = digit+'0';
vfd_digit(digit,c); vfd_matrix(digit,c);
vfd_shift(); vfd_shift();
digit = (digit+1)%10; digit = (digit+1)%12;
// let the fluorescence glow up a bit // let the fluorescence glow up a bit
for (uint32_t i = 0; i < 0x2000; i++) { for (uint32_t i = 0; i < 0x2000; i++) {
__asm__("nop"); __asm__("nop");