Feature: transmit_byte for transmitting a single byte

Feature: `all_on` and `all_off` commands for testing
Optimization: marked functions inline
Optimization: inline function for transmitting a single bit
This commit is contained in:
2022-03-11 08:31:40 +01:00
parent 9a326de094
commit 51921de344
3 changed files with 72 additions and 26 deletions

View File

@@ -34,6 +34,30 @@ inline void PT6302_startup (void)
_delay_us (TWRSTB);
}
inline void transmit_bit(const uint8_t data)
{
PORTB &= ~CLKBpin;
if ((data & 0x01) == 0)
PORTB &= ~DINpin;
else
PORTB |= DINpin;
_delay_us (TCW);
PORTB |= CLKBpin;
_delay_us (TCW);
}
void transmit_byte (uint8_t data)
{
_delay_us (1);
PORTB &= ~CSBpin;
for (int j = 0; j < 8; ++j, data = (data >> 1))
{
transmit_bit (data);
}
_delay_us (TCSH);
PORTB |= CSBpin;
}
void transmit_bytes (const uint8_t *payload, const uint8_t size)
{
_delay_us (1);
@@ -43,14 +67,7 @@ void transmit_bytes (const uint8_t *payload, const uint8_t size)
uint8_t data = payload[i];
for (int j = 0; j < 8; ++j, data = (data >> 1))
{
PORTB &= ~CLKBpin;
if ((data & 0x01) == 0)
PORTB &= ~DINpin;
else
PORTB |= DINpin;
_delay_us (TCW);
PORTB |= CLKBpin;
_delay_us (TCW);
transmit_bit (data);
}
_delay_us (TDOFF);
}
@@ -65,7 +82,7 @@ void set_ports (uint8_t gp1, uint8_t gp2)
command |= 0x01;
if (gp2 != 0)
command |= 0x02;
transmit_bytes (&command, 1);
transmit_byte (command);
}
void set_duty (uint8_t brightness)
@@ -75,7 +92,7 @@ void set_duty (uint8_t brightness)
brightness = 7;
}
const uint8_t command = 0x50 | brightness;
transmit_bytes (&command, 1);
transmit_byte (command);
}
void set_digits (uint8_t digit_count)
@@ -86,7 +103,7 @@ void set_digits (uint8_t digit_count)
digit_count = 9;
digit_count -= 8;
const uint8_t command = 0x60 | digit_count;
transmit_bytes (&command, 1);
transmit_byte (command);
}
void set_ADRAM (const uint8_t address, const uint8_t *data, uint8_t size)
@@ -119,7 +136,6 @@ 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)
@@ -133,4 +149,15 @@ void set_DCRAM (const uint8_t address, const uint8_t *cg_address, uint8_t size)
payload[i] = cg_address[i - 1];
}
transmit_bytes (payload, size);
}
}
void all_on (void)
{
const uint8_t command = 0x72;
transmit_byte (command);
}
void all_off (void)
{
const uint8_t command = 0x71;
transmit_byte (command);
}

View File

@@ -1,3 +1,4 @@
#pragma once
/*
* AT-VFD
* Copyright (C) 2022 László Párkányi
@@ -18,15 +19,13 @@
* USA
*/
#ifndef _PT6302_H_
#define _PT6302_H_
#define DISPLAY_DIGITS 12
/* PT6302 timing constants, all in usec */
static const uint8_t TCW = 1; //CLKB pulse width
static const uint8_t TDOFF = 16; //Data processing time
static const uint8_t DTCSH = 16; //time difference between tDOFF and tCSH
static const uint8_t TCSH = 32; //Chip select hold time
static const uint8_t TPRZ = 100; //VDD rise time
static const uint8_t TWRSTB = 1; //RSTB pulse width
@@ -49,6 +48,19 @@ enum RAM_types{
* ------------------------------------------------------------- */
void PT6302_startup (void);
/* --------------------------------
* Transmits the LSB of data
* Handles communication except CSB
* --------------------------------- */
static inline void transmit_bit(uint8_t data);
/* ------------------------------------------------
* Transmits one character (data)
* Handles the entire communication
* this is (mostly) intended to be used by wrappers
* ------------------------------------------------ */
void transmit_byte(uint8_t data);
/* -------------------------------------------------------------------------------
* Transmits size byte of data through the VFD controller's interface from payload
* Handles CLKB, CSB and timing constraints
@@ -59,14 +71,14 @@ 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);
inline void set_ports (uint8_t gp1, uint8_t gp2);
/* ---------------------------------------------------------------------------------------
* Sets the number of digit_count the VFD has
* digit_count below 9 are interpreted as 9 and digit_count above 16 are interpreted as 16
* Handles the entire communication
* --------------------------------------------------------------------------------------- */
void set_digits(uint8_t digit_count);
inline void set_digits(uint8_t digit_count);
/* -----------------------------------------------------------
* Sets duty cycle of controlled VFD
@@ -74,7 +86,7 @@ void set_digits(uint8_t digit_count);
* duty = (brightness + 8)/16 (valid between 8/16 and 15/16)
* Handles the entire communication
* ----------------------------------------------------------- */
void set_duty (uint8_t brightness);
inline void set_duty (uint8_t brightness);
/* ------------------------------------------------------------------------------------------
* Set the content of the DCRAM - this will display a character from the CGROM/RAM at address
@@ -108,4 +120,15 @@ 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);
#endif //_PT6302_H_
/* -----------------------------------------
* Turn all outputs of the VFD controller on
* This is primarily used for testing
* Handles the entire communication
* ----------------------------------------- */
inline void all_on(void);
/* ------------------------------------------
* Turn all outputs of the VFD controller off
* Handles the entire communication
* ------------------------------------------ */
inline void all_off(void);

8
main.c
View File

@@ -25,10 +25,6 @@
#include <util/delay.h>
#include "PT6302.h"
/* PT6302 commands */
static const uint8_t lighton = 0x72;
static const uint8_t lightoff = 0x71;
int main ()
{
@@ -46,9 +42,9 @@ int main ()
set_DCRAM (0, characters, DISPLAY_DIGITS);
while (1)
{
transmit_bytes (&lighton, 1);
all_on();
_delay_us (1000);
transmit_bytes (&lightoff, 1);
all_off();
_delay_us (1000);
}
}