/* Alcohol Unit Counter - see http://www.technoblogy.com/show?2AUF David Johnson-Davies - www.technoblogy.com - 26th August 2018 ATtiny84 @ 8 MHz (external crystal; BOD disabled) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ #include #include // Seven-segment definitions const int charArrayLen = 14; char charArray[] = { // ABCDEFG Segments 0b1111110, // 0 0b0110000, // 1 0b1101101, // 2 0b1111001, // 3 0b0110011, // 4 0b1011011, // 5 0b1011111, // 6 0b1110000, // 7 0b1111111, // 8 0b1111011, // 9 0b0000000, // 10 Space 0b0000001, // 11 '-' 0b0001000, // 12 '_' 0b1000000 // 13 '^' }; const int Blank = 10; const int Minus = 11; const int Under = 12; const int Over = 13; const int ndigits = 2; const int Units = 2; // Allowed units per day const int Day = 1350; // Number of ticks in a day const int Delay = 500; // Number of display cycles before display blanks const int Max = 40; const int Min = -10; const int Start = 675; // Number of ticks before clock first updates volatile char Buffer[] = {2, 2}; char digit = 0; volatile int Counter; // Units counter volatile int Ticks = Start; // Time counter volatile int Timeout = 0; // Display timeout; 0 = off // Pin assignments char Digits[] = {PORTA1, PORTA7}; // Port A pins const int Button = PIN_B2; // Display multiplexer ********************************************** void DisplayNextDigit () { digit = digit ^ 1; // Toggle between 0 and 1 char segs = charArray[Buffer[digit]]; PORTA = 0; // All low DDRA = 0; // All inputs DDRA = segs & 0x7F; // Set display segments DDRA = DDRA | 1< 3) temp0 = temp1 = Over; else if ((tens == 0) && (units >= 0)) temp0 = Blank; else if ((tens == 0) && (units < 0)) temp0 = Minus; Buffer[0] = temp0; Buffer[1] = temp1; } // Timer/Counter0 interrupt - multiplexes display - 125Hz ISR(TIM0_COMPA_vect) { DisplayNextDigit(); Timeout--; if (Timeout != 0) return; TIMSK0 = 0<