-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssembly_Blink_LED.S
More file actions
39 lines (39 loc) · 1.59 KB
/
Assembly_Blink_LED.S
File metadata and controls
39 lines (39 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;------------------------
; Assembly Code
;------------------------
#define __SFR_OFFSET 0x00
#include "avr/io.h"
;------------------------
.global start
.global led
;------------------------
start:
SBI DDRB,4 ;set PB5 (D12) as o/p
RET ;return to setup() function
;----------------------------------------------------------------------
led:
CPI R24, 0x00 ;value passed by caller in R24 compared with 0
BREQ ledOFF ;jump (branch) if equal to subroutine ledOFF
SBI PORTB, 4 ;set D12 to high
RET ;return to loop() function
;----------------------------------------------------------------------
ledOFF:
CBI PORTB, 4 ;set D12 to low
RCALL myDelay
RET ;return to loop() function
;---------------------------------------------------------------------------
.equ delayVal, 10000 ;initial count value for inner loop
;---------------------------------------------------------------------------
myDelay:
LDI R20, 100 ;initial count value for outer loop
outerLoop:
LDI R30, lo8(delayVal) ;low byte of delayVal in R30
LDI R31, hi8(delayVal) ;high byte of delayVal in R31
innerLoop:
SBIW R30, 1 ;subtract 1 from 16-bit value in R31, R30
BRNE innerLoop ;jump if countVal not equal to 0
;--------------
SUBI R20, 1 ;subtract 1 from R20
BRNE outerLoop ;jump if R20 not equal to 0
RET
;---------------------------------------------------------------------------