refactor: blink

This commit is contained in:
Sergey Yarkov 2021-09-25 00:24:49 +03:00
parent 6e07f71337
commit 2d18dcd014
2 changed files with 28 additions and 8 deletions

View File

@ -20,8 +20,7 @@
.equ LED_PORT = PORTA ; LED Port .equ LED_PORT = PORTA ; LED Port
.equ LED_PIN = PINA0 ; LED Pin .equ LED_PIN = PINA0 ; LED Pin
.equ oVal = 70 .equ iVal = 65000
.equ iVal = 1000
.org 0x00 ; Start program at 0x00 .org 0x00 ; Start program at 0x00
.cseg ; Code segment .cseg ; Code segment
@ -29,9 +28,7 @@
main: ; Start up program main: ; Start up program
init_stack_p r16, RAMEND init_stack_p r16, RAMEND
rcall init_ports ; Initialize MCU ports rcall init_ports ; Initialize MCU ports
ldi r18, oVal rcall delay_loop_reset
ldi r24, low(iVal)
ldi r25, high(iVal)
loop: ; Program loop loop: ; Program loop
cbi LED_PORT, LED_PIN cbi LED_PORT, LED_PIN
@ -48,7 +45,28 @@ init_ports: ; Init MCU ports
out LED_PORT, r17 out LED_PORT, r17
ret ret
delay_loop_reset: ; Load value to registar pair again
ldi r24, low(iVal)
ldi r25, high(iVal)
ret
delay_loop: delay_loop:
sbiw r24, 1 sbiw r24, 1
brne delay_loop brne delay_loop
nop
rcall delay_loop_reset
rcall delay_loop_2
ret
delay_loop_2:
sbiw r24, 1
brne delay_loop_2
rcall delay_loop_reset
rcall delay_loop_3
ret
delay_loop_3:
sbiw r24, 1
brne delay_loop_3
rcall delay_loop_reset
ret ret

View File

@ -1,5 +1,7 @@
:020000020000FC :020000020000FC
:100000000FED0DBF08D026E488EE93E0D89809D014 :100000000FED0DBF06D00BD0D8980CD0D89A0AD0DF
:10001000D89A07D0FBCF01E010E000000ABB1BBB61 :10001000FBCF01E010E000000ABB1BBB089588EE97
:0800200008950197F1F708951E :100020009DEF08950197F1F70000F9DF01D00895E1
:100030000197F1F7F4DF01D008950197F1F7EFDFB1
:02004000089521
:00000001FF :00000001FF