From 934cbc2441cdee77bee616c0a1f8f52faf2ef312 Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Sat, 19 Mar 2022 19:03:03 +0100 Subject: [PATCH] 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 --- Makefile | 2 +- PT6302.c | 15 +++++---------- PT6302.h | 18 +++++++++--------- main.c | 12 ++++-------- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 553fb80..09d561b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ MCU=atmega88 F_CPU=8000000UL CC=avr-gcc 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 SRCS=main.c PT6302.c PT6302.h diff --git a/PT6302.c b/PT6302.c index 47be36c..f0db39f 100644 --- a/PT6302.c +++ b/PT6302.c @@ -93,8 +93,7 @@ void set_duty (uint8_t brightness) { brightness = 7; } - const uint8_t command = 0x50 | brightness; - transmit_byte (command); + transmit_byte (0x50 | brightness); } 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); } + void set_DCRAM (const uint8_t address, const uint8_t *cg_address, uint8_t size) { 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); } -void all_on (void) + +void set_display_mode (enum display_modes mode) { - const uint8_t command = 0x72; - transmit_byte (command); + transmit_byte (mode | 0x70); } -void all_off (void) -{ - const uint8_t command = 0x71; - transmit_byte (command); -} void PT6302_reset (void) { PORTC &= ~RSTpin; diff --git a/PT6302.h b/PT6302.h index 034ad2f..bdc49fc 100644 --- a/PT6302.h +++ b/PT6302.h @@ -43,6 +43,12 @@ enum RAM_types { ADRAM = 0x30, }; +enum display_modes { + NORMAL_MODE = 0x0, + ALL_ON = 0x1, + ALL_OFF = 0x2, +}; + /* ------------------------------------------------------------- * Initial setup for the VFD controller interface * 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); /* ----------------------------------------- - * Turn all outputs of the VFD controller on - * This is primarily used for testing + * Sets the VFD operation mode + * See operation modes in enum display_modes * Handles the entire communication * ----------------------------------------- */ -void all_on (void); - -/* ------------------------------------------ - * Turn all outputs of the VFD controller off - * Handles the entire communication - * ------------------------------------------ */ -void all_off (void); \ No newline at end of file +void set_display_mode (enum display_modes mode); \ No newline at end of file diff --git a/main.c b/main.c index 62c6a56..38e7dfe 100644 --- a/main.c +++ b/main.c @@ -18,8 +18,7 @@ * USA */ -#define F_CPU 8000000UL -#define DISPLAY_DIGITS 12 +#define DISPLAY_DIGITS 15 #include #include @@ -28,10 +27,10 @@ int main () { 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 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 (); set_ports (1, 1); set_digits (DISPLAY_DIGITS); @@ -39,11 +38,8 @@ int main () set_ADRAM (0, digitstates, DISPLAY_DIGITS); set_CGRAM (0, custom_chars, 8); set_DCRAM (0, characters, DISPLAY_DIGITS); + set_display_mode (NORMAL_MODE); while (1) { - all_on (); - _delay_us (1000); - all_off (); - _delay_us (1000); } }