📄 led.s
字号:
.module led.c
.area text(rom, con, rel)
.dbfile D:\AVR单片机学习资料\LED来回循环闪烁\led.c
.dbfunc e Delay _Delay fV
; a -> R16,R17
; b -> R18,R19
.even
_Delay::
.dbline -1
.dbline 6
; #include <iom8v.h>
; #include <macros.h>
;
; /* This seems to produce the right amount of delay for the LED to be seen */
; void Delay()
; {
.dbline 9
; unsigned int a, b;
;
; for (a = 1; a<25; a++)
ldi R16,1
ldi R17,0
rjmp L5
L2:
.dbline 10
; {
.dbline 11
; for (b = 1; b<2000; b++);
ldi R18,1
ldi R19,0
rjmp L9
L6:
.dbline 11
L7:
.dbline 11
subi R18,255 ; offset = 1
sbci R19,255
L9:
.dbline 11
cpi R18,208
ldi R30,7
cpc R19,R30
brlo L6
X0:
.dbline 12
; }
L3:
.dbline 9
subi R16,255 ; offset = 1
sbci R17,255
L5:
.dbline 9
cpi R16,25
ldi R30,0
cpc R17,R30
brlo L2
X1:
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r a 16 i
.dbsym r b 18 i
.dbend
.dbfunc e LED_PORTBOn _LED_PORTBOn fV
; i -> R10,R11
.even
_LED_PORTBOn::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 16
; }
;
; void LED_PORTBOn(int i)
; {
.dbline 17
; PORTB = ~BIT(i); /* low output to turn BLED on */
ldi R16,1
ldi R17,0
movw R18,R10
rcall lsl16
movw R2,R16
com R2
com R3
out 0x18,R2
.dbline 18
; Delay();
rcall _Delay
.dbline -2
L10:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r i 10 I
.dbend
.dbfunc e LED_PORTDOn _LED_PORTDOn fV
; j -> R10,R11
.even
_LED_PORTDOn::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 21
; }
; void LED_PORTDOn(int j)
; {
.dbline 22
; PORTD = ~BIT(j);/* low output to turn DLED on */
ldi R16,1
ldi R17,0
movw R18,R10
rcall lsl16
movw R2,R16
com R2
com R3
out 0x12,R2
.dbline 23
; Delay();
rcall _Delay
.dbline -2
L11:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r j 10 I
.dbend
.dbfunc e LED_PORTBOff _LED_PORTBOff fV
; i -> R10,R11
.even
_LED_PORTBOff::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 26
; }
; void LED_PORTBOff(int i)
; {
.dbline 27
; PORTB = ~BIT(i); /* hight output to turn BLED off */
ldi R16,1
ldi R17,0
movw R18,R10
rcall lsl16
movw R2,R16
com R2
com R3
out 0x18,R2
.dbline -2
L12:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r i 10 I
.dbend
.dbfunc e LED_PORTDOff _LED_PORTDOff fV
; j -> R10,R11
.even
_LED_PORTDOff::
st -y,R10
st -y,R11
movw R10,R16
.dbline -1
.dbline 30
; }
; void LED_PORTDOff(int j)
; {
.dbline 31
; PORTD = ~BIT(j);/* hight output to turn DLED off */
ldi R16,1
ldi R17,0
movw R18,R10
rcall lsl16
movw R2,R16
com R2
com R3
out 0x12,R2
.dbline -2
L13:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r j 10 I
.dbend
.dbfunc e main _main fV
; j -> R22,R23
; i -> R20,R21
.even
_main::
.dbline -1
.dbline 34
; }
; void main()
; {
.dbline 36
; int i,j;
; DDRB = 0xFF; /* output */
ldi R24,255
out 0x17,R24
.dbline 37
; PORTB = 0xFF; /* all off */
out 0x18,R24
.dbline 38
; DDRD=0xFF;/*D output*/
out 0x11,R24
.dbline 39
; PORTD=0xFF;/*all off*/
out 0x12,R24
rjmp L16
L15:
.dbline 42
;
; while (1)
; {
.dbline 43
; for (i = 0; i < 3; i++)
clr R20
clr R21
L18:
.dbline 44
; LED_PORTBOn(i);
movw R16,R20
rcall _LED_PORTBOn
L19:
.dbline 43
subi R20,255 ; offset = 1
sbci R21,255
.dbline 43
cpi R20,3
ldi R30,0
cpc R21,R30
brlt L18
X2:
.dbline 45
; LED_PORTBOff(i);
movw R16,R20
rcall _LED_PORTBOff
.dbline 46
; for (j = 5; j < 8; j++)
ldi R22,5
ldi R23,0
L22:
.dbline 47
; LED_PORTDOn(j);
movw R16,R22
rcall _LED_PORTDOn
L23:
.dbline 46
subi R22,255 ; offset = 1
sbci R23,255
.dbline 46
cpi R22,8
ldi R30,0
cpc R23,R30
brlt L22
X3:
.dbline 48
; for(j = 7;j >4; j--)
ldi R22,7
ldi R23,0
L26:
.dbline 49
; LED_PORTDOn(j);
movw R16,R22
rcall _LED_PORTDOn
L27:
.dbline 48
subi R22,1
sbci R23,0
.dbline 48
ldi R24,4
ldi R25,0
cp R24,R22
cpc R25,R23
brlt L26
X4:
.dbline 50
; LED_PORTDOff(j);
movw R16,R22
rcall _LED_PORTDOff
.dbline 51
; for (i = 2; i >=0; i--)
ldi R20,2
ldi R21,0
L30:
.dbline 52
; LED_PORTBOn(i);
movw R16,R20
rcall _LED_PORTBOn
L31:
.dbline 51
subi R20,1
sbci R21,0
.dbline 51
cpi R20,0
ldi R30,0
cpc R21,R30
brge L30
X5:
.dbline 53
; }
L16:
.dbline 41
rjmp L15
X6:
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbsym r j 22 I
.dbsym r i 20 I
.dbend
; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -