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

📄 18b20.s

📁 AVR mega16系列单片机开发程序
💻 S
字号:
	.module _18b20.c
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\USING07-07\18B20未完成\18B20\18b20.c
	.dbfunc e init_1820 _init_1820 fV
	.even
_init_1820::
	.dbline -1
	.dbline 11
; /**************************************
; ** Filename: 18b20.c
; ** Describe: 18b20 温度传感器
; ** Time  :   2007-2-15
; **************************************/
; 
; #include "config.h"
; 
; unsigned char wmh,wml,flag; //flag温度为负标志,count为实际温度
; void init_1820(void)  
; {  
	.dbline 12
;     SET_DIR_1WIRE;      //设置PC4为输出 
	.dbline 13
;     SET_OP_1WIRE;        
	.dbline 14
;     delay_us(480);    //480us以上  
	ldi R16,480
	ldi R17,1
	xcall _delay_us
	.dbline 15
;     CLR_OP_1WIRE;
	.dbline 16
;     SET_OP_1WIRE;  
	.dbline 17
;     CLR_DIR_1WIRE;  
	.dbline 18
;     delay_us(20);     //15~60us  
	ldi R16,20
	ldi R17,0
	xcall _delay_us
L2:
	.dbline 19
L3:
	.dbline 19
;     while(CHECK_IP_1WIRE);  
	sbic 0x16,4
	rjmp L2
	.dbline 20
;     SET_DIR_1WIRE;  
	.dbline 21
;     SET_OP_1WIRE;  
	.dbline 22
;     delay_us(140);   //60~240us  
	ldi R16,140
	ldi R17,0
	xcall _delay_us
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e write_1820 _write_1820 fV
;              m -> R20
;              x -> R22
	.even
_write_1820::
	xcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 25
; }  
; void write_1820(unsigned char x)  
; {     
	.dbline 27
;      unsigned char m;  
;     for(m=0;m<8;m++)  
	clr R20
	xjmp L9
L6:
	.dbline 28
;     {  
	.dbline 29
;        CLR_OP_1WIRE;  
	.dbline 30
;        if(x&(1<<m))    //写数据了,先写低位的 
	ldi R16,1
	mov R17,R20
	xcall lsl8
	mov R2,R22
	and R2,R16
	breq L10
	.dbline 31
;        SET_OP_1WIRE;  
L10:
	.dbline 33
;        else  
;        {CLR_OP_1WIRE;}  
	.dbline 33
	.dbline 33
L11:
	.dbline 34
	ldi R16,40
	ldi R17,0
	xcall _delay_us
	.dbline 35
	.dbline 36
L7:
	.dbline 27
	inc R20
L9:
	.dbline 27
	cpi R20,8
	brlo L6
	.dbline 37
;        delay_us(40);   //15~60us  
;        SET_OP_1WIRE;  
;     }  
;      SET_OP_1WIRE;  
	.dbline -2
L5:
	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 40
; }  
; unsigned char read_1820(void)  
; {      
	.dbline 42
;     unsigned char temp,k,n;  
;     temp=0;  
	clr R20
	.dbline 43
;     for(n=0;n<8;n++)  
	clr R10
	xjmp L16
L13:
	.dbline 44
;     {
	.dbline 45
;       CLR_OP_1WIRE;  
	.dbline 46
;       SET_OP_1WIRE;  
	.dbline 47
;       CLR_DIR_1WIRE;  
	.dbline 48
;       k=(CHECK_IP_1WIRE);    //读数据,从低位开始  
	in R22,0x16
	andi R22,16
	.dbline 49
;       if(k)  
	breq L17
	.dbline 50
;       temp|=(1<<n);  
	ldi R16,1
	mov R17,R10
	xcall lsl8
	or R20,R16
	xjmp L18
L17:
	.dbline 52
;       else  
;       temp&=~(1<<n);  
	ldi R16,1
	mov R17,R10
	xcall lsl8
	mov R2,R16
	com R2
	and R20,R2
L18:
	.dbline 53
	ldi R16,50
	ldi R17,0
	xcall _delay_us
	.dbline 54
	.dbline 55
L14:
	.dbline 43
	inc R10
L16:
	.dbline 43
	mov R24,R10
	cpi R24,8
	brlo L13
	.dbline 56
;       delay_us(50); //60~120us      
;       SET_DIR_1WIRE;  
;     }  
;    return (temp);  
	mov R16,R20
	.dbline -2
L12:
	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 gettemp _gettemp fc
;            wm3 -> R14
;            wm1 -> R20
;            wm0 -> R22
;           teml -> R12
;          count -> R10
;           temh -> R14
;            wm2 -> R12
	.even
_gettemp::
	xcall push_gset5
	sbiw R28,4
	.dbline -1
	.dbline 60
; }   
; 
; unsigned char gettemp()         //读取温度值 
; {    
	.dbline 63
;     unsigned char count;
;      unsigned char temh,teml,wm0,wm1,wm2,wm3;  
;      init_1820();        //复位18b20  
	xcall _init_1820
	.dbline 64
;      write_1820(0xcc);   // 发出转换命令  
	ldi R16,204
	xcall _write_1820
	.dbline 65
;      write_1820(0xbe); 
	ldi R16,190
	xcall _write_1820
	.dbline 67
;    //  delay_nms(800);     //不延时也好使,不知道怎么回事! 
;      teml=read_1820();  //读数据  
	xcall _read_1820
	mov R12,R16
	.dbline 68
;      temh=read_1820();  
	xcall _read_1820
	mov R14,R16
	.dbline 69
;      init_1820();  
	xcall _init_1820
	.dbline 70
;      write_1820(0xcc);  //发出读命令  
	ldi R16,204
	xcall _write_1820
	.dbline 71
;      write_1820(0x44);
	ldi R16,68
	xcall _write_1820
	.dbline 74
;    
; 
; if((temh&0xF8) == 0xF8)  
	mov R24,R14
	andi R24,248
	cpi R24,248
	breq X0
	xjmp L20
X0:
	.dbline 75
; { 
	.dbline 76
;    flag=1; 
	ldi R24,1
	sts _flag,R24
	.dbline 77
;    count=((0xFF-temh)*256+(0xFF-teml))*6.25; 
	ldi R16,<L24
	ldi R17,>L24
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	mov R2,R14
	clr R3
	ldi R18,255
	ldi R19,0
	sub R18,R2
	sbc R19,R3
	ldi R16,256
	ldi R17,1
	xcall empy16s
	movw R2,R16
	mov R4,R12
	clr R5
	ldi R24,255
	ldi R25,0
	sub R24,R4
	sbc R25,R5
	add R2,R24
	adc R3,R25
	movw R16,R2
	xcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	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,<L25
	ldi R17,>L25
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L22
	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,<L25
	ldi R17,>L25
	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 L23
L22:
	movw R30,R28
	ldd R16,z+0
	ldd R17,z+1
	ldd R18,z+2
	ldd R19,z+3
	xcall fp2int
	movw R10,R16
L23:
	.dbline 79
; 
; } 
	xjmp L21
L20:
	.dbline 81
; else 
; {    
	.dbline 82
;    flag=0; 
	clr R2
	sts _flag,R2
	.dbline 83
;    count=(temh*256+teml)*6.25;             //计算具体温度  
	ldi R16,<L24
	ldi R17,>L24
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	mov R18,R14
	clr R19
	ldi R16,256
	ldi R17,1
	xcall empy16s
	movw R2,R16
	mov R4,R12
	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
	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,<L25
	ldi R17,>L25
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	xcall cmp32f
	brlt L26
	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,<L25
	ldi R17,>L25
	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 L27
L26:
	movw R30,R28
	ldd R16,z+0
	ldd R17,z+1
	ldd R18,z+2
	ldd R19,z+3
	xcall fp2int
	movw R12,R16
L27:
	mov R10,R12
	.dbline 84
; }
L21:
	.dbline 85
;      wm2=wm1+wm0;                          //16进制转10进制 
	mov R12,R20
	add R12,R22
	.dbline 86
;      wm3=wm2/100; 
	ldi R17,100
	mov R16,R12
	xcall div8u
	mov R14,R16
	.dbline 87
;      wmh=(wm2%100)/10;                     //出口参数了!wmh是显示的高位,wml是显示的低位 
	ldi R17,100
	mov R16,R12
	xcall mod8u
	ldi R17,10
	xcall div8u
	sts _wmh,R16
	.dbline 88
;      wml=(wm2%100)%10;
	ldi R17,100
	mov R16,R12
	xcall mod8u
	ldi R17,10
	xcall mod8u
	sts _wml,R16
	.dbline 89
; 	 return(count); 
	mov R16,R10
	.dbline -2
L19:
	adiw R28,4
	xcall pop_gset5
	.dbline 0 ; func end
	ret
	.dbsym r wm3 14 c
	.dbsym r wm1 20 c
	.dbsym r wm0 22 c
	.dbsym r teml 12 c
	.dbsym r count 10 c
	.dbsym r temh 14 c
	.dbsym r wm2 12 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile C:\DOCUME~1\Administrator\桌面\USING07-07\18B20未完成\18B20\18b20.c
_flag::
	.blkb 1
	.dbsym e flag _flag c
_wml::
	.blkb 1
	.dbsym e wml _wml c
_wmh::
	.blkb 1
	.dbsym e wmh _wmh c
	.area lit(rom, con, rel)
L25:
	.word 0x0,0x4700
L24:
	.word 0x0,0x40c8

⌨️ 快捷键说明

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