From dd641a1af6a698c6ad14bc0f1cd1d31f71070bd9 Mon Sep 17 00:00:00 2001 From: Derisis13 Date: Wed, 2 Mar 2022 20:16:53 +0100 Subject: [PATCH] Innitial commit, blinky --- .gitignore | 2 ++ CMakeLists.txt | 22 +++++++++++++++ PT6302.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ PT6302.h | 42 +++++++++++++++++++++++++++++ main.c | 18 +++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 PT6302.c create mode 100644 PT6302.h create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b0ceaa2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +./cmake-build-debug +./.idea \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2ca7342 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.21) +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_C_STANDARD 99) +project(vfdprog C) + +set(CMAKE_C_COMPILER avr-gcc) +set(TARGET_CPU ATmega88) + +add_compile_definitions("__AVR_${TARGET_CPU}__") +include_directories(/usr/lib/avr/include) + +add_link_options(-Wl,--print-memory-usage) +add_executable(${PROJECT_NAME} main.c + #PT6302.c PT6302.h + ) + +add_custom_target( + FLASH + avrdude -p ${TARGET_CPU} -c USBasp -v -U flash:w:${PROJECT_BINARY_DIR}/${PROJECT_NAME}:a + DEPENDS ${PROJECT_NAME} + COMMENT "Flash to ${TARGET_CPU}" +) \ No newline at end of file diff --git a/PT6302.c b/PT6302.c new file mode 100644 index 0000000..1368e76 --- /dev/null +++ b/PT6302.c @@ -0,0 +1,73 @@ +// +// Created by lacko on 02/03/2022. +// +#include +#include +#include "PT6302.h" + +void PT6302_startup (void) +{ + PORTB |= (CSBpin | CLKBpin); + PORTB &= ~DINpin; + PORTC |= RSTpin; + DDRB |= (CSBpin | CLKBpin | DINpin); + DDRC |= RSTpin; + _delay_us (TPRZ); + PORTC &= ~RSTpin; + _delay_us (TWRSTB); +}; + +void transmit_bytes (const uint8_t *payload, const uint8_t size) +{ + PORTB &= ~CSBpin; + for (int i = 0; i < size; ++i) + { + uint8_t data = payload[i]; + for (int j = 0; j < 8; ++j) + { + PORTB &= ~CLKBpin; + if ((data & 0x01) == 0) + { + PORTB |= DINpin; + } + else + { + PORTB &= ~DINpin; + } + _delay_us (TCW); + PORTB |= CLKBpin; + _delay_us (TCW); + data >> 1; + } + _delay_us (TDOFF); + } + _delay_us (DTCSH); + PORTB |= CSBpin; +} + +void send_command (const uint8_t command) +{ + transmit_bytes (&command, 1); +} + + +void set_display_brightness (uint8_t level) +{ + switch (level) + { + case 0:send_command (0x0A); + break; + case 1:send_command (0x2A); + break; + case 2:send_command (0x4A); + break; + case 3:send_command (0x6A); + break; + case 4:send_command (0x8A); + break; + case 5:send_command (0xAA); + break; + case 6:send_command (0xCA); + default:send_command (0xEA); + } +} diff --git a/PT6302.h b/PT6302.h new file mode 100644 index 0000000..2e85cb9 --- /dev/null +++ b/PT6302.h @@ -0,0 +1,42 @@ +// +// Created by lacko on 02/03/2022. +// + +#ifndef _PT6302_H_ +#define _PT6302_H_ + +/* PT6302 timing constants, all in usec */ +#define TCW 1 //CLKB pulse width +#define TDOFF 8 //Data processing time +#define DTCSH 16 //time difference between tDOFF and tCSH +#define TPRZ 100 //VDD rise time +#define TWRSTB 1 //RSTB pulse width + +#define RSTpin (uint8_t) (1 << PC2) +#define CSBpin (uint8_t) (1 << PB0) +#define CLKBpin (uint8_t) (1 << PB6) +#define DINpin (uint8_t) (1 << PB7) + + +/* ------------------------------------------------------------- + * Innitial setup for the VFD controller interface + * Sets up the connected pins and leaves them in inactive state. + * ------------------------------------------------------------- */ +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); + + +/* -------------------------------------------------------------- + * Set the brightness of the VFD + * level can be between 0-7, 7 and larger will set max brightness + * It sets the display's duty cycle to conroll the brightness + * -------------------------------------------------------------- */ +void set_display_brightness (uint8_t level); + +#endif //_PT6302_H_ diff --git a/main.c b/main.c new file mode 100644 index 0000000..437b27f --- /dev/null +++ b/main.c @@ -0,0 +1,18 @@ +#define F_CPU 8000000UL +#include +#include + + +int main () +{ + uint8_t ledpin = (1 << PC4); + DDRC |= ledpin; + + while (1) + { + PORTC |= ledpin; + _delay_ms (1000); + PORTC &= ~ledpin; + _delay_ms (1000); + } +}