commit 008f12d166a0507e656cf016678af7e5cb7586e3 Author: produktr Date: Tue Jul 8 12:12:25 2025 +0200 Upload files to "/" diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f8b852 --- /dev/null +++ b/README.md @@ -0,0 +1,114 @@ +# AtTiny26L-8pi_counter + +Hand held device with display to count button presses. It uses buttons to detect user input one +1 and one for -1. +Made with of the shelf components. + +For me this is a exploration in programming ASM assembly as I had never done this before. +Also the designing was interesting. + +## Components + +### The ATTiny microcontroller +As I had a `ATTiny26L` 8-bit microcontroller laying around I decided to use that. As it already has an onboard clock which is plenty +fast enough for this simple project it saved me from connection a XTAL. + +``` +Ttiny26 + _____________________________________ + 1 / |20 +o--|PB0 /OC1A SDA DI MOSI PA0 ADC0|--o + 2| |19 +o--|PB1 OC1A DO MISO PA1 ADC1|--o + 3| |18 +o--|PB2 /OC1B SCL SCK PA2 ADC2|--o + 4| |17 +o--|PB3 OC1B PA3 AREF|--o + 5| |16 +o--|VCC GND|--o + 6| |15 +o--|GND AVCC|--o + 7| |14 +o--|PB4 XTAL1 ADC7 PA4 ADC3|--o + 8| |13 +o--|PB5 XTAL2 ADC8 PA5 ADC4|--o + 9| |12 +o--|PB6 T0 INT0 ADC9 PA6 ADC5 AIN0|--o + 10| |11 +o--|PB7 RESET ADC10 PA7 ADC6 AIN1|--o + |______________________________________| +``` + +### The shift register +As the ATTiny doesn't have enough outputs do drive a 7-segment display we need a shift register. I used a `74HCT595N` as again this what I had on hand. + +``` +74HCT595N + _____________________________________ + 1 / |16 +o--|Q1 VCC|--o + 2| |15 +o--|Q2 Q0|--o + 3| |14 +o--|Q3 DS|--o + 4| |13 +o--|Q4 ~OE|--o + 5| |12 +o--|Q5 STCP|--o + 6| |11 +o--|Q6 SHCP|--o + 7| |10 +o--|Q7 ~MR|--o + 8| |9 +o--|GND Q7S|--o + |______________________________________| +``` + +### Something to read the number +A 7-segment display sporting 4 digits is used for outputting the number to the user. I used a `CL5642BH-30` as you guessed it already, was the one I had laying around. + +``` +CL5642BH-30 + + DIG1 A F DIG2 DIG3 B + o12 o11 o10 o9 o8 o7 + | | | | | | + ----|------|-------|-------|-------|-------|---- + | | + | | + | | + | | + ----|------|-------|-------|-------|-------|---- + | | | | | | + o1 o2 o3 o4 o5 o6 + E D : C G DIG4 + + + --a-- + f b + --g-- + e c + --d-- + +1 = no path to ground +0 = path to ground + + | b | a | f | e | d | c | g | ; | +MSB | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | LSB + 1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | + 2 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | + 3 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | + 4 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | + 5 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | + 6 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | + 7 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | + 8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | + 9 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | + 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | +``` + +### Other components +Something to mount it all on, for this perfboard was used. +As I use a 9v battery a 5 volt regulator was used. +2 buttons to read the user input. +A 3d printed case. +Supporting electronics like condensators and current resisters as pull-up/down and current limiting. diff --git a/counter.asm b/counter.asm new file mode 100644 index 0000000..bb23577 --- /dev/null +++ b/counter.asm @@ -0,0 +1,629 @@ +; 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<