⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 led.s

📁 一个关于AVR单片机的例程
💻 S
📖 第 1 页 / 共 3 页
字号:
;   temp2=data/10;
	movw R30,R28
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L28
	ldi R17,>L28
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall div32f
	movw R30,R28
	std z+0,R16
	std z+1,R17
	std z+2,R18
	std z+3,R19
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L59
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R24,R16
	subi R24,0  ; offset = 32768
	sbci R25,128
	movw R10,R24
	xjmp L60
L59:
	movw R30,R28
	ldd R16,z+0
	ldd R17,z+1
	ldd R18,z+2
	ldd R19,z+3
	xcall fp2int
	movw R10,R16
L60:
	movw R22,R10
	.dbline 212
;   temp=temp2%10;// 123.4/10%10=2
	ldi R18,10
	ldi R19,0
	movw R16,R22
	xcall mod16u
	mov R20,R16
	.dbline 213
;   display_one(2,temp);
	mov R18,R20
	ldi R16,2
	xcall _display_one
	.dbline 214
;   delay_ms(6);
	ldi R16,6
	ldi R17,0
	xcall _delay_ms
	.dbline 215
;   led_contrl_port &=~ (1<<2);
	cbi 0x18,2
	.dbline 217
;   
;   temp2=data;
	movw R30,R28
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L61
	movw R30,R28
	ldd R2,z+22
	ldd R3,z+23
	ldd R4,z+24
	ldd R5,z+25
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R24,R16
	subi R24,0  ; offset = 32768
	sbci R25,128
	movw R10,R24
	xjmp L62
L61:
	movw R30,R28
	ldd R16,z+22
	ldd R17,z+23
	ldd R18,z+24
	ldd R19,z+25
	xcall fp2int
	movw R10,R16
L62:
	movw R22,R10
	.dbline 218
;   temp=(temp2%10);// 123.4%10=3
	ldi R18,10
	ldi R19,0
	movw R16,R22
	xcall mod16u
	mov R20,R16
	.dbline 219
;   display_one(1,temp);
	mov R18,R20
	ldi R16,1
	xcall _display_one
	.dbline 220
;   led_port |= 0x80; //点亮对应小数点
	sbi 0x1b,7
	.dbline 221
;   delay_ms(6);
	ldi R16,6
	ldi R17,0
	xcall _delay_ms
	.dbline 222
;   led_contrl_port &=~ (1<<1);
	cbi 0x18,1
	.dbline 224
;   
;   temp2=(data*10);
	ldi R16,<L28
	ldi R17,>L28
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R30,R28
 ; stack offset 4
	ldd R2,z+26
	ldd R3,z+27
	ldd R4,z+28
	ldd R5,z+29
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall empy32f
	movw R30,R28
	std z+4,R16
	std z+5,R17
	std z+6,R18
	std z+7,R19
	movw R30,R28
	ldd R2,z+4
	ldd R3,z+5
	ldd R4,z+6
	ldd R5,z+7
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L63
	movw R30,R28
	ldd R2,z+4
	ldd R3,z+5
	ldd R4,z+6
	ldd R5,z+7
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R24,R16
	subi R24,0  ; offset = 32768
	sbci R25,128
	movw R10,R24
	xjmp L64
L63:
	movw R30,R28
	ldd R16,z+4
	ldd R17,z+5
	ldd R18,z+6
	ldd R19,z+7
	xcall fp2int
	movw R10,R16
L64:
	movw R22,R10
	.dbline 225
;   temp=temp2%10;// 123.4*10%10=4
	ldi R18,10
	ldi R19,0
	movw R16,R22
	xcall mod16u
	mov R20,R16
	.dbline 226
;   display_one(0,temp);
	mov R18,R20
	clr R16
	xcall _display_one
	.dbline 227
;   delay_ms(6);
	ldi R16,6
	ldi R17,0
	xcall _delay_ms
	.dbline 228
;   led_contrl_port &=~ (1<<0);
	cbi 0x18,0
	.dbline 229
;  }
	xjmp L56
L55:
	.dbline 230
;  else led_error();
	xcall _led_error
L56:
L46:
L36:
L24:
	.dbline -2
L16:
	adiw R28,16
	xcall pop_gset3
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym r temp2 22 i
	.dbsym r temp 20 c
	.dbsym l data 22 D
	.dbend
	.dbfunc e display_float2 _display_float2 fV
;           temp -> R20,R21
;           data -> y+8
	.even
_display_float2::
	xcall push_arg4
	xcall push_gset2
	sbiw R28,4
	.dbline -1
	.dbline 240
; }
; 
; /***********************************************
; ** 显示浮点数 本函数占用 mega16 的空间 9%,有一点闪烁感,可将display中的延时调小
; ** 思路二:直接显示整数,再显示点
; ** 注意:输入的data必须为小于1000的四位小数(0.234,1.23,12.45,224.8) 等
; ***********************************************/
; 
; void display_float2(float data)
; {
	.dbline 242
;  uint16 temp;
;  if(data>1000)
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R30,R28
 ; stack offset 4
	ldd R2,z+12
	ldd R3,z+13
	ldd R4,z+14
	ldd R5,z+15
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall cmp32f
	brlt X4
	xjmp L66
X4:
	.dbline 243
;  {
	.dbline 244
;  temp=data;
	movw R30,R28
	ldd R2,z+8
	ldd R3,z+9
	ldd R4,z+10
	ldd R5,z+11
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L68
	movw R30,R28
	ldd R2,z+8
	ldd R3,z+9
	ldd R4,z+10
	ldd R5,z+11
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R22,R16
	subi R22,0  ; offset = 32768
	sbci R23,128
	xjmp L69
L68:
	movw R30,R28
	ldd R16,z+8
	ldd R17,z+9
	ldd R18,z+10
	ldd R19,z+11
	xcall fp2int
	movw R22,R16
L69:
	movw R20,R22
	.dbline 245
;  display(temp,1);
	ldi R18,1
	movw R16,R20
	xcall _display
	.dbline 246
;   return;
	xjmp L65
L66:
	.dbline 248
;  }
;  if(data>100)   //比如123.4
	ldi R16,<L32
	ldi R17,>L32
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R30,R28
 ; stack offset 4
	ldd R2,z+12
	ldd R3,z+13
	ldd R4,z+14
	ldd R5,z+15
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall cmp32f
	brlt X5
	xjmp L70
X5:
	.dbline 249
;  {
	.dbline 250
;   temp=data*10;
	ldi R16,<L28
	ldi R17,>L28
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R30,R28
 ; stack offset 4
	ldd R2,z+12
	ldd R3,z+13
	ldd R4,z+14
	ldd R5,z+15
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall empy32f
	movw R30,R28
	std z+0,R16
	std z+1,R17
	std z+2,R18
	std z+3,R19
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L72
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R22,R16
	subi R22,0  ; offset = 32768
	sbci R23,128
	xjmp L73
L72:
	movw R30,R28
	ldd R16,z+0
	ldd R17,z+1
	ldd R18,z+2
	ldd R19,z+3
	xcall fp2int
	movw R22,R16
L73:
	movw R20,R22
	.dbline 251
;   display(temp,0); //普通模式显示 1234
	clr R18
	movw R16,R20
	xcall _display
	.dbline 252
;   led_contrl_port |= (1<<1); //选中第三位
	sbi 0x18,1
	.dbline 253
;   led_port = 0x80; //点亮对应小数点
	ldi R24,128
	out 0x1b,R24
	.dbline 254
;   delay_ms(6);
	ldi R16,6
	ldi R17,0
	xcall _delay_ms
	.dbline 255
;   led_contrl_port &=~ (1<<1);
	cbi 0x18,1
	.dbline 256
;   return;
	xjmp L65
L70:
	.dbline 258
;  }
;  if(data>10)   //比如12.34
	ldi R16,<L28
	ldi R17,>L28
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R30,R28
 ; stack offset 4
	ldd R2,z+12
	ldd R3,z+13
	ldd R4,z+14
	ldd R5,z+15
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall cmp32f
	brlt X6
	xjmp L74
X6:
	.dbline 259
;  {
	.dbline 260
;   temp=data*100;
	ldi R16,<L32
	ldi R17,>L32
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R30,R28
 ; stack offset 4
	ldd R2,z+12
	ldd R3,z+13
	ldd R4,z+14
	ldd R5,z+15
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall empy32f
	movw R30,R28
	std z+0,R16
	std z+1,R17
	std z+2,R18
	std z+3,R19
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L76
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R22,R16
	subi R22,0  ; offset = 32768
	sbci R23,128
	xjmp L77
L76:
	movw R30,R28
	ldd R16,z+0
	ldd R17,z+1
	ldd R18,z+2
	ldd R19,z+3
	xcall fp2int
	movw R22,R16
L77:
	movw R20,R22
	.dbline 261
;   display(temp,0); //普通模式显示 1234
	clr R18
	movw R16,R20
	xcall _display
	.dbline 262
;   led_contrl_port |= (1<<2); //选中第二位
	sbi 0x18,2
	.dbline 263
;   led_port = 0x80; //点亮对应小数点
	ldi R24,128
	out 0x1b,R24
	.dbline 264
;   delay_ms(6);
	ldi R16,6
	ldi R17,0
	xcall _delay_ms
	.dbline 265
;   led_contrl_port &=~ (1<<2);
	cbi 0x18,2
	.dbline 266
;   return;
	xjmp L65
L74:
	.dbline 268
;  }
;  if(data>1)   //比如1.234
	ldi R16,<L25
	ldi R17,>L25
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R30,R28
 ; stack offset 4
	ldd R2,z+12
	ldd R3,z+13
	ldd R4,z+14
	ldd R5,z+15
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall cmp32f
	brlt X7
	xjmp L78
X7:
	.dbline 269
;  {
	.dbline 270
;   temp=data*1000;
	ldi R16,<L19
	ldi R17,>L19
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R30,R28
 ; stack offset 4
	ldd R2,z+12
	ldd R3,z+13
	ldd R4,z+14
	ldd R5,z+15
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	xcall empy32f
	movw R30,R28
	std z+0,R16
	std z+1,R17
	std z+2,R18
	std z+3,R19
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L80
	movw R30,R28
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	ldi R16,<L29
	ldi R17,>L29
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall sub32f
	xcall fp2int
	movw R22,R16
	subi R22,0  ; offset = 32768
	sbci R23,128
	xjmp L81
L80:
	movw R30,R28
	ldd R16,z+0
	ldd R17,z+1
	ldd R18,z+2
	ldd R19,z+3
	xcall fp2int
	movw R22,R16
L81:
	movw R20,R22
	.dbline 271
	clr R18
	movw R16,R20
	xcall _display
	.dbline 272
	sbi 0x18,3
	.dbline 273
	ldi R24,128
	out 0x1b,R24
	.dbline 274
	ldi R16,6
	ldi R17,0
	xcall _delay_ms
	.dbline 275
	cbi 0x18,3
	.dbline 276
L78:
	.dbline -2
L65:
	adiw R28,4
	xcall pop_gset2
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 i
	.dbsym l data 8 D
	.dbend
	.dbfunc e led_error _led_error fV
	.even
_led_error::
	.dbline -1
	.dbline 284
;   display(temp,0); //普通模式显示 1234
;   led_contrl_port |= (1<<3); //选中第一位
;   led_port = 0x80; //点亮对应小数点,这里用等于,否则display函数的显影有残留。
;   delay_ms(6);
;   led_contrl_port &=~ (1<<3);
;   return;
;  }
; }
; 
; /***********************************************
; ** 异常处理,led全亮 8。8。8。8。
; ***********************************************/
; void led_error(void)
; {
	.dbline 286
;  // 以下两句将会使LED全亮,如果立即更改状态,将看不出来效果
;   led_port = 0xFF;
	ldi R24,255
	out 0x1b,R24
	.dbline 287
;   led_contrl_port |= (1<<led_a)|(1<<led_b)|(1<<led_c)|(1<<led_d);
	in R24,0x18
	ori R24,15
	out 0x18,R24
	.dbline -2
L82:
	.dbline 0 ; func end
	ret
	.dbend
	.area lit(rom, con, rel)
L32:
	.word 0x0,0x42c8
L29:
	.word 0x0,0x4700
L28:
	.word 0x0,0x4120
L25:
	.word 0x0,0x3f80
L22:
	.word 0x0,0x0
L19:
	.word 0x0,0x447a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -