Fix: changed display digits to 15 according to my vfd

Refactor: one function to set display mode
Enhancement: made demo program display something
Enhancement: changed compiler optimisation for smaller size
This commit is contained in:
2022-03-19 19:03:03 +01:00
parent e7e988c44d
commit 934cbc2441
4 changed files with 19 additions and 28 deletions

View File

@@ -3,7 +3,7 @@ MCU=atmega88
F_CPU=8000000UL F_CPU=8000000UL
CC=avr-gcc CC=avr-gcc
OBJCOPY=avr-objcopy OBJCOPY=avr-objcopy
CFLAGS=-std=c99 -Wall -g -O3 -mmcu=${MCU} -DF_CPU=${F_CPU} -I/usr/lib/avr/include/ CFLAGS=-std=c99 -Wall -g -Os -mcall-prologues -mmcu=${MCU} -DF_CPU=${F_CPU} -I/usr/lib/avr/include/
TARGET=main TARGET=main
SRCS=main.c PT6302.c PT6302.h SRCS=main.c PT6302.c PT6302.h

View File

@@ -93,8 +93,7 @@ void set_duty (uint8_t brightness)
{ {
brightness = 7; brightness = 7;
} }
const uint8_t command = 0x50 | brightness; transmit_byte (0x50 | brightness);
transmit_byte (command);
} }
void set_digits (uint8_t digit_count) void set_digits (uint8_t digit_count)
@@ -138,6 +137,7 @@ void set_CGRAM (const uint8_t address, const uint8_t *data, uint8_t size)
} }
transmit_bytes (payload, size); transmit_bytes (payload, size);
} }
void set_DCRAM (const uint8_t address, const uint8_t *cg_address, uint8_t size) void set_DCRAM (const uint8_t address, const uint8_t *cg_address, uint8_t size)
{ {
if (address > DISPLAY_DIGITS) if (address > DISPLAY_DIGITS)
@@ -152,17 +152,12 @@ void set_DCRAM (const uint8_t address, const uint8_t *cg_address, uint8_t size)
} }
transmit_bytes (payload, size); transmit_bytes (payload, size);
} }
void all_on (void)
void set_display_mode (enum display_modes mode)
{ {
const uint8_t command = 0x72; transmit_byte (mode | 0x70);
transmit_byte (command);
} }
void all_off (void)
{
const uint8_t command = 0x71;
transmit_byte (command);
}
void PT6302_reset (void) void PT6302_reset (void)
{ {
PORTC &= ~RSTpin; PORTC &= ~RSTpin;

View File

@@ -43,6 +43,12 @@ enum RAM_types {
ADRAM = 0x30, ADRAM = 0x30,
}; };
enum display_modes {
NORMAL_MODE = 0x0,
ALL_ON = 0x1,
ALL_OFF = 0x2,
};
/* ------------------------------------------------------------- /* -------------------------------------------------------------
* Initial setup for the VFD controller interface * Initial setup for the VFD controller interface
* Sets up the connected pins and leaves them in inactive state. * Sets up the connected pins and leaves them in inactive state.
@@ -122,14 +128,8 @@ void set_CGRAM (uint8_t address, const uint8_t *data, uint8_t size);
void set_ADRAM (uint8_t address, const uint8_t *data, uint8_t size); void set_ADRAM (uint8_t address, const uint8_t *data, uint8_t size);
/* ----------------------------------------- /* -----------------------------------------
* Turn all outputs of the VFD controller on * Sets the VFD operation mode
* This is primarily used for testing * See operation modes in enum display_modes
* Handles the entire communication * Handles the entire communication
* ----------------------------------------- */ * ----------------------------------------- */
void all_on (void); void set_display_mode (enum display_modes mode);
/* ------------------------------------------
* Turn all outputs of the VFD controller off
* Handles the entire communication
* ------------------------------------------ */
void all_off (void);

12
main.c
View File

@@ -18,8 +18,7 @@
* USA * USA
*/ */
#define F_CPU 8000000UL #define DISPLAY_DIGITS 15
#define DISPLAY_DIGITS 12
#include <avr/io.h> #include <avr/io.h>
#include <util/delay.h> #include <util/delay.h>
@@ -28,10 +27,10 @@
int main () int main ()
{ {
static const uint8_t digitstates[] = static const uint8_t digitstates[] =
{0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11}; {0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00, 0b00};
static const uint8_t custom_chars[8 * 5] = {0}; static const uint8_t custom_chars[8 * 5] = {0};
static const uint8_t characters[] = static const uint8_t characters[] =
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; {0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x48, 0x41, 0x35, 0x4B, 0x46, 0x55, 0x20, 0x20, 0x20};
PT6302_startup (); PT6302_startup ();
set_ports (1, 1); set_ports (1, 1);
set_digits (DISPLAY_DIGITS); set_digits (DISPLAY_DIGITS);
@@ -39,11 +38,8 @@ int main ()
set_ADRAM (0, digitstates, DISPLAY_DIGITS); set_ADRAM (0, digitstates, DISPLAY_DIGITS);
set_CGRAM (0, custom_chars, 8); set_CGRAM (0, custom_chars, 8);
set_DCRAM (0, characters, DISPLAY_DIGITS); set_DCRAM (0, characters, DISPLAY_DIGITS);
set_display_mode (NORMAL_MODE);
while (1) while (1)
{ {
all_on ();
_delay_us (1000);
all_off ();
_delay_us (1000);
} }
} }