📄 main.s
字号:
adiw R28,4
xjmp pop_xgset303C
.dbsym r temp 20 c
.dbsym l ascii 2 A[2:2]c
.dbsym l asc 10 c
.dbsym r column 12 c
.dbsym r row 10 c
.dbend
.dbfunc e delay_1us _delay_1us fV
.even
_delay_1us::
.dbline -1
.dbline 152
; }
;
; /****************************************************************************/
; //////////////////////////////延时程序////////////////////////////////////////
; /****************************************************************************/
; #define XTAL 8 //晶振频率,单位MHz
; void delay_1us(void) //1us延时函数
; {
.dbline 153
; asm("nop");
nop
.dbline -2
L41:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay_nus _delay_nus fV
; i -> R20,R21
; n -> R10,R11
.even
_delay_nus::
xcall push_xgset300C
movw R10,R16
.dbline -1
.dbline 157
; }
;
; void delay_nus(unsigned int n) //N us延时函数
; {
.dbline 158
; unsigned int i=0;
clr R20
clr R21
.dbline 159
; for (i=0;i<n;i++)
xjmp L46
L43:
.dbline 160
; delay_1us();
xcall _delay_1us
L44:
.dbline 159
subi R20,255 ; offset = 1
sbci R21,255
L46:
.dbline 159
cp R20,R10
cpc R21,R11
brlo L43
X8:
.dbline -2
L42:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r i 20 i
.dbsym r n 10 i
.dbend
.dbfunc e delay_1ms _delay_1ms fV
; i -> R16,R17
.even
_delay_1ms::
.dbline -1
.dbline 164
; }
;
; void delay_1ms(void) //1ms延时函数
; {
.dbline 166
; unsigned int i;
; for (i=0;i<(unsigned int)(XTAL*143-2);i++);
clr R16
clr R17
xjmp L51
L48:
.dbline 166
L49:
.dbline 166
subi R16,255 ; offset = 1
sbci R17,255
L51:
.dbline 166
ldi R24,1142
ldi R25,4
cp R16,R24
cpc R17,R25
brlo L48
X9:
.dbline -2
L47:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e delay_nms _delay_nms fV
; i -> R20,R21
; n -> R10,R11
.even
_delay_nms::
xcall push_xgset300C
movw R10,R16
.dbline -1
.dbline 170
; }
;
; void delay_nms(unsigned int n) //N ms延时函数
; {
.dbline 171
; unsigned int i=0;
clr R20
clr R21
.dbline 172
; for (i=0;i<n;i++)
xjmp L56
L53:
.dbline 173
; {
.dbline 174
; delay_1ms();
xcall _delay_1ms
.dbline 175
; }
L54:
.dbline 172
subi R20,255 ; offset = 1
sbci R21,255
L56:
.dbline 172
cp R20,R10
cpc R21,R11
brlo L53
X10:
.dbline -2
L52:
.dbline 0 ; func end
xjmp pop_xgset300C
.dbsym r i 20 i
.dbsym r n 10 i
.dbend
.dbfile D:\DS18B20\ds18b20.h
.dbfunc e resetDS18B20 _resetDS18B20 fc
; errTime -> R10
.even
_resetDS18B20::
st -y,R10
.dbline -1
.dbline 8
; #define dq_clr PORTB&=~(1<<PB7) //数据线强制拉低
; #define dq_set PORTB|=(1<<PB7) //数据线强制拉高,上拉
; #define hold_dq DDRB|=(1<<PB7) //Mega16控制总线
; #define rls_dq DDRB&=~(1<<PB7) //释放总线
; #define stu_dq PINB&(1<<PB7) //数据线的状态
;
; unsigned char resetDS18B20(void)
; {
.dbline 9
; unsigned char errTime=0;
clr R10
.dbline 10
; rls_dq; //释放总线
cbi 0x17,7
.dbline 11
; _NOP();
nop
.dbline 12
; hold_dq; //Maga16控制总线
sbi 0x17,7
.dbline 13
; dq_clr; //强制拉低
cbi 0x18,7
.dbline 14
; delay_nus(480);
ldi R16,480
ldi R17,1
xcall _delay_nus
.dbline 16
; //以上延时大于480us
; rls_dq; //释放总线,总线自动上拉
cbi 0x17,7
.dbline 17
; _NOP();
nop
xjmp L59
L58:
.dbline 19
; while(stu_dq)
; {
.dbline 20
; delay_nus(5); //5us
ldi R16,5
ldi R17,0
xcall _delay_nus
.dbline 21
; errTime++;
inc R10
.dbline 22
; if(errTime>12)
ldi R24,12
cp R24,R10
brsh L61
X11:
.dbline 23
; return(0x00); //如果等带大于约 5*12就返回0x00,报告复位失败(实际上只要等待15-60us)
clr R16
xjmp L57
L61:
.dbline 24
; }
L59:
.dbline 18
sbic 0x16,7
rjmp L58
X12:
.dbline 25
; errTime=0;
clr R10
xjmp L64
L63:
.dbline 27
; while(!(stu_dq))
; {
.dbline 28
; delay_nus(5); //5us
ldi R16,5
ldi R17,0
xcall _delay_nus
.dbline 29
; errTime++;
inc R10
.dbline 30
; if(errTime>50)
ldi R24,50
cp R24,R10
brsh L66
X13:
.dbline 31
; return(0x00); //如果等带大于约 5us*50就返回0x00,报告复位失败(实际上只要等待60-240us)
clr R16
xjmp L57
L66:
.dbline 32
; }
L64:
.dbline 26
sbis 0x16,7
rjmp L63
X14:
.dbline 33
; return(0xff);
ldi R16,255
.dbline -2
L57:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym r errTime 10 c
.dbend
.dbfunc e readByteDS18B20 _readByteDS18B20 fc
; retVal -> R20
; i -> R22
.even
_readByteDS18B20::
st -y,R20
st -y,R22
.dbline -1
.dbline 37
; }
;
; unsigned char readByteDS18B20(void)
; {
.dbline 39
; unsigned char i;
; unsigned char retVal=0;
clr R20
.dbline 40
; rls_dq; //释放总线
cbi 0x17,7
.dbline 41
; for(i=8;i>0;i--)
ldi R22,8
xjmp L72
L69:
.dbline 42
; {
.dbline 43
; retVal>>=1;
lsr R20
.dbline 44
; hold_dq; //Maga16控制总线
sbi 0x17,7
.dbline 45
; dq_clr; //强制拉低
cbi 0x18,7
.dbline 46
; delay_nus(8); //延时大于1us
ldi R16,8
ldi R17,0
xcall _delay_nus
.dbline 47
; dq_set; //释放总线,DS18B20会将总线强制拉低
sbi 0x18,7
.dbline 49
;
; rls_dq; //释放总线
cbi 0x17,7
.dbline 50
; if(stu_dq)
sbis 0x16,7
rjmp L73
X15:
.dbline 51
; retVal|=0x80;
ori R20,128
L73:
.dbline 52
; delay_nus(30); //30us
ldi R16,30
ldi R17,0
xcall _delay_nus
.dbline 53
; hold_dq; //释放总线
sbi 0x17,7
.dbline 54
; dq_set; //释放总线,DS18B20会将总线强制拉低
sbi 0x18,7
.dbline 56
;
; }
L70:
.dbline 41
dec R22
L72:
.dbline 41
ldi R24,0
cp R24,R22
brlo L69
X16:
.dbline 57
; delay_nus(5); //2.71us(大于1us就行了)
ldi R16,5
ldi R17,0
xcall _delay_nus
.dbline 58
; return(retVal);
mov R16,R20
.dbline -2
L68:
.dbline 0 ; func end
ld R22,y+
ld R20,y+
ret
.dbsym r retVal 20 c
.dbsym r i 22 c
.dbend
.dbfunc e writeByteDS18B20 _writeByteDS18B20 fV
; temp -> R22
; i -> R20
; wb -> R10
.even
_writeByteDS18B20::
xcall push_xgsetF00C
mov R10,R16
.dbline -1
.dbline 62
; }
;
; void writeByteDS18B20(unsigned char wb)
; {
.dbline 65
; unsigned char i;
; unsigned char temp;
; rls_dq; //释放总线
cbi 0x17,7
.dbline 66
; for(i=0;i<8;i++)
clr R20
xjmp L79
L76:
.dbline 67
; {
.dbline 68
; hold_dq; //Maga16控制总线
sbi 0x17,7
.dbline 69
; dq_clr; //强制拉低
cbi 0x18,7
.dbline 70
; delay_nus(4);
ldi R16,4
ldi R17,0
xcall _delay_nus
.dbline 71
; temp=wb>>i;
mov R16,R10
mov R17,R20
xcall lsr8
mov R22,R16
.dbline 72
; temp&=0x01;
andi R22,1
.dbline 73
; if(temp)
breq L80
X17:
.dbline 74
; dq_set; //释放总线
sbi 0x18,7
xjmp L81
L80:
.dbline 76
; else
; dq_clr; //强制拉低
cbi 0x18,7
L81:
.dbline 77
; delay_nus(50);
ldi R16,50
ldi R17,0
xcall _delay_nus
.dbline 79
;
; dq_set; //释放总线
sbi 0x18,7
.dbline 80
; delay_nus(4); //(大于1us就行了)
ldi R16,4
ldi R17,0
xcall _delay_nus
.dbline 81
; }
L77:
.dbline 66
inc R20
L79:
.dbline 66
cpi R20,8
brlo L76
X18:
.dbline -2
L75:
.dbline 0 ; func end
xjmp pop_xgsetF00C
.dbsym r temp 22 c
.dbsym r i 20 c
.dbsym r wb 10 c
.dbend
.dbfunc e readTempDS18B20 _readTempDS18B20 fV
; tempH -> R12
; tempL -> R10
; x -> R10,R11
.even
_readTempDS18B20::
xcall push_xgset003C
sbiw R28,2
.dbline -1
.dbline 85
; }
;
; void readTempDS18B20(void)
; {
.dbline 88
; unsigned char tempL,tempH;
; unsigned int x;
; resetDS18B20();
xcall _resetDS18B20
.dbline 89
; writeByteDS18B20(0xcc); //跳过ROM
ldi R16,204
xcall _writeByteDS18B20
.dbline 90
; writeByteDS18B20(0x44); //启动温度转换
ldi R16,68
xcall _writeByteDS18B20
.dbline 91
; delay_nus(500); //等待500us
ldi R16,500
ldi R17,1
xcall _delay_nus
.dbline 92
; resetDS18B20();
xcall _resetDS18B20
.dbline 93
; writeByteDS18B20(0xcc); //跳过ROM
ldi R16,204
xcall _writeByteDS18B20
.dbline 94
; writeByteDS18B20(0xbe); //读数据
ldi R16,190
xcall _writeByteDS18B20
.dbline 95
; tempL=readByteDS18B20();
xcall _readByteDS18B20
mov R10,R16
.dbline 96
; tempH=readByteDS18B20();
xcall _readByteDS18B20
mov R12,R16
.dbline 97
; x=(tempH<<8)|tempL;
mov R11,R12
.dbline 98
; resetDS18B20();
xcall _resetDS18B20
.dbline 99
; writeByteDS18B20(0xcc); //跳过ROM
ldi R16,204
xcall _writeByteDS18B20
.dbline 100
; writeByteDS18B20(0x44); //启动温度转换
ldi R16,68
xcall _writeByteDS18B20
.dbline 101
; x=x*0.625;
ldi R16,<L83
ldi R17,>L83
xcall lpm32
movw R2,R16
movw R4,R18
movw R16,R10
xcall uint2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
movw R16,R2
movw R18,R4
xcall fpmule2
xcall fpint
movw R10,R16
.dbline 102
; LCD_DisplayInt(2,3,x); //未将温度值的小数点显示出
std y+1,R11
std y+0,R10
ldi R18,3
ldi R16,2
xcall _LCD_DisplayInt
.dbline -2
L82:
.dbline 0 ; func end
adiw R28,2
xjmp pop_xgset003C
.dbsym r tempH 12 c
.dbsym r tempL 10 c
.dbsym r x 10 i
.dbend
.dbfile D:\DS18B20\main.c
.dbfunc e main _main fV
; temp -> R10,R11
; i -> R10
.even
_main::
sbiw R28,2
.dbline -1
.dbline 7
; #include <iom16v.h>
; #include <macros.h>
; #include "lcd.h"
; #include "ds18b20.h"
;
; void main(void)
; {
.dbline 8
; unsigned char i=0;
clr R10
.dbline 9
; unsigned int temp=0;
clr R11
.dbline 10
; CLI();
cli
.dbline 11
; LCD_init();
xcall _LCD_init
.dbline 12
; SEI();
sei
.dbline 13
; LCD_DisplayString(1,4,"DS18B20");
ldi R24,<L85
ldi R25,>L85
std y+1,R25
std y+0,R24
ldi R18,4
ldi R16,1
xcall _LCD_DisplayString
.dbline 14
; LCD_DisplayString(2,1,"T=");
ldi R24,<L86
ldi R25,>L86
std y+1,R25
std y+0,R24
ldi R18,1
ldi R16,2
xcall _LCD_DisplayString
xjmp L88
L87:
.dbline 16
; while(1)
; {
.dbline 17
; readTempDS18B20();
xcall _readTempDS18B20
.dbline 18
; }
L88:
.dbline 15
xjmp L87
X19:
.dbline -2
L84:
.dbline 0 ; func end
adiw R28,2
ret
.dbsym r temp 10 i
.dbsym r i 10 c
.dbend
.area bss(ram, con, rel)
.dbfile D:\DS18B20\main.c
_ch1::
.blkb 6
.dbfile D:\DS18B20\lcd.h
.dbsym e ch1 _ch1 A[6:6]c
.area data(ram, con, rel)
.dbfile D:\DS18B20\lcd.h
L86:
.blkb 3
.area idata
.byte 'T,61,0
.area data(ram, con, rel)
.dbfile D:\DS18B20\lcd.h
L85:
.blkb 8
.area idata
.byte 'D,'S,49,56,'B,50,48,0
.area data(ram, con, rel)
.dbfile D:\DS18B20\lcd.h
.area lit(rom, con, rel)
L83:
.word 0x0,0x3f20
; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -