📄 main.s
字号:
std z+1,R17
std z+0,R16
.dbline 217
ldi R16,2
ldi R17,0
xcall _Delay_nms
.dbline 218
L29:
.dbline 214
inc R22
L31:
.dbline 214
cpi R22,10
brlo L28
.dbline 219
clr R22
xjmp L35
L32:
.dbline 219
ldi R24,2
mul R24,R22
movw R30,R0
movw R24,R28
add R30,R24
adc R31,R25
ldd R2,z+0
ldd R3,z+1
add R20,R2
adc R21,R3
L33:
.dbline 219
inc R22
L35:
.dbline 219
; {
; array[i]=ADC_Convert();
; Delay_nms(2);
; }
; for(i=0;i<10;i++)avx=avx+array[i];
cpi R22,10
brlo L32
.dbline 220
; avx=avx/10;
ldi R18,10
ldi R19,0
movw R16,R20
xcall div16u
movw R20,R16
.dbline 221
; return avx;
.dbline -2
L27:
adiw R28,20
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l array 0 A[20:10]i
.dbsym r avx 20 i
.dbsym r i 22 c
.dbend
.dbfunc e main _main fV
.area func_lit(rom, con, rel)
L183:
.word `L43
.word `L44
.word `L45
.word `L46
.word `L47
.word `L50
.word `L52
.word `L69
.word `L70
.word `L73
.word `L75
.word `L87
.word `L88
.word `L91
.word `L93
.word `L96
.word `L98
.word `L110
.word `L111
.word `L114
.word `L116
.word `L119
.word `L121
.word `L133
.word `L146
.word `L147
.word `L148
.word `L161
.area text(rom, con, rel)
.dbfile D:\ac18-1\main.c
; f -> y+2
; temp -> R10,R11
; i -> R20
.even
_main::
sbiw R28,6
.dbline -1
.dbline 225
; }
; /**********************主函数*****************************/
; void main(void)
; { uint temp;float f;uchar i;
.dbline 226
; Delay_nms(400);
ldi R16,400
ldi R17,1
xcall _Delay_nms
.dbline 227
; init_devices();
xcall _init_devices
.dbline 228
; InitLcd();
xcall _InitLcd
.dbline 229
; welcome();
xcall _welcome
.dbline 230
; LCM_BLCON_ON;
cbi 0x12,4
.dbline 231
; Delay_nms(3000);
ldi R16,3000
ldi R17,11
xcall _Delay_nms
.dbline 232
; LCM_BLCON_OFF;
sbi 0x12,4
xjmp L38
L37:
.dbline 235
; /********************************************/
; while(1) //无限循环
; {
.dbline 236
; switch(status)
lds R22,_status
clr R23
cpi R22,0
ldi R30,0
cpc R23,R30
brge X2
xjmp L41
X2:
ldi R24,27
ldi R25,0
cp R24,R22
cpc R25,R23
brge X3
xjmp L41
X3:
ldi R16,2
ldi R17,0
movw R18,R22
xcall empy16s
movw R30,R16
ldi R24,<L183
ldi R25,>L183
add R30,R24
adc R31,R25
lpm R0,Z+
lpm R1,Z
movw R30,R0
ijmp
X0:
.dbline 237
; {
L43:
.dbline 238
; case 0:scan_key();WDR();//等待按启动键
xcall _scan_key
.dbline 238
wdr
.dbline 239
; break;
xjmp L41
L44:
.dbline 240
; case 1:LcdWriteCommand(0x01,1);//清屏
ldi R18,1
ldi R16,1
xcall _LcdWriteCommand
.dbline 241
; LcdWriteCommand(0x0c,1);//开显示
ldi R18,1
ldi R16,12
xcall _LcdWriteCommand
.dbline 242
; test_display();//显示测试界面
xcall _test_display
.dbline 243
; status=2;
ldi R24,2
sts _status,R24
.dbline 244
; break;
xjmp L41
L45:
.dbline 246
;
; case 2:AIR_ON;Delay_nms(2000);status=3;//启动气缸并等待2S进入刹车
cbi 0x12,3
.dbline 246
ldi R16,2000
ldi R17,7
xcall _Delay_nms
.dbline 246
ldi R24,3
sts _status,R24
.dbline 247
; break;
xjmp L41
L46:
.dbline 249
;
; case 3:SPEED_5V;Delay_nms(100);POW_27V;//转换成27V,RPM
cbi 0x12,0
.dbline 249
ldi R16,100
ldi R17,0
xcall _Delay_nms
.dbline 249
cbi 0x12,2
.dbline 250
; Delay_nms(100);POW_ON;status=4;//开电源
ldi R16,100
ldi R17,0
xcall _Delay_nms
.dbline 250
cbi 0x12,1
.dbline 250
ldi R24,4
sts _status,R24
.dbline 251
; break;
xjmp L41
L47:
.dbline 253
;
; case 4:Wait2S_Start_Flag=1;cnt=0;status=5;//启动2S定时
ldi R24,1
sts _Wait2S_Start_Flag,R24
.dbline 253
clr R2
clr R3
sts _cnt+1,R3
sts _cnt,R2
.dbline 253
ldi R24,5
sts _status,R24
.dbline 254
; break;
xjmp L41
L49:
.dbline 256
ldi R16,10
ldi R17,0
xcall _Delay_nms
L50:
.dbline 256
;
; case 5:while(Wait2S_End_Flag==0)Delay_nms(10);Wait2S_End_Flag=0;status=6;//等待2S定时结束
lds R2,_Wait2S_End_Flag
tst R2
breq L49
.dbline 256
clr R2
sts _Wait2S_End_Flag,R2
.dbline 256
ldi R24,6
sts _status,R24
.dbline 257
; break;
xjmp L41
L52:
.dbline 259
;
; case 6:current=average();status=7;//取样堵转电流
xcall _average
sts _current+1,R17
sts _current,R16
.dbline 259
ldi R24,7
sts _status,R24
.dbline 260
; current=current-14;
movw R24,R16
sbiw R24,14
sts _current+1,R25
sts _current,R24
.dbline 261
; f=(float)current;f=(f*2560)/1024;
ldi R16,<L53
ldi R17,>L53
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
lds R16,_current
lds R17,_current+1
lsr R17
ror R16
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall empy32fs
lds R16,_current
lds R17,_current+1
andi R16,1
andi R17,0
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall add32f
movw R30,R28
std z+2,R16
std z+3,R17
std z+4,R18
std z+5,R19
.dbline 261
ldi R16,<L54
ldi R17,>L54
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R30,R28
; stack offset 4
ldd R2,z+6
ldd R3,z+7
ldd R4,z+8
ldd R5,z+9
st -y,R5
st -y,R4
st -y,R3
st -y,R2
xcall empy32fs
ldi R16,<L55
ldi R17,>L55
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall div32f
movw R30,R28
std z+2,R16
std z+3,R17
std z+4,R18
std z+5,R19
.dbline 262
; f=f*4.25;//修正
ldi R16,<L56
ldi R17,>L56
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R30,R28
; stack offset 4
ldd R2,z+6
ldd R3,z+7
ldd R4,z+8
ldd R5,z+9
st -y,R5
st -y,R4
st -y,R3
st -y,R2
xcall empy32f
movw R30,R28
std z+2,R16
std z+3,R17
std z+4,R18
std z+5,R19
.dbline 263
; LLC=f;//暂存堵转电流
movw R30,R28
ldd R2,z+2
ldd R3,z+3
ldd R4,z+4
ldd R5,z+5
sts _LLC+1,R3
sts _LLC,R2
sts _LLC+2+1,R5
sts _LLC+2,R4
.dbline 264
; if(LLC<480)OutFlag++;//判断堵转电流大小
st -y,R5
st -y,R4
st -y,R3
st -y,R2
ldi R16,<L59
ldi R17,>L59
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall cmp32f
brge L57
.dbline 264
lds R24,_OutFlag
subi R24,255 ; addi 1
sts _OutFlag,R24
L57:
.dbline 265
; current=(uint)f;
movw R30,R28
ldd R2,z+2
ldd R3,z+3
ldd R4,z+4
ldd R5,z+5
st -y,R5
st -y,R4
st -y,R3
st -y,R2
ldi R16,<L62
ldi R17,>L62
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall cmp32f
brlt L60
movw R30,R28
ldd R2,z+2
ldd R3,z+3
ldd R4,z+4
ldd R5,z+5
st -y,R5
st -y,R4
st -y,R3
st -y,R2
ldi R16,<L62
ldi R17,>L62
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall sub32f
xcall fp2int
movw R20,R16
subi R20,0 ; offset = 32768
sbci R21,128
xjmp L61
L60:
movw R30,R28
ldd R16,z+2
ldd R17,z+3
ldd R18,z+4
ldd R19,z+5
xcall fp2int
movw R20,R16
L61:
sts _current+1,R21
sts _current,R20
.dbline 267
;
; temp=current;temp=temp/1000;LC[3]=(uchar)temp;
movw R10,R20
.dbline 267
ldi R18,1000
ldi R19,3
movw R16,R10
xcall div16u
movw R10,R16
.dbline 267
sts _LC+3,R10
.dbline 268
; temp=current;temp=(temp/100)%10;LC[2]=(uchar)temp;
lds R10,_current
lds R11,_current+1
.dbline 268
ldi R18,100
ldi R19,0
movw R16,R10
xcall div16u
ldi R18,10
ldi R19,0
xcall mod16u
movw R10,R16
.dbline 268
sts _LC+2,R10
.dbline 269
; temp=current;temp=(temp/10)%10;LC[1]=(uchar)temp;
lds R10,_current
lds R11,_current+1
.dbline 269
ldi R18,10
ldi R19,0
movw R16,R10
xcall div16u
ldi R18,10
ldi R19,0
xcall mod16u
movw R10,R16
.dbline 269
sts _LC+1,R10
.dbline 270
; temp=current;temp=temp%10;LC[0]=(uchar)temp;
lds R10,_current
lds R11,_current+1
.dbline 270
ldi R18,10
ldi R19,0
movw R16,R10
xcall mod16u
movw R10,R16
.dbline 270
sts _LC,R10
.dbline 271
; DisplayOneChar(3,3,LC[3]+0x30);
lds R24,_LC+3
subi R24,208 ; addi 48
std y+0,R24
ldi R18,3
ldi R16,3
xcall _DisplayOneChar
.dbline 272
; DisplayOneChar(4,3,0x2e);
ldi R24,46
std y+0,R24
ldi R18,3
ldi R16,4
xcall _DisplayOneChar
.dbline 273
; DisplayOneChar(5,3,LC[2]+0x30);
lds R24,_LC+2
subi R24,208 ; addi 48
std y+0,R24
ldi R18,3
ldi R16,5
xcall _DisplayOneChar
.dbline 274
; DisplayOneChar(6,3,LC[1]+0x30);
lds R24,_LC+1
subi R24,208 ; addi 48
std y+0,R24
ldi R18,3
ldi R16,6
xcall _DisplayOneChar
.dbline 275
; break;
xjmp L41
L69:
.dbline 277
;
; case 7:POW_OFF;Delay_nms(100);//关闭电源
sbi 0x12,1
.dbline 277
ldi R16,100
ldi R17,0
xcall _Delay_nms
.dbline 278
; AIR_OFF;Delay_nms(500);status=8;cnt=0;//关闭气缸
sbi 0x12,3
.dbline 278
ldi R16,500
ldi R17,1
xcall _Delay_nms
.dbline 278
ldi R24,8
sts _status,R24
.dbline 278
clr R2
clr R3
sts _cnt+1,R3
sts _cnt,R2
.dbline 279
; break;
xjmp L41
L70:
.dbline 281
;
; case 8:SPEED_5V;//黄线接5V
cbi 0x12,0
.dbline 282
; POW_14V;Delay_nms(100);POW_ON;//启动测试14V低压
sbi 0x12,2
.dbline 282
ldi R16,100
ldi R17,0
xcall _Delay_nms
.dbline 282
cbi 0x12,1
.dbline 284
;
; Wait10S_Start_Flag=1;cnt=0;clr_T1();//启动10S并开始T1计数
ldi R24,1
sts _Wait10S_Start_Flag,R24
.dbline 284
clr R2
clr R3
sts _cnt+1,R3
sts _cnt,R2
.dbline 284
xcall _clr_T1
.dbline 285
; display_val=0;status=9;TCCR1B = 0x06;
clr R2
clr R3
sts _display_val+1,R3
sts _display_val,R2
.dbline 285
ldi R24,9
sts _status,R24
.dbline 285
ldi R24,6
out 0x2e,R24
.dbline 286
; break;
xjmp L41
L72:
.dbline 288
ldi R16,10
ldi R17,0
xcall _Delay_nms
L73:
.dbline 288
;
; case 9:while(Wait10S_End_Flag==0)Delay_nms(10);Wait10S_End_Flag=0;status=10;//等待10S定时结束
lds R2,_Wait10S_End_Flag
tst R2
breq L72
.dbline 288
clr R2
sts _Wait10S_End_Flag,R2
.dbline 288
ldi R24,10
sts _status,R24
.dbline 289
; break;
xjmp L41
L75:
.dbline 291
;
; case 10:TCCR1B = 0x00;display_val=read_T1();status=11;//读取T1的计数(14V低压LVS)
clr R2
out 0x2e,R2
.dbline 291
xcall _read_T1
sts _display_val+1,R17
sts _display_val,R16
.dbline 291
ldi R24,11
sts _status,R24
.dbline 292
; f=(float)display_val;f=f*4.985;display_val=(uint)f;//修正
ldi R16,<L53
ldi R17,>L53
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
lds R16,_display_val
lds R17,_display_val+1
lsr R17
ror R16
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall empy32fs
lds R16,_display_val
lds R17,_display_val+1
andi R16,1
andi R17,0
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall add32f
movw R30,R28
std z+2,R16
std z+3,R17
std z+4,R18
std z+5,R19
.dbline 292
ldi R16,<L76
ldi R17,>L76
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R30,R28
; stack offset 4
ldd R2,z+6
ldd R3,z+7
ldd R4,z+8
ldd R5,z+9
st -y,R5
st -y,R4
st -y,R3
st -y,R2
xcall empy32f
movw R30,R28
std z+2,R16
std z+3,R17
std z+4,R18
std z+5,R19
.dbline 292
movw R30,R28
ldd R2,z+2
ldd R3,z+3
ldd R4,z+4
ldd R5,z+5
st -y,R5
st -y,R4
st -y,R3
st -y,R2
ldi R16,<L62
ldi R17,>L62
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall cmp32f
brlt L77
movw R30,R28
ldd R2,z+2
ldd R3,z+3
ldd R4,z+4
ldd R5,z+5
st -y,R5
st -y,R4
st -y,R3
st -y,R2
ldi R16,<L62
ldi R17,>L62
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall sub32f
xcall fp2int
movw R20,R16
subi R20,0 ; offset = 32768
sbci R21,128
xjmp L78
L77:
movw R30,R28
ldd R16,z+2
ldd R17,z+3
ldd R18,z+4
ldd R19,z+5
xcall fp2int
movw R20,R16
L78:
sts _display_val+1,R21
sts _display_val,R20
.dbline 293
; LLVS=display_val;//暂存LVS
movw R2,R20
sts _LLVS+1,R3
sts _LLVS,R2
.dbline 294
; if(LLVS>200)OutFlag++;//判断14V低压能否启动
ldi R24,200
ldi R25,0
lds R2,_LLVS
lds R3,_LLVS+1
cp R24,R2
cpc R25,R3
brsh L79
.dbline 294
lds R24,_OutFlag
subi R24,255 ; addi 1
sts _OutFlag,R24
L79:
.dbline 295
; temp=display_val;temp=temp/1000;LVS[3]=(uchar)temp;
lds R10,_display_val
lds R11,_display_val+1
.dbline 295
ldi R18,1000
ldi R19,3
movw R16,R10
xcall div16u
movw R10,R16
.dbline 295
sts _LVS+3,R10
.dbline 296
; temp=display_val;temp=(temp/100)%10;LVS[2]=(uchar)temp;
lds R10,_display_val
lds R11,_display_val+1
.dbline 296
ldi R18,100
ldi R19,0
movw R16,R10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -