; ; Project name: memory-led-game ; Description: Simple memory game using leds ; Source code: https://github.com/sergeyyarkov/attiny24a_memory-led-game ; Device: ATtiny24A ; Package: 14-pin-PDIP_SOIC ; Assembler: AVR macro assembler 2.2.7 ; Clock frequency: 8MHz with CKDIV8 ; Fuses: lfuse: 0x42, hfuse: 0xDF, efuse: 0xFF, lock:0xFF ; ; Written by Sergey Yarkov 27.09.2021 .include "def.inc" ; Include type definitions of MCU .list ; Enable listing ; ; Registers .def seq_length_r = r10 ; Current length of sequence .def wdt_counter = r11 ; Counter for wathdog timer .def temp_r = r16 ; Temp general register A .def temp_r_b = r23 ; Temp general register B .def temp_r_c = r26 ; Temp general register C .def mcu_state_r = r17 ; Current state of MCU. This register will be compared in an main loop .def delay_counter_r = r19 ; Register for storing delay counter .def poll_step_r = r20 ; Current poll step for checking the input with answer ; ; LEDS constants .equ LED_DIR = DDRA .equ LED_PORT = PORTA .equ LED_PIN = PINA .equ LED_PIN_0 = PINA0 .equ LED_PIN_1 = PINA1 .equ LED_PIN_2 = PINA2 .equ LED_PIN_3 = PINA3 ; ; Buttons constants .equ SW_DIR = DDRA .equ SW_PORT = PORTA .equ SW_PIN = PINA .equ SW_PIN_4 = PINA4 .equ SW_PIN_5 = PINA5 .equ SW_PIN_6 = PINA6 .equ SW_PIN_7 = PINA7 ; ; Buzzer constants .equ BUZZ_DIR = DDRB .equ BUZZ_PORT = PORTB .equ BUZZ_PIN = PINB2 ; ; States constants .equ INIT_STATE = 0x01 .equ SHOWING_STATE = 0x02 .equ POLLING_STATE = 0x03 ; ; SW Flags states constants .equ SW_FLAG_1 = 0xe0 .equ SW_FLAG_2 = 0xd0 .equ SW_FLAG_3 = 0xb0 .equ SW_FLAG_4 = 0x70 .equ SEQ_LENGTH = 2 ; Value that stored in OCR0A for each tone ; 880Hz = 71 ; 785Hz = 80 ; 590Hz = 105 ; 440Hz = 142 .include "macros.asm" ; Include macros .dseg ; Data segment .org SRAM_START ; MCU Global states addresses CURRENT_STATE_ADDRESS: .byte 0x01 PREVIOUS_STATE_ADDRESS: .byte 0x01 ; Button flags SW_FLAGS_ADDRESS: .byte 0x01 .cseg ; Code segment .org 0x00 ; MCU vectors rjmp RESET_vect ; Program start at RESET vector reti ; External Interrupt Request 0 / inactive rjmp PCINT0_vect ; Pin Change Interrupt Request 0 / active reti ; Pin Change Interrupt Request 1 / inactive rjmp WDT_vect ; Watchdog Time-out / active reti ; Timer/Counter1 Capture Event / inactive reti ; Timer/Counter1 Compare Match A / inactive reti ; Timer/Counter1 Compare Match B / inactive reti ; Timer/Counter1 Overflow / inactive reti ; Timer/Counter0 Compare Match A / inactive reti ; Timer/Counter0 Compare Match B / inactive rjmp TIM0_OVF_vect ; Timer/Counter0 Overflow / active reti ; Analog Comparator / inactive reti ; ADC Conversion Complete / inactive reti ; EEPROM Ready / inactive reti ; USI START / inactive reti ; USI Overflow / inactive ; watchdog time-out interrupt handler WDT_vect: inc wdt_counter in temp_r_c, WDTCSR ori temp_r_c, (1<