Given that I accomplished shrinking size of my project and with huge help here and on arduino stack exchange, basically rewrited to atmel studio, my "fire cat" displays all(but 1 led, this was problem before idk, sometimes works sometimes not, not that big of a problem) leds, problem now is I have a button connected on Attiny13a PB3, in theory and simulator everything works, but then IRL it doesnt, like it cant even read the f*in pin
#include <stdbool.h>
#include <string.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/atomic.h>
#define bit_is_set(sfr, bit) (_SFR_BYTE(sfr) & _BV(bit))
#define bit_is_clear(sfr, bit) (!(_SFR_BYTE(sfr) & _BV(bit)))
#define INPUT 0x0f
#define LOW 0x00
#define HIGH 0x01
// Configure Timer 0 to count milliseconds, assuming F_CPU = 8 MHz.
static void init_timer() {
OCR0A = 125 - 1; // period = 125*64 = 8000 CPU cycles
TCCR0A = _BV(WGM01); // CTC, TOP = OCR0A
TCCR0B = _BV(CS00) // clock @ F_CPU/64
| _BV(CS01); // ditto
TIMSK0 = _BV(TOIE0); // enable timer overflow interrupt
}
volatile uint16_t millis_counter;
// Count a millisecond on each timer overflow.
ISR(TIM0_OVF_vect) {
++millis_counter;
}
// Read the milliseconds counter avoiding race conditions.
static uint16_t millis() {
uint16_t millis_counter_copy;
ATOMIC_BLOCK(ATOMIC_FORCEON) {
millis_counter_copy = millis_counter;
}
return millis_counter_copy;
}
static void setup() {
PORTB |= _BV(PB3);
DDRB &= ~_BV(PB3);
PORTB |= _BV(PB3); // pullup on PB3
init_timer();
sei();
}
// Set a pin as either INPUT, LOW or HIGH.
static void set_pin(uint8_t pin_mask, uint8_t state) {
if (state == INPUT) {
DDRB &= ~pin_mask; // INPUT
PORTB &= ~pin_mask; // no pullup
} else {
if (state)
PORTB |= pin_mask; // HIGH
else
PORTB &= ~pin_mask; // LOW
DDRB |= pin_mask; // OUTPUT
}
}
static void charlie(uint8_t a[])
{
set_pin(_BV(PB0), a[0]);
set_pin(_BV(PB1), a[1]);
set_pin(_BV(PB2), a[2]);
set_pin(_BV(PB4), a[3]);
}
static uint16_t oldTime = 0;
static bool holdButt = false;
static uint16_t holdTime = 0;
static uint16_t shortPressATime = 0;
static bool kozichOn = true;
void loop() {
static uint8_t koz1[4] = {INPUT,LOW,HIGH,INPUT};
static uint8_t koz2[4] = {INPUT,HIGH,LOW,INPUT};/*
memcpy(koz2, koz1, sizeof(koz1[0])*4);
koz2[1] = HIGH;
koz2[2] = LOW;
*/
static uint8_t koz3[4] = {LOW,HIGH,INPUT,INPUT};
static uint8_t koz4[4] = {HIGH,LOW,INPUT,INPUT};;/*
memcpy(koz4, koz3, sizeof(koz3[0])*4);
koz4[0] = HIGH;
koz4[1] = LOW;
*/
static uint8_t koz5[4] = {LOW, INPUT,INPUT,HIGH};
static uint8_t koz6[4] = {HIGH, INPUT,INPUT,LOW};/*
memcpy(koz6, koz5, sizeof(koz5[0])*4);
koz4[0] = HIGH;
koz4[3] = LOW;
*/
static uint8_t cap[4] = {INPUT, HIGH,INPUT,LOW};
static uint8_t oko1[4] = {LOW, INPUT,HIGH,INPUT};
static uint8_t oko2[4] = {HIGH, INPUT,LOW,INPUT};/*
memcpy(oko2, oko1, sizeof(oko1[0])*4);
oko2[0] = HIGH;
oko2[2] = LOW;
*/
uint16_t Ctime = millis();
uint16_t diffT = Ctime - oldTime;
oldTime = Ctime;
if (bit_is_clear(PINB, PB3))
{
holdButt = true;
holdTime = holdTime + diffT;
}
else if (holdButt && bit_is_set(PINB, PB3)){
holdButt = false;
if(holdTime > 1000){
kozichOn = !kozichOn;
}
else
{
shortPressATime = 5000;
}
holdTime = 0;
}
if(shortPressATime > 0)
{
shortPressATime = shortPressATime - diffT;
if(shortPressATime & 0x100){
charlie(oko1);
charlie(oko2);
}
}
else{
charlie(oko1);
charlie(oko2);
}
if(kozichOn){
charlie(koz1);
charlie(koz2);
charlie(koz3);
charlie(koz4);
charlie(koz5);
charlie(koz6);
charlie(cap);
}
DDRB &= ~(_BV(PB0) | _BV(PB1) | _BV(PB2) | _BV(PB4));
}
int main(void) {
setup();
for (;;)
loop();
}