From 17ec23023d2cf5d709be779588502773e0b2b10a Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Mon, 7 Mar 2022 16:42:54 +0100 Subject: [PATCH] * QA: formatting * Feature: `set_duty()` for setting VFD duty cycle --- PT6302.c | 17 +++++++++++++---- PT6302.h | 16 +++++++++++----- main.c | 1 + 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/PT6302.c b/PT6302.c index 6c88433..224a583 100644 --- a/PT6302.c +++ b/PT6302.c @@ -42,13 +42,22 @@ void transmit_bytes (const uint8_t *payload, const uint8_t size) PORTB |= CSBpin; } - -void set_ports(uint8_t gp1, uint8_t gp2) +void set_ports (uint8_t gp1, uint8_t gp2) { uint8_t command = 0x40; - if(gp1 != 0 ) + if (gp1 != 0) command |= 0x01; if (gp2 != 0) command |= 0x02; transmit_bytes (&command, 1); -} \ No newline at end of file +} + +void set_duty (uint8_t brightness) +{ + if (brightness > 7) + { + brightness = 7; + } + uint8_t command = 0x50 | brightness; + transmit_bytes (&command, 1); +} diff --git a/PT6302.h b/PT6302.h index 1c1e904..bf6599f 100644 --- a/PT6302.h +++ b/PT6302.h @@ -23,20 +23,26 @@ enum pins { * Initial setup for the VFD controller interface * Sets up the connected pins and leaves them in inactive state. * ------------------------------------------------------------- */ -void PT6302_startup(void); - +void PT6302_startup (void); /* ------------------------------------------------------------------------------- * Transmits size byte of data through the VFD controller's interface from payload * Handles CLKB, CSB and timing constraints * ------------------------------------------------------------------------------- */ -void transmit_bytes (const uint8_t* payload, uint8_t size); - +void transmit_bytes (const uint8_t *payload, uint8_t size); /* --------------------------------------------------------- * Sets GP1 and GP2 to the values given in the function call * Handles the entire communication * --------------------------------------------------------- */ -void set_ports(uint8_t gp1, uint8_t gp2); +void set_ports (uint8_t gp1, uint8_t gp2); + +/* ----------------------------------------------------------- + * Sets duty cycle of controlled VFD + * Brightness between 0 and 7 are accepted, any higher means 7 + * duty = (brightness + 8)/16 (valid between 8/16 and 15/16) + * Handles the entire communication + * ----------------------------------------------------------- */ +void set_duty (uint8_t brightness); #endif //_PT6302_H_ diff --git a/main.c b/main.c index 0c8b6b8..d2e6f0e 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ int main () { PT6302_startup (); set_ports (1, 1); + set_duty (7); while (1) {