📄 1.s
字号:
L28:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym l data 4 c
.dbsym r Y 22 c
.dbsym r X 20 c
.dbend
.dbfunc e delay _delay fV
; x -> R16,R17
.even
_delay::
.dbline -1
.dbline 155
;
; }
;
;
;
;
;
;
;
; /////////////////////////////////////////
; void delay(uint x) //1.5us左右
; {
xjmp L31
L30:
.dbline 157
.dbline 158
subi R16,1
sbci R17,0
.dbline 159
L31:
.dbline 156
; while(x)
cpi R16,0
cpc R16,R17
brne L30
X0:
.dbline -2
L29:
.dbline 0 ; func end
ret
.dbsym r x 16 i
.dbend
.dbfunc e init_1820 _init_1820 fV
.even
_init_1820::
.dbline -1
.dbline 164
; {
; x--;
; }
; }
;
; //////////////////////////////////////////
; void init_1820()
; {
.dbline 165
; PORTD|=(1<<6);
sbi 0x12,6
.dbline 166
; PORTD&=~(1<<6);
cbi 0x12,6
.dbline 167
; delay(3000); //480us以上
ldi R16,3000
ldi R17,11
xcall _delay
.dbline 168
; PORTD|=(1<<6);
sbi 0x12,6
.dbline 169
; DDRD&=~(1<<6);
cbi 0x11,6
.dbline 170
; delay(40); //15~60us
ldi R16,40
ldi R17,0
xcall _delay
L34:
.dbline 172
.dbline 176
L35:
.dbline 171
; while(PIND&(1<<6))
sbic 0x10,6
rjmp L34
.dbline 177
; {
; // disp_led(3,0);
; // for(;;)
; //{}
; }
; DDRD|=(1<<6);
sbi 0x11,6
.dbline 178
; PORTD|=(1<<6);
sbi 0x12,6
.dbline 179
; delay(150); //60~240us
ldi R16,150
ldi R17,0
xcall _delay
.dbline -2
L33:
.dbline 0 ; func end
ret
.dbend
.dbfunc e write_1820 _write_1820 fI
; m -> R20
; x -> R22
.even
_write_1820::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 183
; }
; ///////////////////////////////////////////////////////
; write_1820(uchar x)
; {
.dbline 185
; uchar m;
; for(m=0;m<8;m++)
clr R20
xjmp L41
L38:
.dbline 186
; {
.dbline 187
; PORTD&=~(1<<6);
cbi 0x12,6
.dbline 188
; if(x&(1<<m)) //写数据,从低位开始
ldi R16,1
mov R17,R20
xcall lsl8
mov R2,R22
and R2,R16
breq L42
.dbline 189
; PORTD|=(1<<6);
sbi 0x12,6
xjmp L43
L42:
.dbline 191
; else
; PORTD&=~(1<<6);
cbi 0x12,6
L43:
.dbline 192
ldi R16,40
ldi R17,0
xcall _delay
.dbline 193
sbi 0x12,6
.dbline 194
L39:
.dbline 185
inc R20
L41:
.dbline 185
cpi R20,8
brlo L38
.dbline 195
; delay(40); //15~60us
; PORTD|=(1<<6);
; }
; PORTD|=(1<<6);
sbi 0x12,6
.dbline -2
L37:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r m 20 c
.dbsym r x 22 c
.dbend
.dbfunc e read_1820 _read_1820 fc
; temp -> R20
; k -> R22
; n -> R10
.even
_read_1820::
xcall push_gset3
.dbline -1
.dbline 200
; }
;
; //////////////////////////////////////////////
; uchar read_1820()
; {
.dbline 202
; uchar temp,k,n;
; temp=0;
clr R20
.dbline 203
; for(n=0;n<8;n++)
clr R10
xjmp L48
L45:
.dbline 204
; {
.dbline 205
; PORTD&=~(1<<6);
cbi 0x12,6
.dbline 207
; //delay(2);
; PORTD|=(1<<6);
sbi 0x12,6
.dbline 209
; //delay(3);
; DDRD&=~(1<<6);
cbi 0x11,6
.dbline 210
; k=(PIND&(1<<6)); //读数据,从低位开始
in R22,0x10
andi R22,64
.dbline 211
; if(k)
breq L49
.dbline 212
; temp|=(1<<n);
ldi R16,1
mov R17,R10
xcall lsl8
or R20,R16
xjmp L50
L49:
.dbline 214
; else
; temp&=~(1<<n);
ldi R16,1
mov R17,R10
xcall lsl8
mov R2,R16
com R2
and R20,R2
L50:
.dbline 215
ldi R16,50
ldi R17,0
xcall _delay
.dbline 216
sbi 0x11,6
.dbline 217
L46:
.dbline 203
inc R10
L48:
.dbline 203
mov R24,R10
cpi R24,8
brlo L45
.dbline 218
; delay(50); //60~120us
; DDRD|=(1<<6);
; }
; return (temp);
mov R16,R20
.dbline -2
L44:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r k 22 c
.dbsym r n 10 c
.dbend
.dbfunc e send_byte _send_byte fV
; i -> R20
; x -> R22
.even
_send_byte::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 222
; }
; ////////////////////////////////////////////////
; void send_byte(uchar x) //以下为显示程序
; {
.dbline 224
; uchar i;
; for(i=0;i<8;i++)
clr R20
xjmp L55
L52:
.dbline 225
; {
.dbline 226
; PORTC&=~(1<<5); // PC5为底 为164提供时钟信号
cbi 0x15,5
.dbline 227
; if((x&(1<<(7-i)))||((dp==1)&&(i==0))) //判断每位数据的电平,及小数点判断
ldi R17,7
sub R17,R20
ldi R16,1
xcall lsl8
mov R2,R22
and R2,R16
brne L58
lds R24,_dp
cpi R24,1
brne L56
tst R20
brne L56
L58:
.dbline 228
; PORTC|=(1<<4); //若为高着PC4输出高电平
sbi 0x15,4
xjmp L57
L56:
.dbline 230
; else
; PORTC&=~(1<<4); //若为低着输出低电平
cbi 0x15,4
L57:
.dbline 231
sbi 0x15,5
.dbline 232
L53:
.dbline 224
inc R20
L55:
.dbline 224
cpi R20,8
brlo L52
.dbline -2
L51:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r x 22 c
.dbend
.dbfunc e main _main fV
; teml -> R20
; temh -> R22
; i -> R10
.even
_main::
sbiw R28,2
.dbline -1
.dbline 237
; PORTC|=(1<<5); //PC5 提供始终信号
; }
; //PORTC|=((1<<0)|(1<<1)|(1<<2));
; }
; ////////////////////////////////////////////////
; void main(void) //主函数
; {
.dbline 239
; // disp_led(0,0);
; delay(2000);
ldi R16,2000
ldi R17,7
xcall _delay
.dbline 240
; OSCCAL=0X9d;//系统时钟校准,不同的芯片和不同的频率,
ldi R24,157
out 0x31,R24
.dbline 241
; DDRC=0xff;
ldi R24,255
out 0x14,R24
.dbline 242
; DDRD=0XFF;
out 0x11,R24
.dbline 243
; DDRA=0XFF;
out 0x1a,R24
.dbline 244
; PORTA=0XF3;
ldi R24,243
out 0x1b,R24
.dbline 245
; PORTD=0XFF;
ldi R24,255
out 0x12,R24
.dbline 246
; WDR(); //看门狗计数清零
wdr
.dbline 247
; LCD_init();
xcall _LCD_init
.dbline 248
; WDTCR=0x0F;
ldi R24,15
out 0x21,R24
.dbline 249
; PORTC=0xff;
ldi R24,255
out 0x15,R24
xjmp L61
L60:
.dbline 251
; while(1)
; {
.dbline 253
; uchar i,temh,teml;
; init_1820(); //复位18b20
xcall _init_1820
.dbline 254
; write_1820(0xcc); //skip rom
ldi R16,204
xcall _write_1820
.dbline 255
; write_1820(0x44); // 发出转换命令 convert T
ldi R16,68
xcall _write_1820
.dbline 256
; delay(400);
ldi R16,400
ldi R17,1
xcall _delay
.dbline 257
; init_1820();
xcall _init_1820
.dbline 258
; WDR();
wdr
.dbline 259
; write_1820(0xcc); //发出读命令
ldi R16,204
xcall _write_1820
.dbline 260
; write_1820(0xbe);
ldi R16,190
xcall _write_1820
.dbline 261
; teml=read_1820(); //读数据
xcall _read_1820
mov R20,R16
.dbline 262
; temh=read_1820();
xcall _read_1820
mov R22,R16
.dbline 273
;
; //for(i=0;i<7;i++) //测试用
; //{
; //send_byte(0x40);
; //send_byte(disp_table[0&0x0f]);
; //}
; //send_byte(disp_table[temh>>4]);
; //send_byte(disp_table[temh&0x0f]);
; //send_byte(disp_table[teml>>4]);
; //send_byte(disp_table[teml&0x0f]);
; count=(temh*256+teml)*6.25; //计算具体温度
ldi R16,<L63
ldi R17,>L63
xcall lpm32
st -y,R19
st -y,R18
st -y,R17
st -y,R16
mov R18,R22
clr R19
ldi R16,256
ldi R17,1
xcall empy16s
movw R2,R16
mov R4,R20
clr R5
add R2,R4
adc R3,R5
movw R16,R2
xcall int2fp
st -y,R19
st -y,R18
st -y,R17
st -y,R16
xcall empy32f
xcall fp2long
sts _count+1,R17
sts _count,R16
sts _count+2+1,R19
sts _count+2,R18
.dbline 274
; WDR();
wdr
.dbline 276
; //disp_led(0,1); //显示温度
; for(i=0;i<100;i++) //每次转换需要延时200ms以上
clr R10
xjmp L67
L64:
.dbline 277
ldi R16,1000
ldi R17,3
xcall _delay
L65:
.dbline 276
inc R10
L67:
.dbline 276
mov R24,R10
cpi R24,100
brlo L64
.dbline 278
ldi R24,<L68
ldi R25,>L68
std y+1,R25
std y+0,R24
clr R18
clr R16
xcall _LCD_write_string
.dbline 279
L61:
.dbline 250
xjmp L60
X1:
.dbline -2
L59:
adiw R28,2
.dbline 0 ; func end
ret
.dbsym r teml 20 c
.dbsym r temh 22 c
.dbsym r i 10 c
.dbend
.area bss(ram, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\18b20\1.c
_count::
.blkb 4
.dbsym e count _count L
_dp::
.blkb 1
.dbsym e dp _dp c
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\18b20\1.c
L68:
.blkb 6
.area idata
.byte 'c,'o,'u,'n,'t,0
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\Administrator\桌面\18b20\1.c
.area lit(rom, con, rel)
L63:
.word 0x0,0x40c8
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -