📄 练习闪烁.s
字号:
.module _练习闪烁.c
.area data(ram, con, rel)
_porta_temp::
.blkb 1
.area idata
.byte 1
.area data(ram, con, rel)
.area text(rom, con, rel)
; i -> R16,R17
.even
_delay_1ms::
; #include <iom128v.h>
; unsigned char porta_temp=0x01;
; void delay_1ms(void)
; {
clr R16
clr R17
xjmp L5
L2:
L3:
subi R16,255 ; offset = 1
sbci R17,255
L5:
; unsigned int i;
; for (i=0;i<556;i++);
cpi R16,44
ldi R30,2
cpc R17,R30
brlo L2
L1:
.dbline 0 ; func end
ret
; i -> R20,R21
; n -> R22,R23
.even
_delay_nms::
xcall push_gset2
movw R22,R16
; }
; void delay_nms(unsigned int n)
; {unsigned int i=0;
clr R20
clr R21
; for (i=0;i<n;i++)
xjmp L10
L7:
xcall _delay_1ms
L8:
subi R20,255 ; offset = 1
sbci R21,255
L10:
cp R20,R22
cpc R21,R23
brlo L7
L6:
xcall pop_gset2
.dbline 0 ; func end
ret
; i -> R20,R21
.even
_LED_On::
xcall push_gset1
movw R20,R16
; delay_1ms();
; }
; void LED_On(int i)
; {
; PORTB=~(1<<i);
ldi R16,1
ldi R17,0
movw R18,R20
xcall lsl16
movw R2,R16
com R2
com R3
out 0x18,R2
; delay_nms(50);}
ldi R16,50
ldi R17,0
xcall _delay_nms
L11:
xcall pop_gset1
.dbline 0 ; func end
ret
; i -> R20,R21
.even
_main::
;
; void main()
; {unsigned int i;
; DDRA = 0x00; DDRB = 0xFF; /*定义输入输出*/
clr R2
out 0x1a,R2
ldi R24,255
out 0x17,R24
; PORTA= 0xFF;PORTB= 0xFF;
out 0x1b,R24
out 0x18,R24
xjmp L14
L13:
; while(1)
; {PORTB=0XFF;
ldi R24,255
out 0x18,R24
xjmp L17
L16:
; while((PINA & 0x01) == 0)
; {
; for(i=0;(PINA & 0X01) == 0;i++)
clr R20
clr R21
xjmp L22
L19:
in R2,0x18
com R2
out 0x18,R2
ldi R16,50
ldi R17,0
xcall _delay_nms
L20:
subi R20,255 ; offset = 1
sbci R21,255
L22:
in R24,0x19
andi R24,1
breq L19
L17:
in R24,0x19
andi R24,1
breq L16
xjmp L24
L23:
; {PORTB=~PORTB;
; delay_nms(50);}
; }
; while((PINA & 0x02) == 0) //判断PA0口的状态
; {
; PORTB = ~porta_temp;
lds R2,_porta_temp
com R2
out 0x18,R2
; delay_nms(50);
ldi R16,50
ldi R17,0
xcall _delay_nms
; porta_temp=porta_temp>>1;
lds R2,_porta_temp
lsr R2
sts _porta_temp,R2
; if(porta_temp == 0) //右移到为0时重新赋值
tst R2
brne L26
; {porta_temp=0x80;}
ldi R24,128
sts _porta_temp,R24
L26:
L24:
in R24,0x19
andi R24,2
breq L23
xjmp L29
L28:
; }
; while((PINA & 0x04) ==0)
; { PORTB = ~porta_temp;
lds R2,_porta_temp
com R2
out 0x18,R2
; delay_nms(50);
ldi R16,50
ldi R17,0
xcall _delay_nms
; porta_temp=porta_temp<<1;
lds R2,_porta_temp
lsl R2
sts _porta_temp,R2
; if(porta_temp == 0)
tst R2
brne L31
; { porta_temp=0x01;}
ldi R24,1
sts _porta_temp,R24
L31:
L29:
in R24,0x19
andi R24,4
breq L28
L14:
xjmp L13
X0:
L12:
.dbline 0 ; func end
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -