now able to drive all VFG parts
This commit is contained in:
parent
515b52ec7b
commit
15100f6e21
99
lib/vfd.c
99
lib/vfd.c
@ -135,7 +135,7 @@ static const uint8_t ascii_7segments[] = {
|
||||
* first value is left-most line
|
||||
* LSB is top dot, MSB is not used
|
||||
*/
|
||||
static const uint8_t ascii_font5x7[][5] = {
|
||||
static const uint8_t font5x7[][5] = {
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00}, // (space)
|
||||
{0x00, 0x00, 0x5F, 0x00, 0x00}, // !
|
||||
{0x00, 0x07, 0x00, 0x07, 0x00}, // "
|
||||
@ -237,7 +237,7 @@ static const uint8_t ascii_font5x7[][5] = {
|
||||
* first value is left-most line
|
||||
* LSB is top dot, MSB is not used
|
||||
*/
|
||||
static const uint8_t ascii_pict5x7[][5] = {
|
||||
static const uint8_t pict5x7[][5] = {
|
||||
{0x08, 0x08, 0x2A, 0x1C, 0x08}, // ->
|
||||
{0x08, 0x1C, 0x2A, 0x08, 0x08}, // <-
|
||||
{0b01110000, 0b01110000, 0b01111010, 0b01111100, 0b01011000}, // bunny side 1
|
||||
@ -255,23 +255,16 @@ static const uint8_t ascii_pict5x7[][5] = {
|
||||
};
|
||||
|
||||
/* the three 32 bits values to be shifted out to the VFD driver */
|
||||
static uint32_t vfd_data[3];
|
||||
static uint32_t vfd_data[3] = {0};
|
||||
|
||||
/* the ten seven segments + dot displays
|
||||
* actually they also have a comma and underline, but we want to save space
|
||||
*/
|
||||
//static uint8_t digits[10];
|
||||
/* the twelve 5x7 dot matrix displays
|
||||
* the last column dot/bit is not used, making them byte aligned
|
||||
*/
|
||||
//static uint8_t dots[12][5];
|
||||
char vfd_digits[VFD_DIGITS] = {0};
|
||||
char vfd_matrixs[VFD_MATRIX] = {0};
|
||||
|
||||
/* set digit <nb> to ASCII character <c>
|
||||
* use the MSB of <c> to enable the dot */
|
||||
void vfd_digit(uint8_t nb, char c)
|
||||
{
|
||||
// there are only 10 digits
|
||||
if (nb>9) {
|
||||
if (!(nb<VFD_DIGITS)) { // check the digit exists
|
||||
return;
|
||||
}
|
||||
vfd_data[0] = 0;
|
||||
@ -308,35 +301,34 @@ void vfd_digit(uint8_t nb, char c)
|
||||
* non ASCII characters are used for pictures */
|
||||
void vfd_matrix(uint8_t nb, char c)
|
||||
{
|
||||
// there are only 12 matrix
|
||||
if (nb>11) {
|
||||
if (!(nb<VFD_MATRIX)) { // check the matrix exists
|
||||
return;
|
||||
} else if (nb<4) {
|
||||
vfd_data[0] = 0;
|
||||
vfd_data[1] = 1<<(3-nb); // select digit
|
||||
vfd_data[1] = 1<<(3-nb); // select matrix
|
||||
} else {
|
||||
vfd_data[0] = 1<<(35-nb); // select digit
|
||||
vfd_data[0] = 1<<(35-nb); // select matrix
|
||||
vfd_data[1] = 0;
|
||||
}
|
||||
|
||||
vfd_data[2] = 0;
|
||||
if ((c<0x80) && (c>=' ')) { // only take printable characters
|
||||
uint8_t i = c-' '; // get index for character
|
||||
if (i<LENGTH(ascii_font5x7)) {
|
||||
vfd_data[1] |= ascii_font5x7[i][0]<<24;
|
||||
vfd_data[2] |= ascii_font5x7[i][1]<<0;
|
||||
vfd_data[2] |= ascii_font5x7[i][2]<<8;
|
||||
vfd_data[2] |= ascii_font5x7[i][3]<<16;
|
||||
vfd_data[2] |= ascii_font5x7[i][4]<<24;
|
||||
if (i<LENGTH(font5x7)) {
|
||||
vfd_data[1] |= font5x7[i][0]<<24;
|
||||
vfd_data[2] |= font5x7[i][1]<<0;
|
||||
vfd_data[2] |= font5x7[i][2]<<8;
|
||||
vfd_data[2] |= font5x7[i][3]<<16;
|
||||
vfd_data[2] |= font5x7[i][4]<<24;
|
||||
}
|
||||
} else if (c>0x7f) { // the non ASCII character are used for pictures
|
||||
uint8_t i = c-0x80; // get index for character
|
||||
if (i<LENGTH(ascii_pict5x7)) {
|
||||
vfd_data[1] |= ascii_pict5x7[i][0]<<24;
|
||||
vfd_data[2] |= ascii_pict5x7[i][1]<<0;
|
||||
vfd_data[2] |= ascii_pict5x7[i][2]<<8;
|
||||
vfd_data[2] |= ascii_pict5x7[i][3]<<16;
|
||||
vfd_data[2] |= ascii_pict5x7[i][4]<<24;
|
||||
if (i<LENGTH(pict5x7)) {
|
||||
vfd_data[1] |= pict5x7[i][0]<<24;
|
||||
vfd_data[2] |= pict5x7[i][1]<<0;
|
||||
vfd_data[2] |= pict5x7[i][2]<<8;
|
||||
vfd_data[2] |= pict5x7[i][3]<<16;
|
||||
vfd_data[2] |= pict5x7[i][4]<<24;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -362,26 +354,45 @@ void vfd_shift(void)
|
||||
gpio_set(VFD_PORT, VFD_NLE); // latch data
|
||||
gpio_clear(VFD_PORT, VFD_STR); // enable HV output
|
||||
gpio_clear(VFD_PORT, VFD_NLE); // stop latching data
|
||||
|
||||
// let the fluorescence glow up a bit
|
||||
for (uint32_t i = 0; i < 0x2000; i++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
}
|
||||
|
||||
/* transmit each digit and dot */
|
||||
/*
|
||||
static void vfd_transmit(void)
|
||||
/* transmit every digit and matrix */
|
||||
void vfd_transmit(void)
|
||||
{
|
||||
// convert digits
|
||||
|
||||
for (uint8_t i=0; i<LENGTH(vfd_digits); i++) {
|
||||
if (vfd_digits[i]==0) {
|
||||
continue; // skip unused digits
|
||||
}
|
||||
vfd_digit(i,vfd_digits[i]); // set digit
|
||||
vfd_shift(); // shift out data
|
||||
// let the fluorescence glow up a bit
|
||||
for (uint32_t j = 0; j < 0x2000; j++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
}
|
||||
for (uint8_t i=0; i<LENGTH(vfd_matrixs); i++) {
|
||||
if (vfd_matrixs[i]==0) {
|
||||
continue; // skip unused matrix
|
||||
}
|
||||
vfd_matrix(i,vfd_matrixs[i]); // set matrix
|
||||
vfd_shift(); // shift out data
|
||||
// let the fluorescence glow up a bit
|
||||
for (uint32_t j = 0; j < 0x2000; j++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* clear VFD display
|
||||
* the data has to be transmitted separately */
|
||||
void vfd_clear(void)
|
||||
{
|
||||
for (uint8_t i=0; i<LENGTH(vfd_digits); i++) {
|
||||
vfd_digits[i] = 0;
|
||||
}
|
||||
for (uint8_t i=0; i<LENGTH(vfd_matrixs); i++) {
|
||||
vfd_matrixs[i] = 0;
|
||||
}
|
||||
for (uint8_t i=0; i<LENGTH(vfd_data); i++) {
|
||||
vfd_data[i] = 0;
|
||||
}
|
||||
@ -391,6 +402,12 @@ void vfd_clear(void)
|
||||
* the data has to be transmitted separately */
|
||||
void vfd_test(void)
|
||||
{
|
||||
for (uint8_t i=0; i<LENGTH(vfd_digits); i++) {
|
||||
vfd_digits[i] = '8';
|
||||
}
|
||||
for (uint8_t i=0; i<LENGTH(vfd_matrixs); i++) {
|
||||
vfd_matrixs[i] = 0x80+LENGTH(pict5x7)-1;
|
||||
}
|
||||
for (uint8_t i=0; i<LENGTH(vfd_data); i++) {
|
||||
vfd_data[i] = ~0;
|
||||
}
|
||||
@ -405,6 +422,8 @@ void vfd_setup(void)
|
||||
gpio_set_mode(VFD_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, VFD_CLK); // set VFD pin to 'output push-pull'
|
||||
gpio_set_mode(VFD_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, VFD_DIN); // set VFD pin to 'output push-pull'
|
||||
|
||||
vfd_clear(); // initialize values
|
||||
|
||||
gpio_set(VFD_PORT, VFD_STR); // disable HV output
|
||||
gpio_clear(VFD_PORT, VFD_NLE); // do not latch data
|
||||
gpio_set(VFD_PORT, VFD_CLK); // clock is idle high
|
||||
|
10
lib/vfd.h
10
lib/vfd.h
@ -24,6 +24,14 @@
|
||||
#define VFD_CLK GPIO6
|
||||
#define VFD_DIN GPIO7
|
||||
|
||||
/* the number of blocks available on the VFD */
|
||||
#define VFD_DIGITS 10
|
||||
#define VFD_MATRIX 12
|
||||
|
||||
/* all digits and matrix values */
|
||||
extern char vfd_digits[VFD_DIGITS];
|
||||
extern char vfd_matrixs[VFD_MATRIX];
|
||||
|
||||
/* set digit <nb> to ASCII character <c>
|
||||
* use the MSB of <c> to enable the dot */
|
||||
void vfd_digit(uint8_t nb, char c);
|
||||
@ -38,5 +46,7 @@ void vfd_clear(void);
|
||||
/* test VFD display (light up all anodes)
|
||||
* the data has to be transmitted separately */
|
||||
void vfd_test(void);
|
||||
/* transmit every digit and matrix */
|
||||
void vfd_transmit(void);
|
||||
/* setup VFD */
|
||||
void vfd_setup(void);
|
||||
|
41
main.c
41
main.c
@ -33,6 +33,9 @@
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
#include "vfd.h" // VFD driver
|
||||
|
||||
/* get the length of an array */
|
||||
#define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
/* default output (i.e. for printf) */
|
||||
int _write(int file, char *ptr, int len)
|
||||
{
|
||||
@ -74,44 +77,34 @@ int main(void)
|
||||
|
||||
printf("welcome to the STM32F1 CuVoodoo display driver\n");
|
||||
|
||||
bool vfd_transmit = false;
|
||||
uint8_t digit = 0;
|
||||
uint8_t matrix = 0;
|
||||
char c = 0x80;
|
||||
|
||||
vfd_clear();
|
||||
vfd_shift();
|
||||
for (uint32_t i = 0; i < 0x800000; i++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
vfd_test();
|
||||
vfd_shift();
|
||||
for (uint32_t i = 0; i < 0x800000; i++) {
|
||||
__asm__("nop");
|
||||
}
|
||||
vfd_digit(digit,'0');
|
||||
vfd_clear();
|
||||
vfd_shift();
|
||||
|
||||
bool vfd_flag = false;
|
||||
for (uint8_t i=0; i<LENGTH(vfd_digits); i++) {
|
||||
vfd_digits[i] = '0'+i;
|
||||
}
|
||||
for (uint8_t i=0; i<LENGTH(vfd_matrixs); i++) {
|
||||
vfd_matrixs[i] = 'A'+i;
|
||||
}
|
||||
while (true) {
|
||||
while (usart_received) { // echo every received character
|
||||
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
||||
printf("%c",usart_getchar()); // transmit receive character
|
||||
vfd_transmit = true;
|
||||
vfd_flag = true;
|
||||
}
|
||||
while (cdcacm_received) { // echo every received character
|
||||
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
||||
printf("%c",cdcacm_getchar()); // transmit receive character
|
||||
vfd_transmit = true;
|
||||
vfd_flag = true;
|
||||
}
|
||||
while (vfd_transmit) {
|
||||
vfd_transmit = false;
|
||||
printf("%u: %c\n", matrix, c);
|
||||
|
||||
vfd_matrix(matrix,c);
|
||||
vfd_shift();
|
||||
|
||||
matrix = (matrix+1)%12;
|
||||
c++;
|
||||
while (vfd_flag) {
|
||||
//vfd_flag = false;
|
||||
gpio_toggle(LED_PORT, LED_PIN); // toggle LED
|
||||
vfd_transmit();
|
||||
}
|
||||
__WFI(); // go to sleep
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user