📄 1820.s
字号:
mov R16,R20
.dbline -2
L28:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r retVal 20 c
.dbsym r i 22 c
.dbend
.dbfunc e writeByteDS18B20 _writeByteDS18B20 fV
; temp -> R20
; i -> R22
; wb -> R10
.even
_writeByteDS18B20::
xcall push_gset3
mov R10,R16
.dbline -1
.dbline 277
; }
;
;
; /**********************************************************************
; functionName: BYTE readByteDS18B20(void)
; description :写DS18B20一个字节
; **********************************************************************/
; void writeByteDS18B20(unsigned char wb)
; {
.dbline 280
; unsigned char i;
; unsigned char temp;
; RLS_DS18B20; //释放总线
cbi 0x17,1
.dbline 281
; for(i=0;i<8;i++)
clr R22
xjmp L39
L36:
.dbline 282
; {
.dbline 283
; HLD_DS18B20; //Maga16控制总线
sbi 0x17,1
.dbline 284
; CLR_DS18B20; //强制拉低
cbi 0x18,1
.dbline 285
; delayUs(16); //14.92us
ldi R16,16
xcall _delayUs
.dbline 286
; temp=wb>>i;
mov R16,R10
mov R17,R22
xcall lsr8
mov R20,R16
.dbline 287
; temp&=0x01;
andi R20,1
.dbline 288
; if(temp)
breq L40
.dbline 289
; RLS_DS18B20; //释放总线
cbi 0x17,1
xjmp L41
L40:
.dbline 291
; else
; CLR_DS18B20; //强制拉低
cbi 0x18,1
L41:
.dbline 292
ldi R16,16
xcall _delayUs
.dbline 293
ldi R16,35
xcall _delayUs
.dbline 294
cbi 0x17,1
.dbline 295
ldi R16,1
xcall _delayUs
.dbline 296
L37:
.dbline 281
inc R22
L39:
.dbline 281
cpi R22,8
brlo L36
.dbline -2
L35:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r i 22 c
.dbsym r wb 10 c
.dbend
.dbfunc e readTempDS18B20 _readTempDS18B20 fi
; x -> R20,R21
; tempH -> R20
; tempL -> R22
.even
_readTempDS18B20::
xcall push_gset2
.dbline -1
.dbline 305
; delayUs(16); //14.92us
; delayUs(35); //30.38us
; RLS_DS18B20; //释放总线
; delayUs(1); //2.71us(大于1us就行了)
; }
; }
;
;
; /**********************************************************************
; functionName: unsigned int readTempDS18B20(void)
; description :读DS18B20温度
; **********************************************************************/
; unsigned int readTempDS18B20(void)
; {
.dbline 308
; unsigned char tempL,tempH;
; unsigned int x;
; resetDS18B20();
xcall _resetDS18B20
.dbline 309
; writeByteDS18B20(0xcc); //跳过ROM
ldi R16,204
xcall _writeByteDS18B20
.dbline 310
; writeByteDS18B20(0x44); //启动温度转换
ldi R16,68
xcall _writeByteDS18B20
.dbline 311
; delayUs(1);
ldi R16,1
xcall _delayUs
.dbline 312
; tempL=resetDS18B20();
xcall _resetDS18B20
.dbline 313
; writeByteDS18B20(0xcc); //跳过ROM
ldi R16,204
xcall _writeByteDS18B20
.dbline 314
; writeByteDS18B20(0xbe); //读数据
ldi R16,190
xcall _writeByteDS18B20
.dbline 315
; tempL=readByteDS18B20();
xcall _readByteDS18B20
mov R22,R16
.dbline 316
; tempH=readByteDS18B20();
xcall _readByteDS18B20
mov R20,R16
.dbline 317
; x=(tempH<<8)|tempL;
mov R21,R20
mov R20,R22
.dbline 318
; return(x);
movw R16,R20
.dbline -2
L42:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r x 20 i
.dbsym r tempH 20 c
.dbsym r tempL 22 c
.dbend
.dbfunc e realTemp _realTemp fD
; Temp -> y+0
.even
_realTemp::
sbiw R28,4
.dbline -1
.dbline 331
; }
;
;
; /******************************************************************************
; * 名称:float realTemp(void)
; * 说明:倍率为0.0625
; * 功能:计算真实温度值
; * 调用:unsigned int readTempDS18B20(void)
; * 输入:无
; * 返回值:真实温度值(浮点数)
; *******************************************************************************/
; float realTemp(void)
; {
.dbline 332
; float Temp= readTempDS18B20()*0.0625;
xcall _readTempDS18B20
movw R2,R16
ldi R16,<L44
ldi R17,>L44
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
ldi R16,<L45
ldi R17,>L45
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R16,R2
lsr R17
ror R16
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall empy32fs
movw R16,R2
andi R16,1
andi R17,0
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall add32fs
xcall empy32f
movw R30,R28
std z+0,R16
std z+1,R17
std z+2,R18
std z+3,R19
.dbline 333
; return Temp;
movw R30,R28
ldd R16,z+0
ldd R17,z+1
ldd R18,z+2
ldd R19,z+3
.dbline -2
L43:
adiw R28,4
.dbline 0 ; func end
ret
.dbsym l Temp 0 D
.dbend
.dbfunc e displayTemp _displayTemp fI
; l -> <dead>
; T -> y+2
; temp -> R10,R11
; num -> y+19
; j -> R22
; i -> R20
.even
_displayTemp::
xcall push_gset4
mov R22,R18
mov R20,R16
sbiw R28,11
.dbline -1
.dbline 346
; }
;
;
; /******************************************************************************
; * 名称:displayTemp
; * 说明:num为真实温度值,i列.j为行,
; * 功能:显示温度值
; * 调用:LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
; * 输入:真实温度值
; * 返回值:无
; *******************************************************************************/
; displayTemp( unsigned char i,unsigned char j, float num)//LCD显示
; {unsigned char T[5] ,l;
.dbline 347
; unsigned int temp=num*100;
ldi R16,<L49
ldi R17,>L49
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R30,R28
; stack offset 4
ldd R2,z+23
ldd R3,z+24
ldd R4,z+25
ldd R5,z+26
st -y,R5
st -y,R4
st -y,R3
st -y,R2
xcall empy32f
movw R30,R28
std z+7,R16
std z+8,R17
std z+9,R18
std z+10,R19
movw R30,R28
ldd R2,z+7
ldd R3,z+8
ldd R4,z+9
ldd R5,z+10
st -y,R5
st -y,R4
st -y,R3
st -y,R2
ldi R16,<L50
ldi R17,>L50
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall cmp32f
brlt L47
movw R30,R28
ldd R2,z+7
ldd R3,z+8
ldd R4,z+9
ldd R5,z+10
st -y,R5
st -y,R4
st -y,R3
st -y,R2
ldi R16,<L50
ldi R17,>L50
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 R12,R24
xjmp L48
L47:
movw R30,R28
ldd R16,z+7
ldd R17,z+8
ldd R18,z+9
ldd R19,z+10
xcall fp2int
movw R12,R16
L48:
movw R10,R12
.dbline 348
; T[0]='0'+temp/1000;
ldi R18,1000
ldi R19,3
movw R16,R10
xcall div16u
movw R24,R16
adiw R24,48
std y+2,R24
.dbline 349
; temp=temp%1000;
ldi R18,1000
ldi R19,3
movw R16,R10
xcall mod16u
movw R10,R16
.dbline 350
; T[1]='0'+temp/100;
ldi R18,100
ldi R19,0
xcall div16u
movw R24,R16
adiw R24,48
std y+3,R24
.dbline 351
; temp=temp%100;
ldi R18,100
ldi R19,0
movw R16,R10
xcall mod16u
movw R10,R16
.dbline 352
; T[2]='.';
ldi R24,46
std y+4,R24
.dbline 353
; T[3]='0'+temp/10;
ldi R18,10
ldi R19,0
xcall div16u
movw R24,R16
adiw R24,48
std y+5,R24
.dbline 354
; temp=temp%10;
ldi R18,10
ldi R19,0
movw R16,R10
xcall mod16u
movw R10,R16
.dbline 355
; T[4]='0'+temp/1;
movw R24,R10
adiw R24,48
std y+6,R24
.dbline 356
; LCD_write_string(i,j,T);
movw R24,R28
adiw R24,2
std y+1,R25
std y+0,R24
mov R18,R22
mov R16,R20
xcall _LCD_write_string
.dbline -2
L46:
adiw R28,11
xcall pop_gset4
.dbline 0 ; func end
ret
.dbsym l l 3 c
.dbsym l T 2 A[5:5]c
.dbsym r temp 10 i
.dbsym l num 19 D
.dbsym r j 22 c
.dbsym r i 20 c
.dbend
.dbfunc e delay_1us _delay_1us fV
.even
_delay_1us::
.dbline -1
.dbline 386
;
; }
; /*void displayTemp(char x,char y,float num)
; {
; /*uint Tempp=num*10;
; char s[3],i;
; for(i=0;i<3;i++)
; {
; s[i]= Tempp%10;
; Tempp=Tempp/10;
; }
; for(i=0;i<4;i++)
; {
; if(i<2)
; LCD_write_char(x++,y,s[2-i]+'0');
; if(i==2)
; LCD_write_char(x++, y,'.');
; if(i==3)
; LCD_write_char(x++,y,s[0]+'0');
; }
; }*/
; /******************************************************************************
; DS18B20驱动程序
; ******************************************************************************/
;
;
;
; //********************延时函数
; void delay_1us(void) //1us延时函数
; {
.dbline 387
; asm("nop");
nop
.dbline -2
L55:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay_nus _delay_nus fV
; i -> R20,R21
; n -> R22,R23
.even
_delay_nus::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 391
; }
;
; void delay_nus(unsigned int n) //N us延时函数
; {
.dbline 392
; unsigned int i=0;
clr R20
clr R21
.dbline 393
; for (i=0;i<n;i++)
xjmp L60
L57:
.dbline 394
xcall _delay_1us
L58:
.dbline 393
subi R20,255 ; offset = 1
sbci R21,255
L60:
.dbline 393
cp R20,R22
cpc R21,R23
brlo L57
.dbline -2
L56:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 22 i
.dbend
.dbfunc e delay_1ms _delay_1ms fV
; i -> R16,R17
.even
_delay_1ms::
.dbline -1
.dbline 398
; delay_1us();
; }
;
; void delay_1ms(void) //1ms延时函数
; {
.dbline 400
clr R16
clr R17
xjmp L65
L62:
.dbline 400
L63:
.dbline 400
subi R16,255 ; offset = 1
sbci R17,255
L65:
.dbline 400
; unsigned int i;
; for (i=0;i<1140;i++);
cpi R16,116
ldi R30,4
cpc R17,R30
brlo L62
.dbline -2
L61:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e delay_nms _delay_nms fV
; i -> R20,R21
; n -> R22,R23
.even
_delay_nms::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 404
; }
;
; void delay_nms(unsigned int n) //N ms延时函数
; {
.dbline 405
; unsigned int i=0;
clr R20
clr R21
.dbline 406
; for (i=0;i<n;i++)
xjmp L70
L67:
.dbline 407
xcall _delay_1ms
L68:
.dbline 406
subi R20,255 ; offset = 1
sbci R21,255
L70:
.dbline 406
cp R20,R22
cpc R21,R23
brlo L67
.dbline -2
L66:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r n 22 i
.dbend
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 413
; delay_1ms();
; }
; //********************延时函数
;
; //端口初始化
; void port_init(void)
; {
.dbline 414
; PORTA = 0xff;
ldi R24,255
out 0x1b,R24
.dbline 415
; DDRA = 0xff;
out 0x1a,R24
.dbline 416
; PORTB = 0x00;
clr R2
out 0x18,R2
.dbline 417
; DDRB = 0xff;
out 0x17,R24
.dbline 418
; PORTD = 0xff;
out 0x12,R24
.dbline 419
; DDRD = 0xe0;
ldi R24,224
out 0x11,R24
.dbline -2
L71:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fI
; i -> y+4
.even
_main::
sbiw R28,8
.dbline -1
.dbline 424
; }
;
; //主函数
; main()
; {
.dbline 425
; float i=0;
ldi R16,<L73
ldi R17,>L73
xcall lpm32
movw R30,R28
std z+4,R16
std z+5,R17
std z+6,R18
std z+7,R19
.dbline 427
; //port_init();
; LCD_init();
xcall _LCD_init
.dbline 429
;
; LCD_write_string(0,0 ,"welcome");
ldi R24,<L74
ldi R25,>L74
std y+1,R25
std y+0,R24
clr R18
clr R16
xcall _LCD_write_string
xjmp L76
L75:
.dbline 432
.dbline 432
xcall _realTemp
movw R30,R28
std z+4,R16
std z+5,R17
std z+6,R18
std z+7,R19
.dbline 434
movw R30,R28
ldd R2,z+4
ldd R3,z+5
ldd R4,z+6
ldd R5,z+7
std y+0,R2
std y+1,R3
std y+2,R4
std y+3,R5
ldi R18,1
clr R16
xcall _displayTemp
.dbline 435
ldi R16,1500
ldi R17,5
xcall _delay_nms
.dbline 438
L76:
.dbline 431
xjmp L75
X0:
.dbline -2
L72:
adiw R28,8
.dbline 0 ; func end
ret
.dbsym l i 4 D
.dbend
.area data(ram, con, rel)
.dbfile E:\单片机\AVR程序\温度传感器\1820.c
L74:
.blkb 8
.area idata
.byte 'w,'e,'l,'c,'o,'m,'e,0
.area data(ram, con, rel)
.dbfile E:\单片机\AVR程序\温度传感器\1820.c
.area lit(rom, con, rel)
L73:
.word 0x0,0x0
L50:
.word 0x0,0x4700
L49:
.word 0x0,0x42c8
L45:
.word 0x0,0x4000
L44:
.word 0x0,0x3d80
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -