Innitial commit, blinky

This commit is contained in:
2022-03-02 20:16:53 +01:00
commit dd641a1af6
5 changed files with 157 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
./cmake-build-debug
./.idea

22
CMakeLists.txt Normal file
View File

@@ -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}"
)

73
PT6302.c Normal file
View File

@@ -0,0 +1,73 @@
//
// Created by lacko on 02/03/2022.
//
#include <avr/io.h>
#include <util/delay.h>
#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);
}
}

42
PT6302.h Normal file
View File

@@ -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_

18
main.c Normal file
View File

@@ -0,0 +1,18 @@
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
int main ()
{
uint8_t ledpin = (1 << PC4);
DDRC |= ledpin;
while (1)
{
PORTC |= ledpin;
_delay_ms (1000);
PORTC &= ~ledpin;
_delay_ms (1000);
}
}