mirror of
https://github.com/Derisis13/AT-VFD.git
synced 2025-12-06 19:32:49 +01:00
* Feature: functions to set all RAM types
This commit is contained in:
46
PT6302.c
46
PT6302.c
@@ -72,3 +72,49 @@ void set_digits (uint8_t digit_count)
|
|||||||
const uint8_t command = 0x60 | digit_count;
|
const uint8_t command = 0x60 | digit_count;
|
||||||
transmit_bytes (&command, 1);
|
transmit_bytes (&command, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_ADRAM (const uint8_t address, const uint8_t *data, uint8_t size)
|
||||||
|
{
|
||||||
|
if (address > DISPLAY_DIGITS)
|
||||||
|
return;
|
||||||
|
if (address + size > DISPLAY_DIGITS)
|
||||||
|
size = DISPLAY_DIGITS - address;
|
||||||
|
uint8_t payload[++size];
|
||||||
|
payload[0] = ADRAM | address;
|
||||||
|
for (int i = 1; i < size; ++i)
|
||||||
|
{
|
||||||
|
payload[i] = data[i - 1];
|
||||||
|
}
|
||||||
|
transmit_bytes (payload, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_CGRAM (const uint8_t address, const uint8_t *data, uint8_t size)
|
||||||
|
{
|
||||||
|
if (address > 0x08)
|
||||||
|
return;
|
||||||
|
if (address + size > 0x08)
|
||||||
|
size = 0x08 - address;
|
||||||
|
size = size * 5 + 1;
|
||||||
|
uint8_t payload[size];
|
||||||
|
payload[0] = CGRAM | address;
|
||||||
|
for (int i = 1; i < size; ++i)
|
||||||
|
{
|
||||||
|
payload[i] = *(data + i - 1);
|
||||||
|
}
|
||||||
|
transmit_bytes (payload, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_DCRAM (const uint8_t address, const uint8_t *cg_address, uint8_t size)
|
||||||
|
{
|
||||||
|
if (address > DISPLAY_DIGITS)
|
||||||
|
return;
|
||||||
|
if (address + size > DISPLAY_DIGITS)
|
||||||
|
size = DISPLAY_DIGITS - address;
|
||||||
|
uint8_t payload[++size];
|
||||||
|
payload[0] = DCRAM | address;
|
||||||
|
for (int i = 1; i < size; ++i)
|
||||||
|
{
|
||||||
|
payload[i] = cg_address[i - 1];
|
||||||
|
}
|
||||||
|
transmit_bytes (payload, size);
|
||||||
|
}
|
||||||
40
PT6302.h
40
PT6302.h
@@ -5,6 +5,8 @@
|
|||||||
#ifndef _PT6302_H_
|
#ifndef _PT6302_H_
|
||||||
#define _PT6302_H_
|
#define _PT6302_H_
|
||||||
|
|
||||||
|
#define DISPLAY_DIGITS 12
|
||||||
|
|
||||||
/* PT6302 timing constants, all in usec */
|
/* PT6302 timing constants, all in usec */
|
||||||
static const uint8_t TCW = 1; //CLKB pulse width
|
static const uint8_t TCW = 1; //CLKB pulse width
|
||||||
static const uint8_t TDOFF = 16; //Data processing time
|
static const uint8_t TDOFF = 16; //Data processing time
|
||||||
@@ -19,6 +21,12 @@ enum pins {
|
|||||||
DINpin = (1 << PB7),
|
DINpin = (1 << PB7),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum RAM_types{
|
||||||
|
DCRAM = 0x10,
|
||||||
|
CGRAM = 0x20,
|
||||||
|
ADRAM = 0x30,
|
||||||
|
};
|
||||||
|
|
||||||
/* -------------------------------------------------------------
|
/* -------------------------------------------------------------
|
||||||
* 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.
|
||||||
@@ -52,4 +60,36 @@ void set_digits(uint8_t digit_count);
|
|||||||
* ----------------------------------------------------------- */
|
* ----------------------------------------------------------- */
|
||||||
void set_duty (uint8_t brightness);
|
void set_duty (uint8_t brightness);
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------------------------------
|
||||||
|
* Set the content of the DCRAM - this will display a character from the CGROM/RAM at address
|
||||||
|
* cd_address is an array of the CGROM/RAM addresses of characters to display
|
||||||
|
* size is the number of characters to display (max DISPLAY_DIGITS - address)
|
||||||
|
* if exceeded, max possible number of characters will be displayed
|
||||||
|
* address is the starting address (4 bits, max DISPLAY_DIGITS)
|
||||||
|
* if DISPLAY_DIGITS is exceeded, no characters will be set
|
||||||
|
* Handles the entire communication
|
||||||
|
* ------------------------------------------------------------------------------------------ */
|
||||||
|
void set_DCRAM(uint8_t address, const uint8_t* cg_address, uint8_t size);
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------------
|
||||||
|
* Set the content of the CGRAM - this will write custom characters into the CGRAM
|
||||||
|
* data is an array of 5-byte arrays that contain the custom character data
|
||||||
|
* size is the number of 5-byte arrays
|
||||||
|
* address is the starting address (3 bits)
|
||||||
|
* Handles the entire communication
|
||||||
|
* ------------------------------------------------------------------------------- */
|
||||||
|
void set_CGRAM (uint8_t address, const uint8_t *data, uint8_t size);
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------------------------------
|
||||||
|
* Set the content of the ADRAM - This will cause the corresponding segments to be set
|
||||||
|
* data is an array containing sequential data of the segments (one byte for two segments)
|
||||||
|
* elements of the array are truncated after two bits
|
||||||
|
* size is the number of segment pairs to be changed (max DISPLAY_DIGITS pairs - address)
|
||||||
|
* if exceeded, max possible number of segment pairs will be set
|
||||||
|
* address is the starting address (4 bits, max DISPLAY_DIGITS)
|
||||||
|
* if DISPLAY_DIGITS is exceeded, no segment pairs will be set
|
||||||
|
* Handles the entire communication
|
||||||
|
* --------------------------------------------------------------------------------------- */
|
||||||
|
void set_ADRAM(uint8_t address, const uint8_t* data, uint8_t size);
|
||||||
|
|
||||||
#endif //_PT6302_H_
|
#endif //_PT6302_H_
|
||||||
|
|||||||
15
main.c
15
main.c
@@ -1,4 +1,6 @@
|
|||||||
#define F_CPU 8000000UL
|
#define F_CPU 8000000UL
|
||||||
|
#define DISPLAY_DIGITS 12
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include "PT6302.h"
|
#include "PT6302.h"
|
||||||
@@ -10,12 +12,23 @@ static const uint8_t lightoff = 0x71;
|
|||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
|
static const uint8_t digitstates[] =
|
||||||
|
{0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11, 0b11};
|
||||||
|
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};
|
||||||
PT6302_startup ();
|
PT6302_startup ();
|
||||||
set_ports (1, 1);
|
set_ports (1, 1);
|
||||||
set_digits (12);
|
set_digits (12);
|
||||||
set_duty (7);
|
set_duty (7);
|
||||||
|
set_ADRAM (0, digitstates, DISPLAY_DIGITS);
|
||||||
|
set_CGRAM (0,custom_chars, 8);
|
||||||
|
set_DCRAM (0, characters, DISPLAY_DIGITS);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
transmit_bytes (&lighton, 1);
|
||||||
|
_delay_us (1000);
|
||||||
|
transmit_bytes (&lightoff, 1);
|
||||||
|
_delay_us (1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user