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

📄 main.s

📁 ds18b20多个时候的分辨函数
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module main.c
	.area text(rom, con, rel)
	.dbfile D:\cood\18b20\main.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 33
; #include <iom32v.h>
; #include <macros.h>
; 
; #define F_CPU 7372800
; 
; //数据类型的定义
; #define     uint8   unsigned char                                         
; #define   uint16   unsigned int
; 
; //位变量操作宏定义
; #define     BIT_SET(a,b)   a|=BIT(b)
; #define     BIT_CLR(a,b)   a&=~BIT(b)
; #define     BIT_INV(a,b)     a^=BIT(b)
; #define     BIT_STATUS(a,b) a&BIT(b)
; 
; //DS18B20操作定义
; #define     CLR_DS18B20     BIT_CLR(PORTA,PA0)     //数据线强制拉低
; #define     SET_DS18B20     BIT_SET(PORTA,PA0)     //数据线强制拉高,上拉
; #define     HLD_DS18B20     BIT_SET(DDRA,PA0)     //Mega16控制总线
; #define     RLS_DS18B20     BIT_CLR(DDRA,PA0)         //释放总线
; #define     STU_DS18B20     BIT_STATUS(PINA,PA0)     //数据线的状态
; #define     bit_0_1  0x00
; #define     bit_0    0x01    //因为移位了,所以低在前,高位在后
; #define     bit_1    0x02
; #define     maxsize  7
; unsigned char rom_seq[maxsize][8];
; unsigned char B20_num;
; unsigned char tep[maxsize][10];
; 
; 
; 
; void port_init(void)
; {
	.dbline 34
; PORTA = 0xFF;
	ldi R24,255
	out 0x1b,R24
	.dbline 35
; DDRA = 0xFF;
	out 0x1a,R24
	.dbline 36
; PORTB = 0xFF;
	out 0x18,R24
	.dbline 37
; DDRB = 0xFF; //输出
	out 0x17,R24
	.dbline 38
; PORTC = 0xFF; //m103 output only
	out 0x15,R24
	.dbline 39
; DDRC = 0xFF; //输出 
	out 0x14,R24
	.dbline 40
; DDRD = 0xFF;
	out 0x11,R24
	.dbline 41
; PORTD = 0xFF;
	out 0x12,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delayUs _delayUs fV
;           temp -> R16
	.even
_delayUs::
	.dbline -1
	.dbline 63
; }
; 
; /**********************************************************************
; functionName: void delayUs(BYTE temp)
; description :延时函数 晶振频率:7.3728MHZ
; delayUs(1);       //2.71us
; delayUs(2);       //3.53us
; delayUs(4);       //5.15us
; delayUs(8);       //8.41us
; delayUs(16);       //14.92us
; delayUs(32);       //27.94us
; delayUs(64);       //53.98us
; delayUs(128);       //106.07us
; delayUs(255);     //209.42us
; delayUs(18);       //16.55us
; delayUs(34);       //29.57us
; delayUs(35);       //30.38us
; delayUs(100);       //83.28
; _NOP();         //0.14us 
; **********************************************************************/
; void delayUs(uint8 temp)
; {
L3:
	.dbline 64
;     while(temp--);
L4:
	.dbline 64
	mov R2,R16
	clr R3
	subi R16,1
	tst R2
	brne L3
X0:
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbsym r temp 16 c
	.dbend
	.dbfunc e longdelay _longdelay fV
;              i -> R20,R21
	.even
_longdelay::
	st -y,R20
	st -y,R21
	.dbline -1
	.dbline 69
; }
; 
; //延时约1s
; void longdelay(void)
; {
	.dbline 71
; unsigned int i;
; for(i=4761;i!=0;i--)
	ldi R20,4761
	ldi R21,18
	xjmp L10
L7:
	.dbline 72
; delayUs(255);
	ldi R16,255
	xcall _delayUs
L8:
	.dbline 71
	subi R20,1
	sbci R21,0
L10:
	.dbline 71
	cpi R20,0
	cpc R20,R21
	brne L7
X1:
	.dbline -2
L6:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r i 20 i
	.dbend
	.dbfunc e resetDS18B20 _resetDS18B20 fc
;        errTime -> R10
	.even
_resetDS18B20::
	st -y,R10
	.dbline -1
	.dbline 81
; }
; 
; 
; /*******************************************************************************
; functionName: uint8 resetDS18B20(void)
; description :DS18B20初始化
; ********************************************************************************/
; uint8 resetDS18B20(void)
; {
	.dbline 82
;   uint8 errTime=0;
	clr R10
	.dbline 83
;   RLS_DS18B20;     //释放总线
	cbi 0x1a,0
	.dbline 84
;   _NOP();
	nop
	.dbline 85
;   HLD_DS18B20;     //Maga16控制总线
	sbi 0x1a,0
	.dbline 86
;   CLR_DS18B20;     //强制拉低
	cbi 0x1b,0
	.dbline 87
;   delayUs(255);     //209.42us
	ldi R16,255
	xcall _delayUs
	.dbline 88
;   delayUs(255);     //209.42us
	ldi R16,255
	xcall _delayUs
	.dbline 89
;   delayUs(255);     //83.28us
	ldi R16,255
	xcall _delayUs
	.dbline 91
;   //以上的三个延时大于480us
;   RLS_DS18B20;     //释放总线,总线自动上拉
	cbi 0x1a,0
	.dbline 92
;   _NOP();         
	nop
	xjmp L13
L12:
	.dbline 94
;   while(STU_DS18B20)   
;   {
	.dbline 95
;     delayUs(4);       //5.15us
	ldi R16,4
	xcall _delayUs
	.dbline 96
;     errTime++;
	inc R10
	.dbline 97
;     if(errTime>20)
	ldi R24,20
	cp R24,R10
	brsh L15
X2:
	.dbline 98
;     return(0x00);     //如果等带大于约 5.15us*20就返回0x00,报告复位失败(实际上只要等待15-60us)
	clr R16
	xjmp L11
L15:
	.dbline 99
;   }
L13:
	.dbline 93
	sbic 0x19,0
	rjmp L12
X3:
	.dbline 100
;   errTime=0;
	clr R10
	xjmp L18
L17:
	.dbline 102
;   while(!(STU_DS18B20))   
;   {
	.dbline 103
;     delayUs(4);       //5.15us
	ldi R16,4
	xcall _delayUs
	.dbline 104
;     errTime++;
	inc R10
	.dbline 105
;     if(errTime>50)
	ldi R24,50
	cp R24,R10
	brsh L20
X4:
	.dbline 106
;     return(0x00);     //如果等带大于约 5.15us*50就返回0x00,报告复位失败(实际上只要等待60-240us)
	clr R16
	xjmp L11
L20:
	.dbline 107
;   }
L18:
	.dbline 101
	sbis 0x19,0
	rjmp L17
X5:
	.dbline 108
;   return(0xff);
	ldi R16,255
	.dbline -2
L11:
	.dbline 0 ; func end
	ld R10,y+
	ret
	.dbsym r errTime 10 c
	.dbend
	.dbfunc e write_a_bit _write_a_bit fV
;           temp -> R10
	.even
_write_a_bit::
	st -y,R10
	mov R10,R16
	.dbline -1
	.dbline 115
; }
; 
; 
; /*
; 写一个位
; */
; void write_a_bit(unsigned char temp){
	.dbline 116
;     HLD_DS18B20;     //Maga16控制总线
	sbi 0x1a,0
	.dbline 117
;     CLR_DS18B20;     //强制拉低
	cbi 0x1b,0
	.dbline 118
;     delayUs(16);       //14.92us
	ldi R16,16
	xcall _delayUs
	.dbline 119
;     if(temp&0x01)
	sbrs R10,0
	rjmp L23
X6:
	.dbline 120
;     RLS_DS18B20;     //释放总线
	cbi 0x1a,0
	xjmp L24
L23:
	.dbline 122
;     else
;     CLR_DS18B20;     //强制拉低
	cbi 0x1b,0
L24:
	.dbline 123
;     delayUs(16);       //14.92us
	ldi R16,16
	xcall _delayUs
	.dbline 124
;     delayUs(35);       //30.38us
	ldi R16,35
	xcall _delayUs
	.dbline 125
;     RLS_DS18B20;     //释放总线
	cbi 0x1a,0
	.dbline 126
;     delayUs(1);         //2.71us(大于1us就行了)
	ldi R16,1
	xcall _delayUs
	.dbline -2
L22:
	.dbline 0 ; func end
	ld R10,y+
	ret
	.dbsym r temp 10 c
	.dbend
	.dbfunc e read_a_bit _read_a_bit fc
;           temp -> R20
	.even
_read_a_bit::
	st -y,R20
	.dbline -1
	.dbline 144
; 	//HLD_DS18B20;   //Maga16控制总线
; 
; 
; }
; 
; 
; 
; /*
; 
;  读一位
; 
; */
; 
; 
; 
; 
; 
; unsigned char  read_a_bit(void){
	.dbline 145
;  unsigned char temp=0;
	clr R20
	.dbline 146
;     HLD_DS18B20;   //Maga16控制总线
	sbi 0x1a,0
	.dbline 147
;     CLR_DS18B20;   //强制拉低
	cbi 0x1b,0
	.dbline 148
;     NOP();
	nop
	.dbline 149
;     NOP();
	nop
	.dbline 150
;     NOP();
	nop
	.dbline 151
;     NOP();
	nop
	.dbline 152
;     NOP();
	nop
	.dbline 153
;     NOP();
	nop
	.dbline 154
;     NOP();   
	nop
	.dbline 155
;     NOP();         //延时大于1us   
	nop
	.dbline 156
;     RLS_DS18B20;     //释放总线
	cbi 0x1a,0
	.dbline 157
;     NOP();
	nop
	.dbline 158
;     NOP();
	nop
	.dbline 159
;     NOP();
	nop
	.dbline 160
;     if(STU_DS18B20)
	sbis 0x19,0
	rjmp L26
X7:
	.dbline 161
;     temp=1;
	ldi R20,1
	xjmp L27
L26:
	.dbline 163
; 	else
; 	temp=0;
	clr R20
L27:
	.dbline 164
;     delayUs(16);       //14.92us
	ldi R16,16
	xcall _delayUs
	.dbline 165
;     delayUs(16);       //14.92us
	ldi R16,16
	xcall _delayUs
	.dbline 166
;     RLS_DS18B20;     //释放总线
	cbi 0x1a,0
	.dbline 167
;     delayUs(35);       //30.38us
	ldi R16,35
	xcall _delayUs
	.dbline 169
; 	//HLD_DS18B20;   //Maga16控制总线
;    return temp;
	mov R16,R20
	.dbline -2
L25:
	.dbline 0 ; func end
	ld R20,y+
	ret
	.dbsym r temp 20 c
	.dbend
	.dbfunc e readuint8DS18B20 _readuint8DS18B20 fc
;         retVal -> R20
;           temp -> R10
;              i -> R22
	.even
_readuint8DS18B20::
	xcall push_xgsetF00C
	.dbline -1
	.dbline 181
; }
; 
; 
; 
; 
; 
; /**********************************************************************
; functionName: uint8 readuint8DS18B20(void)
; description :读DS18B20一个字节
; **********************************************************************/
; uint8 readuint8DS18B20(void)
; {
	.dbline 183
;   uint8 i;
;   uint8 retVal=0;
	clr R20
	.dbline 184
;   uint8 temp=0;
	clr R10
	.dbline 185
;   RLS_DS18B20;     //释放总线
	cbi 0x1a,0
	.dbline 186
;   for(i=8;i>0;i--)
	ldi R22,8
	xjmp L32
L29:
	.dbline 187
;   {
	.dbline 188
;       retVal>>=1;
	lsr R20
	.dbline 212
; 	  /*
;         HLD_DS18B20;   //Maga16控制总线
;     CLR_DS18B20;   //强制拉低
;     NOP();
;       NOP();
;       NOP();
;       NOP();
;       NOP();
;     NOP();
;     NOP();   
;     NOP();         //延时大于1us   
;     RLS_DS18B20;     //释放总线
;     NOP();
;     NOP();
;     NOP();
;     if(STU_DS18B20)
;     retVal|=0x80;
;     delayUs(16);       //14.92us
;     delayUs(16);       //14.92us
;     RLS_DS18B20;     //释放总线
;     delayUs(35);       //30.38us
; 	*/
; 	
; 	temp=read_a_bit();
	xcall _read_a_bit
	mov R10,R16
	.dbline 213
; 	if(temp)
	tst R16
	breq L33
X8:
	.dbline 214
; 	retVal|=0x80;
	ori R20,128
L33:
	.dbline 216
; 	
;   }
L30:
	.dbline 186
	dec R22
L32:
	.dbline 186
	ldi R24,0
	cp R24,R22
	brlo L29
X9:
	.dbline 217
;   delayUs(1);         //2.71us(大于1us就行了)
	ldi R16,1
	xcall _delayUs
	.dbline 218
;   return(retVal);
	mov R16,R20
	.dbline -2
L28:
	.dbline 0 ; func end
	xjmp pop_xgsetF00C
	.dbsym r retVal 20 c
	.dbsym r temp 10 c
	.dbsym r i 22 c
	.dbend
	.dbfunc e writeuint8DS18B20 _writeuint8DS18B20 fV
;           temp -> R22
;              i -> R20
;             wb -> R10
	.even
_writeuint8DS18B20::
	xcall push_xgsetF00C
	mov R10,R16
	.dbline -1
	.dbline 227
; }
; 
; 
; /*******************************************************************************
; functionName: uint8 readuint8DS18B20(void)
; description :写DS18B20一个字节
; ********************************************************************************/
; void writeuint8DS18B20(uint8 wb)
; {
	.dbline 230
;   uint8 i;
;   uint8 temp;
;   RLS_DS18B20;     //释放总线
	cbi 0x1a,0
	.dbline 231
;   for(i=0;i<8;i++)
	clr R20
	xjmp L39
L36:
	.dbline 232
;   {
	.dbline 233
;     temp=wb>>i;
	mov R16,R10
	mov R17,R20
	xcall lsr8
	mov R22,R16
	.dbline 234
;     temp&=0x01;
	andi R22,1
	.dbline 235
;     write_a_bit(temp);
	mov R16,R22
	xcall _write_a_bit
	.dbline 251
;    /*
;     HLD_DS18B20;     //Maga16控制总线
;     CLR_DS18B20;     //强制拉低
;     delayUs(16);       //14.92us
;     temp=wb>>i;
;     temp&=0x01;
;     if(temp)
;     RLS_DS18B20;     //释放总线
;     else
;     CLR_DS18B20;     //强制拉低
;     delayUs(16);       //14.92us
;     delayUs(35);       //30.38us
;     RLS_DS18B20;     //释放总线
;     delayUs(1);         //2.71us(大于1us就行了)
; 	*/
;   }
L37:
	.dbline 231
	inc R20
L39:
	.dbline 231
	cpi R20,8
	brlo L36
X10:
	.dbline -2
L35:
	.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 fi
;              x -> R10,R11
;          tempH -> R12
;          tempL -> R10
	.even
_readTempDS18B20::
	xcall push_xgset003C
	.dbline -1
	.dbline 261
; }
; 
; //////////////////////////////////////////////////////////
; 
; /*******************************************************************************
; functionName: unsigned int readTempDS18B20(void)
; description :读DS18B20温度
; ********************************************************************************/
; unsigned int readTempDS18B20(void)
; {
	.dbline 264
;   uint8 tempL,tempH;
;   uint16 x;
;   resetDS18B20();
	xcall _resetDS18B20
	.dbline 265
;   writeuint8DS18B20(0xcc);   //跳过ROM
	ldi R16,204
	xcall _writeuint8DS18B20
	.dbline 266
;   writeuint8DS18B20(0x44);     //启动温度转换
	ldi R16,68
	xcall _writeuint8DS18B20
	.dbline 267
;   delayUs(1);
	ldi R16,1
	xcall _delayUs
	.dbline 268
;   resetDS18B20();
	xcall _resetDS18B20
	.dbline 269
;   writeuint8DS18B20(0xcc);     //跳过ROM
	ldi R16,204
	xcall _writeuint8DS18B20
	.dbline 270
;   writeuint8DS18B20(0xbe);     //读数据
	ldi R16,190
	xcall _writeuint8DS18B20
	.dbline 271
;   tempL=readuint8DS18B20();
	xcall _readuint8DS18B20
	mov R10,R16
	.dbline 272
;   tempH=readuint8DS18B20();
	xcall _readuint8DS18B20
	mov R12,R16
	.dbline 273
;   x=(tempH<<8)|tempL;
	mov R11,R12
	.dbline 274
;   return(x);
	movw R16,R10
	.dbline -2
L40:
	.dbline 0 ; func end
	xjmp pop_xgset003C
	.dbsym r x 10 i
	.dbsym r tempH 12 c
	.dbsym r tempL 10 c
	.dbend
	.dbfunc e USART_Init _USART_Init fV
;            tmp -> R10,R11
;           baud -> R10,R11
	.even
_USART_Init::
	xcall push_xgsetF00C
	movw R10,R16
	.dbline -1
	.dbline 282
; }
; 
; /*******************************************************************************
; 串口操作相关函数
; *******************************************************************************/
; 
; void USART_Init( unsigned int baud )
; {
	.dbline 285
; unsigned int tmp;
; /* 设置波特率*/
; tmp= F_CPU/baud/16-1;
	movw R2,R10
	clr R4
	clr R5
	ldi R20,0
	ldi R21,128
	ldi R22,112
	ldi R23,0
	st -y,R5
	st -y,R4
	st -y,R3
	st -y,R2
	movw R16,R20
	movw R18,R22
	xcall div32s
	ldi R20,16
	ldi R21,0
	ldi R22,0
	ldi R23,0
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32s
	movw R2,R16
	movw R4,R18
	ldi R20,1
	ldi R21,0
	ldi R22,0
	ldi R23,0
	sub R2,R20
	sbc R3,R21
	sbc R4,R22
	sbc R5,R23
	movw R10,R2
	.dbline 286
; UBRRH = (unsigned char)(tmp>>8);
	mov R2,R3
	clr R3
	out 0x20,R2
	.dbline 287
; UBRRL = (unsigned char)tmp;
	out 0x9,R10
	.dbline 289
; /* 接收器与发送器使能*/
; UCSRB = (1<<RXEN)|(1<<TXEN);
	ldi R24,24
	out 0xa,R24
	.dbline 291
; /* 设置帧格式: 8 个数据位, 2 个停止位*/
; UCSRC = (1<<URSEL)|(1<<USBS)|(1<<UCSZ0)|(1<<UCSZ1);
	ldi R24,142
	out 0x20,R24
	.dbline -2
L41:
	.dbline 0 ; func end
	xjmp pop_xgsetF00C
	.dbsym r tmp 10 i
	.dbsym r baud 10 i
	.dbend
	.dbfunc e USART_Transmit _USART_Transmit fV
;           data -> R16
	.even
_USART_Transmit::
	.dbline -1
	.dbline 296
; }
; 
; // 数据发送【发送5 到8 位数据位的帧】
; void USART_Transmit( unsigned char data )
; {
L43:
	.dbline 299
; /* 等待发送缓冲器为空 */
; while ( !( UCSRA & (1<<UDRE)) )
; ;
L44:
	.dbline 298
	sbis 0xb,5
	rjmp L43
X11:
	.dbline 301
; /* 将数据放入缓冲器,发送数据 */
; UDR = data;
	out 0xc,R16
	.dbline -2
L42:
	.dbline 0 ; func end
	ret
	.dbsym r data 16 c
	.dbend
	.dbfunc e read_rom _read_rom fc
;       end_flag -> R10
;           num2 -> y+10
;            chr -> R12
;           flag -> y+0
;     flag_count -> R20
;            num -> y+20
;              i -> R22
;         retVal -> y+19
;           temp -> y+18
	.even
_read_rom::
	xcall push_xgsetF0FC
	sbiw R28,21
	.dbline -1
	.dbline 306
; } 
; 
; 
; 
; unsigned char read_rom(void){
	.dbline 308
;  unsigned char i;
;  unsigned char num=0;
	clr R0
	std y+20,R0
	.dbline 310
;  unsigned char num2[8];
;  unsigned char retVal=0;
	std y+19,R0
	.dbline 311
;  unsigned char temp=0;
	std y+18,R0
	.dbline 314
;  unsigned char chr;
;  unsigned char flag[10];
;  unsigned char flag_count=0;
	clr R20
	.dbline 315
;  unsigned char end_flag=0; 
	clr R10
	.dbline 316
;  B20_num=0;
	clr R2
	sts _B20_num,R2
L47:
	.dbline 318
;  

⌨️ 快捷键说明

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