feat: first impl of btn handling

This commit is contained in:
Sergey Yarkov 2021-10-03 01:56:32 +03:00
parent b57e406522
commit 8009d0c44e
2 changed files with 100 additions and 49 deletions

View File

@ -16,7 +16,8 @@
; ;
; LEDS constants ; LEDS constants
.equ LED_DIR = DDRA .equ LED_DIR = DDRA
.equ LED_PORT = PORTA .equ LED_PORT = PORTA
.equ LED_PIN = PINA
.equ LED_PIN_0 = PINA0 .equ LED_PIN_0 = PINA0
.equ LED_PIN_1 = PINA1 .equ LED_PIN_1 = PINA1
.equ LED_PIN_2 = PINA2 .equ LED_PIN_2 = PINA2
@ -24,12 +25,13 @@
; ;
; Buttons constants ; Buttons constants
.equ BTN_DIR = DDRA .equ SW_DIR = DDRA
.equ BTN_PORT = PORTA .equ SW_PORT = PORTA
.equ BTN_PIN_4 = PINA4 .equ SW_PIN = PINA
.equ BTN_PIN_5 = PINA5 .equ SW_PIN_4 = PINA4
.equ BTN_PIN_6 = PINA6 .equ SW_PIN_5 = PINA5
.equ BTN_PIN_7 = PINA7 .equ SW_PIN_6 = PINA6
.equ SW_PIN_7 = PINA7
; ;
; Buzzer constants ; Buzzer constants
@ -78,10 +80,10 @@
pop r16 pop r16
.endm .endm
.macro set_btn_flag .macro set_sw_flag
push r16 push r16
ldi r16, @0 ldi r16, @0
sts BTN_FLAGS_ADDRESS, r16 sts SW_FLAGS_ADDRESS, r16
pop r16 pop r16
.endm .endm
@ -95,7 +97,7 @@ PREVIOUS_STATE_ADDRESS: .byte 0x01
; ;
; Button flags ; Button flags
BTN_FLAGS_ADDRESS: .byte 0x01 SW_FLAGS_ADDRESS: .byte 0x01
.cseg ; Code segment .cseg ; Code segment
.org 0x00 ; Start program at 0x00 .org 0x00 ; Start program at 0x00
@ -104,7 +106,7 @@ BTN_FLAGS_ADDRESS: .byte 0x01
; Setup vectors ; Setup vectors
rjmp start ; Program start at RESET vector rjmp start ; Program start at RESET vector
reti ; External Interrupt Request 0 reti ; External Interrupt Request 0
rjmp PCINT0_ISR ; Pin Change Interrupt Request 0 / active rjmp PCINT0_vect ; Pin Change Interrupt Request 0 / active
reti ; Pin Change Interrupt Request 1 / inactive reti ; Pin Change Interrupt Request 1 / inactive
reti ; Watchdog Time-out / inactive reti ; Watchdog Time-out / inactive
reti ; Timer/Counter1 Capture Event / inactive reti ; Timer/Counter1 Capture Event / inactive
@ -122,12 +124,45 @@ reti ; USI Overflow / inactive
; ;
; Interrupt service routines ; Interrupt service routines
PCINT0_ISR: ; Button handlers there PCINT0_vect:
set_btn_flag 0x01 push r17
reti
ldi r18, 0x00 sbis PINA, PINA4
sts BTN_FLAGS_ADDRESS, r18 rjmp sw_check_1
sbic PINA, PINA4
rjmp sw_2nd
sw_2nd:
sbis PINA, PINA5
rjmp sw_check_2
sbic PINA, PINA5
rjmp sw_clr
rjmp PCINT0_vect_end
sw_1:
; lds r17, SW_FLAGS_ADDRESS
; cpi r17, 0x01
; breq sw_clr
sw_check_1:
set_sw_flag 0x01
rjmp PCINT0_vect_end
sw_check_2:
set_sw_flag 0x02
rjmp PCINT0_vect_end
; sw_check_flag:
; lds r16, SW_FLAGS_ADDRESS
; sbis PINA, PINA4
; ldi r16, 0x01
; sw_flag_1:
; cpi r16, 0x01
; brne sw_flag_not_found
; sts SW_FLAGS_ADDRESS, r16
; sw_flag_not_found:
sw_clr:
set_sw_flag 0x00
PCINT0_vect_end:
pop r17
reti
; ;
; Program start at reset ; Program start at reset
@ -146,16 +181,27 @@ loop: ; Program loop
showing: ; Showing state showing: ; Showing state
cpi r16, SHOWING_STATE cpi r16, SHOWING_STATE
brne polling brne polling
lds r18, BTN_FLAGS_ADDRESS led_1:
cpi r18, 0x01 lds r18, SW_FLAGS_ADDRESS
brne led_off cpi r18, 0x01
led_on: brne led_off_1
sbi LED_PORT, 2 led_on_1:
rcall delay_50ms sbi LED_PORT, 0
rjmp polling rcall delay_50ms
led_off: rjmp led_2
cbi LED_PORT, 2 led_off_1:
cbi LED_PORT, 0
led_2:
lds r18, SW_FLAGS_ADDRESS
cpi r18, 0x02
brne led_off_2
led_on_2:
sbi LED_PORT, 1
rcall delay_50ms
rjmp polling
led_off_2:
cbi LED_PORT, 1
polling: ; Polling state polling: ; Polling state
cpi r16, POLLING_STATE cpi r16, POLLING_STATE
brne completion brne completion
@ -232,8 +278,9 @@ init_interrupts:
; ;
; Set Pin Change Mask Register ; Set Pin Change Mask Register
ldi r16, (1<<PCINT4) | (1<<PCINT5)| (1<<PCINT6)| (1<<PCINT7) ldi r16, (1<<PCINT4) | (1<<PCINT5)| (1<<PCINT6) | (1<<PCINT7)
out PCMSK0, r16 out PCMSK0, r16
clr r16 clr r16
sei ; Enable Global Interrupts sei ; Enable Global Interrupts

View File

@ -1,25 +1,29 @@
:020000020000FC :020000020000FC
:1000000019C018950EC0189518951895189518953B :100000002DC018950EC01895189518951895189527
:100010001895189518951895189518951895189578 :100010001895189518951895189518951895189578
:1000200018950F9301E0009362000F91189520E05E :1000200018951F93CC9B07C0CC9900C0CD9B09C0ED
:10003000209362000FED0DBF0F93009160000093BD :10003000CD990DC011C00F9301E0009362000F91A4
:1000400061000F9301E0009360000F910F91009108 :100040000BC00F9302E0009362000F9105C00F9365
:100050006000013061F441D00F9300916000009383 :1000500000E0009362000F911F9118950FED0DBF06
:1000600061000F9302E0009360000F910F91023046 :100060000F9300916000009361000F9301E00093F3
:1000700041F420916200213019F4DA9A46D001C08F :1000700060000F910F9100916000013061F449D050
:10008000DA98033001F4043001F4E1CF1F932F9389 :100080000F9300916000009361000F9302E00093D2
:100090003F934F934BB30F9301EF0BBB0F9135D0B1 :1000900060000F910F91023081F4209162002130B5
:1000A00011E033E020EF110F210F2BBB2ED03A953A :1000A00019F4D89A4ED001C0D8982091620022301D
:1000B000C9F70F9308EF0BBB0F9127D018E033E07F :1000B00019F4D99A46D001C0D998033001F404301C
:1000C00020EF1695210F2BBB20D03A95C9F74BBBDB :1000C00001F4D9CF1F932F933F934F934BB30F93CB
:1000D0004F913F912F911F91089510D008D001D0DA :1000D00001EF0BBB0F9135D011E033E020EF110F92
:1000E000089516E0D3DF1A95E9F71BD0089500E1D3 :1000E000210F2BBB2ED03A95C9F70F9308EF0BBB0E
:1000F0000BBF00EF02BB0027789408950FE00ABB06 :1000F0000F9127D018E033E020EF1695210F2BBB8E
:1001000002950BBBBA9AC29808952F933F9321E4AE :1001000020D03A95C9F74BBB4F913F912F911F914A
:100110003FEE3A95F1F72A95E1F700003F912F91D4 :10011000089510D008D001D0089516E0D3DF1A95C5
:1001200008958F939F9324E683EC99E00197F1F76C :10012000E9F71BD0089500E10BBF00EF02BB0027E9
:100130002A95D1F724E69F918F9108954D656D6FB3 :10013000789408950FE00ABB02950BBBBA9AC29857
:100140007279206C65642067616D652E2057726935 :1001400008952F933F9321E43FEE3A95F1F72A95D6
:100150007474656E206279205365726765792059E1 :10015000E1F700003F912F9108958F939F9324E63C
:1001600061726B6F762032372E30392E3230323159 :1001600083EC99E00197F1F72A95D1F724E69F9166
:100170008F9108954D656D6F7279206C656420676D
:10018000616D652E205772697474656E20627920E6
:10019000536572676579205961726B6F76203237CB
:0801A0002E30392E32303231CD
:00000001FF :00000001FF