; A digital 4x7 digit display witch keeps track of button presses ; ; 2020 R. Branten ; Written for use with the AtTiny26L-8pi ; ; Clock set to 1Mhz internal clock .NOLIST .include "tn26def.inc" .LIST ;=============================================================================== ; REGISTERS ; ; Register | Name | Function ;-----------|------------------------------------------------------- ; R1 | arithmicRegisterA | Calculations ; R2 | arithmicRegisterB | Calculations ; R3 | arithmicRegisterC | Calculations ; R4 | arithmicRegisterD | Calculations ; R16 | registerA | General purpose ; R17 | registerB | General purpose ; R18 | buttonPushRegister | Button push detection ; R19 | delayRegisterB | Delaying program execution ; R20 | digit1 | Storing ones of 7-segment ; R21 | digit2 | Storing tens of 7-segment ; R22 | digit3 | Storing hundreds of 7-segment ; R23 | digit4 | Storing thousands of 7-segment ; R24 | counterLow | LSB of counter ; R25 | counterHigh | MSB of counter ; R10 | incrementButtonStatus | Button debounce state for increment ; R11 | decrementButtonStatus | Button debounce state for decrement ; .DEF registerA = R16 .DEF registerB = R17 .DEF arithmicRegisterA = R1 .DEF arithmicRegisterB = R2 .DEF arithmicRegisterC = R3 .DEF arithmicRegisterD = R4 .DEF buttonPushRegister = R18 .DEF counterHigh = R25 .DEF counterLow = R24 .DEF delayRegisterA = R18 .DEF delayRegisterB = R19 .DEF incrementButtonStatus = R10 .DEF decrementButtonStatus = R11 ; Digit numbering ; +-----+ +-----+ +-----+ +-----+ ; | | | | | | | | ; | 4 | | 3 | | 2 | | 1 | ; | R23 | | R22 | | R21 | | R22 | ; +-----+ +-----+ +-----+ +-----+ ; .DEF digit1 = R20 .DEF digit2 = R21 .DEF digit3 = R22 .DEF digit4 = R23 ;=============================================================================== ; PINS ; ; Port | Name | Function | Direction | Init ;-------|---------------|-------------------------------|-----------|------ ; PA0 | display4 | Ground fourth segment | OUTPUT | LOW ; PA1 | display2 | Ground third segment | OUTPUT | LOW ; PA2 | display3 | Ground second segment | OUTPUT | LOW ; PA3 | display1 | Ground first segment | OUTPUT | LOW ; PB0 | incrementPin | Trigger ISR | INPUT | LOW ; PB1 | decrementPin | Trigger ISR | INPUT | LOW ; PB4 | latchPin | Latching of shift register | OUTPUT | LOW ; PB5 | clockPin | Clock of shift register | OUTPUT | LOW ; PB6 | dataPin | Data to shift register | OUTPUT | LOW ; ; Inputs .EQU incrementPin = PB0 ; PCINT0 .EQU decrementPin = PB1 ; PCINT0 ; Outputs .EQU latchPin = PB4 ; pin 07 of the Attiny to pin number 12 of the 74HC595 .EQU clockPin = PB5 ; pin 08 of the Attiny to pin number 11 of the 74HC595 .EQU dataPin = PB6 ; pin 09 of the Attiny to pin number 14 of the 74HC595 .EQU display4 = PA0 .EQU display2 = PA1 .EQU display3 = PA2 .EQU display1 = PA3 ;=============================================================================== ; CONSTANTS ; Segment numbers ; +--[1]--+ ; | | ;[2] [3] ; | | ; +--[4]--+ ; | | ;[5] [6] ; | | ; +--[7]--+ [8] ; .EQU displayDigit0 = 0b00000011 .EQU displayDigit1 = 0b01111011 .EQU displayDigit2 = 0b00100101 .EQU displayDigit3 = 0b00110001 .EQU displayDigit4 = 0b01011001 .EQU displayDigit5 = 0b10010001 .EQU displayDigit6 = 0b10000001 .EQU displayDigit7 = 0b00111011 .EQU displayDigit8 = 0b00000001 .EQU displayDigit9 = 0b00010001 ; Button debounce states .EQU BUTTON_IDLE = 0 .EQU BUTTON_DEBOUNCE = 1 .EQU BUTTON_PRESSED = 2 ;=============================================================================== ; VECTORS ; .CSEG .ORG $0000 RJMP RESET ; Hardware Pin and Watchdog Reset RETI ; External Interrupt Request 0 RJMP PIN_CHANGE ; Pin Change Interrupt RETI ; Timer/Counter1 Compare Match 1A RETI ; Timer/Counter1 Compare Match 1B RETI ; Timer/Counter1 Overflow RJMP TIM0_OVF ; Timer/Counter0 Overflow RETI ; USI Start RETI ; USI Overflow RETI ; EEPROM Ready RETI ; Analog Comparator RETI ; ADC Conversion Complete ;=============================================================================== ; SETUP ; RESET: CLI ; Disable interrupts LDI registerA, RAMEND OUT SP, registerA ; Set stack pointer, 8 bits on the attiny26 ; Port A, direction LDI registerA, (1<