Components and supplies
Resistor 100 ohm
ATtiny13
LED L-144
Tools and machines
Soldering iron (generic)
Tweezer
Apps and platforms
Arduino IDE
Project description
Code
Licz_ATtiny13_7seg.ino
arduino
pulse counter firmware for ATtiny13
1// ---------------- licznik na jednym wyswietlaczu siedmiosegmentowym, przerwanie sprzetowe zwieksza liczbe 2// ---------------- 2019-07-10 LucasWiackowski(at)gmail.com 3 4#define SEG_CDEG 1 5#define SEG_AFED 0 6#define SEG_AFBG 2 7#define SEG_BC 3 8#define ODST 5 9#define INTENS 33 10 11volatile byte i=0; 12 13ISR(PCINT0_vect) { 14 PCMSK &= ~(1<<PCINT4); 15 PORTB &= ~_BV(SEG_AFED) & ~_BV(SEG_AFBG) & ~_BV(SEG_BC) & ~_BV(SEG_CDEG); 16 i=++i>19?0:i; 17 delay(222); 18 PCMSK |= (1<<PCINT4); 19} 20 21void setup() { 22 DDRB &= ~(1<<PB4); 23 PORTB |= 1<<PB4; 24 MCUCR |= (1<<ISC00) | (1<<ISC01); 25 PCMSK |= (1<<PCINT4); 26 GIMSK |= (1<<PCIE); 27 28 DDRB |= _BV(SEG_AFED) | _BV(SEG_AFBG) | _BV(SEG_BC) | _BV(SEG_CDEG); 29} 30 31void loop() { 32 if(i<10) poka(i); 33 else { 34 poka(i/10); 35 poka(11); 36 poka(i%10); 37 poka(10); 38 poka(11); 39 } 40} 41 42void poka(const byte j) { 43 for(byte k=0; k<INTENS; k++) { 44 switch(j) { 45 case 0: 46 PORTB |= _BV(SEG_AFBG); 47 PORTB &= ~_BV(SEG_AFED); 48 PORTB &= ~_BV(SEG_BC); 49 PORTB |= _BV(SEG_CDEG); 50 delay(ODST); 51 PORTB &= ~_BV(SEG_AFBG); 52 PORTB |= _BV(SEG_AFED); 53 PORTB |= _BV(SEG_BC); 54 PORTB &= ~_BV(SEG_CDEG); 55 delay(ODST+ODST); 56 break; 57 case 1: 58 PORTB |= _BV(SEG_BC); 59 delay(ODST+ODST+ODST); 60 break; 61 case 2: 62 PORTB &= ~_BV(SEG_AFBG); 63 PORTB |= _BV(SEG_AFED); 64 delay(ODST); 65 PORTB &= ~_BV(SEG_AFBG); 66 PORTB &= ~_BV(SEG_AFED); 67 PORTB |= _BV(SEG_BC); 68 PORTB |= _BV(SEG_CDEG); 69 delay(ODST); 70 PORTB |= _BV(SEG_AFBG); 71 PORTB |= _BV(SEG_AFED); 72 PORTB &= ~_BV(SEG_BC); 73 PORTB &= ~_BV(SEG_CDEG); 74 delay(ODST); 75 break; 76 case 3: 77 PORTB |= _BV(SEG_AFED); 78 PORTB |= _BV(SEG_BC); 79 PORTB |= _BV(SEG_CDEG); 80 delay(ODST); 81 PORTB &= ~_BV(SEG_AFED); 82 PORTB &= ~_BV(SEG_CDEG); 83 delay(ODST); 84 PORTB |= _BV(SEG_CDEG); 85 delay(ODST); 86 break; 87 case 4: 88 PORTB |= _BV(SEG_AFBG); 89 PORTB &= ~_BV(SEG_BC); 90 delay(ODST); 91 PORTB &= ~_BV(SEG_AFBG); 92 PORTB |= _BV(SEG_BC); 93 delay(ODST+ODST); 94 break; 95 case 5: 96 PORTB &= ~_BV(SEG_AFBG); 97 PORTB |= _BV(SEG_AFED); 98 PORTB &= ~_BV(SEG_BC); 99 PORTB |= _BV(SEG_CDEG); 100 delay(ODST); 101 PORTB |= _BV(SEG_AFBG); 102 PORTB &= ~_BV(SEG_AFED); 103 PORTB |= _BV(SEG_BC); 104 PORTB &= ~_BV(SEG_CDEG); 105 delay(ODST); 106 PORTB &= ~_BV(SEG_BC); 107 PORTB |= _BV(SEG_CDEG); 108 delay(ODST); 109 break; 110 case 6: 111 PORTB |= _BV(SEG_AFED); 112 PORTB &= ~_BV(SEG_CDEG); 113 delay(ODST); 114 PORTB |= _BV(SEG_AFBG); 115 PORTB &= ~_BV(SEG_AFED); 116 PORTB |= _BV(SEG_BC); 117 PORTB &= ~_BV(SEG_CDEG); 118 delay(ODST); 119 PORTB &= ~_BV(SEG_AFBG); 120 PORTB &= ~_BV(SEG_BC); 121 PORTB |= _BV(SEG_CDEG); 122 delay(ODST); 123 break; 124 case 7: 125 PORTB |= _BV(SEG_AFED); 126 PORTB &= ~_BV(SEG_BC); 127 PORTB |= _BV(SEG_CDEG); 128 delay(ODST); 129 PORTB &= ~_BV(SEG_AFED); 130 PORTB |= _BV(SEG_BC); 131 PORTB &= ~_BV(SEG_CDEG); 132 delay(ODST+ODST); 133 break; 134 case 8: 135 PORTB |= _BV(SEG_AFBG); 136 PORTB |= _BV(SEG_BC); 137 PORTB &= ~_BV(SEG_CDEG); 138 delay(ODST); 139 PORTB &= ~_BV(SEG_AFBG); 140 PORTB |= _BV(SEG_AFED); 141 delay(ODST); 142 PORTB &= ~_BV(SEG_AFED); 143 PORTB &= ~_BV(SEG_BC); 144 PORTB |= _BV(SEG_CDEG); 145 delay(ODST); 146 break; 147 case 9: 148 PORTB &= ~_BV(SEG_AFED); 149 PORTB |= _BV(SEG_BC); 150 PORTB &= ~_BV(SEG_CDEG); 151 delay(ODST); 152 PORTB |= _BV(SEG_AFBG); 153 delay(ODST); 154 PORTB &= ~_BV(SEG_AFBG); 155 PORTB |= _BV(SEG_AFED); 156 PORTB &= ~_BV(SEG_BC); 157 PORTB |= _BV(SEG_CDEG); 158 delay(ODST); 159 break; 160 case 10: 161 PORTB |= _BV(SEG_CDEG); 162 delay(ODST+ODST+ODST); 163 break; 164 default: 165 delay(ODST); 166 } 167 } 168 PORTB &= ~_BV(SEG_AFED); 169 PORTB &= ~_BV(SEG_AFBG); 170 PORTB &= ~_BV(SEG_BC); 171 PORTB &= ~_BV(SEG_CDEG); 172} 173
Downloadable files
Charliplexed 7 segment display
wiring diagram
Charliplexed 7 segment display
Charliplexed 7 segment display
wiring diagram
Charliplexed 7 segment display
Comments
Only logged in users can leave comments