dj-lukas
Published

The Cheapest and Simplest Pulse Counter

This counter is made only from an ATtiny13 and LED diodes.

IntermediateProtip2,733
The Cheapest and Simplest Pulse Counter

Things used in this project

Hardware components

Microchip ATtiny13
×1
LED L-144
×1
Resistor 100 ohm
Resistor 100 ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Tweezer

Story

Read more

Schematics

Charliplexed 7 segment display

wiring diagram

Code

Licz_ATtiny13_7seg.ino

Arduino
pulse counter firmware for ATtiny13
// ----------------   licznik na jednym wyswietlaczu siedmiosegmentowym, przerwanie sprzetowe zwieksza liczbe
// ----------------   2019-07-10  LucasWiackowski(at)gmail.com

#define SEG_CDEG 1
#define SEG_AFED 0
#define SEG_AFBG 2
#define SEG_BC   3
#define ODST     5
#define INTENS  33

volatile byte i=0;

ISR(PCINT0_vect) {
  PCMSK &= ~(1<<PCINT4);
  PORTB &= ~_BV(SEG_AFED) & ~_BV(SEG_AFBG) & ~_BV(SEG_BC) & ~_BV(SEG_CDEG);
  i=++i>19?0:i;
  delay(222);
  PCMSK |= (1<<PCINT4);
}

void setup() {
  DDRB &= ~(1<<PB4);
  PORTB |= 1<<PB4;
  MCUCR |= (1<<ISC00) | (1<<ISC01);
  PCMSK |= (1<<PCINT4);
  GIMSK |= (1<<PCIE);

  DDRB |= _BV(SEG_AFED) | _BV(SEG_AFBG) | _BV(SEG_BC) | _BV(SEG_CDEG);
}

void loop() {
  if(i<10) poka(i);
  else {
    poka(i/10);
    poka(11);
    poka(i%10);
    poka(10);
    poka(11);
  }
}

void poka(const byte j) {
  for(byte k=0; k<INTENS; k++) {
      switch(j) {
        case 0:
          PORTB |= _BV(SEG_AFBG);
          PORTB &= ~_BV(SEG_AFED);
          PORTB &= ~_BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFBG);
          PORTB |= _BV(SEG_AFED);
          PORTB |= _BV(SEG_BC);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST+ODST);
          break;
        case 1:
          PORTB |= _BV(SEG_BC);
          delay(ODST+ODST+ODST);
          break;
        case 2:
          PORTB &= ~_BV(SEG_AFBG);
          PORTB |= _BV(SEG_AFED);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFBG);
          PORTB &= ~_BV(SEG_AFED);
          PORTB |= _BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          PORTB |= _BV(SEG_AFBG);
          PORTB |= _BV(SEG_AFED);
          PORTB &= ~_BV(SEG_BC);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST);
          break;
        case 3:
          PORTB |= _BV(SEG_AFED);
          PORTB |= _BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFED);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          break;
        case 4:
          PORTB |= _BV(SEG_AFBG);
          PORTB &= ~_BV(SEG_BC);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFBG);
          PORTB |= _BV(SEG_BC);
          delay(ODST+ODST);
          break;
        case 5:
          PORTB &= ~_BV(SEG_AFBG);
          PORTB |= _BV(SEG_AFED);
          PORTB &= ~_BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          PORTB |= _BV(SEG_AFBG);
          PORTB &= ~_BV(SEG_AFED);
          PORTB |= _BV(SEG_BC);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST);
          PORTB &= ~_BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          break;
        case 6: 
          PORTB |= _BV(SEG_AFED);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST);
          PORTB |= _BV(SEG_AFBG);
          PORTB &= ~_BV(SEG_AFED);
          PORTB |= _BV(SEG_BC);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFBG);
          PORTB &= ~_BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          break;
        case 7:
          PORTB |= _BV(SEG_AFED);
          PORTB &= ~_BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFED);
          PORTB |= _BV(SEG_BC);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST+ODST);
          break;
        case 8: 
          PORTB |= _BV(SEG_AFBG);
          PORTB |= _BV(SEG_BC);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFBG);
          PORTB |= _BV(SEG_AFED);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFED);
          PORTB &= ~_BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          break;
        case 9: 
          PORTB &= ~_BV(SEG_AFED);
          PORTB |= _BV(SEG_BC);
          PORTB &= ~_BV(SEG_CDEG);
          delay(ODST);
          PORTB |= _BV(SEG_AFBG);
          delay(ODST);
          PORTB &= ~_BV(SEG_AFBG);
          PORTB |= _BV(SEG_AFED);
          PORTB &= ~_BV(SEG_BC);
          PORTB |= _BV(SEG_CDEG);
          delay(ODST);
          break;
        case 10:
          PORTB |= _BV(SEG_CDEG);
          delay(ODST+ODST+ODST);
          break;
        default:
          delay(ODST);
    }
  }
  PORTB &= ~_BV(SEG_AFED);
  PORTB &= ~_BV(SEG_AFBG);
  PORTB &= ~_BV(SEG_BC);
  PORTB &= ~_BV(SEG_CDEG);
}

Credits

dj-lukas

dj-lukas

1 project • 6 followers

Comments