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

📄 ds18b20.s

📁 DS18B20温度监控程序
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module ds18b20.c
	.area text(rom, con, rel)
	.dbfile ..\..\..\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.area vector(rom, abs)
	.org 32
	rjmp _display_int
	.area text(rom, con, rel)
	.dbfile ..\..\..\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.area data(ram, con, rel)
	.dbfile ..\..\..\VB01D6~1\ComTest\DS18b20\ds18b20.c
_distable::
	.blkb 2
	.area idata
	.byte 39,47
	.area data(ram, con, rel)
	.dbfile ..\..\..\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.blkb 2
	.area idata
	.byte 55,63
	.area data(ram, con, rel)
	.dbfile ..\..\..\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.blkb 2
	.area idata
	.byte 'g,'o
	.area data(ram, con, rel)
	.dbfile ..\..\..\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.blkb 2
	.area idata
	.byte 'w,127
	.area data(ram, con, rel)
	.dbfile ..\..\..\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.blkb 2
	.area idata
	.byte 167,175
	.area data(ram, con, rel)
	.dbfile ..\..\..\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.dbfile E:\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.dbsym e distable _distable A[10:10]c
_count2::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.dbsym e count2 _count2 c
_count1::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.dbsym e count1 _count1 c
	.area vector(rom, abs)
	.org 26
	rjmp _timer1_int
	.area data(ram, con, rel)
	.dbfile E:\VB01D6~1\ComTest\DS18b20\ds18b20.c
_count3::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.dbsym e count3 _count3 c
_flag1::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.dbsym e flag1 _flag1 c
	.area vector(rom, abs)
	.org 36
	rjmp _UartRece_int
	.area data(ram, con, rel)
	.dbfile E:\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.area text(rom, con, rel)
	.dbfile E:\VB01D6~1\ComTest\DS18b20\ds18b20.c
	.dbfunc e main _main fI
;          tempL -> R10
;          tempH -> R12
	.even
_main::
	.dbline -1
	.dbline 51
; /*************************************
;           ds18b20测温程序
; 文 件 名    :ds18b20.c				 
; 设    计    :毕京鹏					 
; 最后修改日期:2008.11.13		 
; 版    本    :V1.0				 	 
; 主控芯片    :ATMEGA48V					 
; 工作频率    :外部16MHz晶振
; 备注        : 初步:实时测温并显示
;               1.读数据时的处理方式
; 			  2.数据口上需带上拉(5.1K)
; 			  3.配置成9位时后三位始终为0,以此类推
; 			  4.1s更新一次
; *************************************/
; #include<iom48v.h>
; #include<macros.h>
; 
; #define uchar unsigned char
; #define uint  unsigned int
; /*DQ 接在PC0上*/
; #define  DQ(x)  x ? (PORTC |= 0x01) : (PORTC &= 0xfe)
; #define  DRC(y)  y ? (DDRC |= 0x01 ) : (DDRC &= 0xfe)
; uchar flag;
; void Init_1wire(void);
; void WriteByte_1wire(uchar data);
; uchar ReadByte_1wire(void);
; 
; void PortInit(void);
; void delay_1us(void); 
; void delay_10us(uchar n);
; /*显示有关*/
; #pragma interrupt_handler display_int:17
; const uchar distable[]={0x27,0x2f,0x37,0x3f,0x67,0x6f,0x77,0x7f,0xa7,0xaf};
;                       // 0    1    2    3    4     5   6     7    8    9
; uchar time1,time2;
; uchar count2=0;
; uchar timeb1,timeb2,timeb3,timeb4,timeb5,timeb6;
; void convert(void);
; /*定时有关*/
; uchar count1=0;
; #pragma interrupt_handler timer1_int:14
; /*通信有关*/
; uchar Rece[2],Send[3];
; uchar count3=0;
; uchar flag1=0;
; void UartInit(void);
; void UartSend(uchar a[],uchar length);
; #pragma interrupt_handler UartRece_int:19
; /*******************主函数********************************/
; main()
; { uchar tempH,tempL;
	.dbline 52
;   PortInit();
	rcall _PortInit
	.dbline 54
;   /***********此部分在初次配置完成后可略去*****************/
;   Init_1wire(); 
	rcall _Init_1wire
	.dbline 55
;   WriteByte_1wire(0xcc);
	ldi R16,204
	rcall _WriteByte_1wire
	.dbline 56
;   WriteByte_1wire(0x4e);   //Write Scratchpad
	ldi R16,78
	rcall _WriteByte_1wire
	.dbline 57
;   WriteByte_1wire(0x7f);   //TH
	ldi R16,127
	rcall _WriteByte_1wire
	.dbline 58
;   WriteByte_1wire(0xff);   //TL
	ldi R16,255
	rcall _WriteByte_1wire
	.dbline 59
;   WriteByte_1wire(0x1f);   //CONFIGURATION REGISTER  9位
	ldi R16,31
	rcall _WriteByte_1wire
	.dbline 61
;   
;   Init_1wire(); 
	rcall _Init_1wire
	.dbline 62
;   WriteByte_1wire(0xcc);
	ldi R16,204
	rcall _WriteByte_1wire
	.dbline 63
;   WriteByte_1wire(0x48);  //Copy Scratchpad
	ldi R16,72
	rcall _WriteByte_1wire
	.dbline 65
;   /***********************************************/
;   SEI();
	sei
	rjmp L3
L2:
	.dbline 67
;   while(1)
;     {if(count1==100)
	.dbline 67
	lds R24,_count1
	cpi R24,100
	brne L5
X0:
	.dbline 68
; 	   {count1=0;
	.dbline 68
	clr R2
	sts _count1,R2
	.dbline 69
; 	    Init_1wire();
	rcall _Init_1wire
	.dbline 70
;   		WriteByte_1wire(0xcc);
	ldi R16,204
	rcall _WriteByte_1wire
	.dbline 71
;   		WriteByte_1wire(0x44);
	ldi R16,68
	rcall _WriteByte_1wire
	.dbline 72
;   		DRC(0);                       //判断转换是否完成
	in R24,0x7
	andi R24,254
	out 0x7,R24
	.dbline 73
;   		if(!(PINC&0x01));
	sbic 0x6,0
	rjmp L7
X1:
	.dbline 73
L7:
	.dbline 74
;   		Init_1wire();
	rcall _Init_1wire
	.dbline 75
;   		WriteByte_1wire(0xcc);
	ldi R16,204
	rcall _WriteByte_1wire
	.dbline 76
;   		WriteByte_1wire(0xbe);
	ldi R16,190
	rcall _WriteByte_1wire
	.dbline 77
;   		tempL = ReadByte_1wire();
	rcall _ReadByte_1wire
	mov R10,R16
	.dbline 78
;   		tempH = ReadByte_1wire();
	rcall _ReadByte_1wire
	mov R12,R16
	.dbline 80
;  
;   		time1=tempH;
	sts _time1,R12
	.dbline 81
;   		time2=tempL;
	sts _time2,R10
	.dbline 82
;   		convert();
	rcall _convert
	.dbline 83
; 	   }
L5:
	.dbline 84
; 	 if(flag1==1)
	lds R24,_flag1
	cpi R24,1
	brne L9
X2:
	.dbline 85
; 	   {flag1=0;
	.dbline 85
	clr R2
	sts _flag1,R2
	.dbline 86
; 	    if((Rece[0]=='S')&&(Rece[1]=='T'))
	lds R24,_Rece
	cpi R24,83
	brne L11
X3:
	lds R24,_Rece+1
	cpi R24,84
	brne L11
X4:
	.dbline 87
; 		  {Send[0]='#';
	.dbline 87
	ldi R24,35
	sts _Send,R24
	.dbline 88
; 		   Send[1]=tempH;
	sts _Send+1,R12
	.dbline 89
; 		   Send[2]=tempL;
	sts _Send+2,R10
	.dbline 90
; 		   UartSend(Send,3);            //向上位机发送数据
	ldi R18,3
	ldi R16,<_Send
	ldi R17,>_Send
	rcall _UartSend
	.dbline 91
; 		  }
L11:
	.dbline 92
; 	   }  
L9:
	.dbline 93
; 	}
L3:
	.dbline 66
	rjmp L2
X5:
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbsym r tempL 10 c
	.dbsym r tempH 12 c
	.dbend
	.dbfunc e timer1_int _timer1_int fV
	.even
_timer1_int::
	st -y,R24
	st -y,R25
	IN R24,63
	st -y,R24
	.dbline -1
	.dbline 98
; }
; /*******************中断函数****************************/
; /*定时中断*/
; void timer1_int(void)
; {TCNT1=0xfd8f; //重赋初值
	.dbline 98
	ldi R24,64911
	ldi R25,253
	sts 132+1,R25
	sts 132,R24
	.dbline 99
;  if(count1!=100)count1++;
	lds R24,_count1
	cpi R24,100
	breq L17
X6:
	.dbline 99
	subi R24,255    ; addi 1
	sts _count1,R24
L17:
	.dbline -2
L16:
	.dbline 0 ; func end
	ld R24,y+
	OUT 63,R24
	ld R25,y+
	ld R24,y+
	reti
	.dbend
	.dbfunc e display_int _display_int fV
	.even
_display_int::
	st -y,R2
	st -y,R3
	st -y,R16
	st -y,R17
	st -y,R24
	st -y,R25
	st -y,R26
	st -y,R30
	st -y,R31
	IN R2,63
	st -y,R2
	.dbline -1
	.dbline 103
; }
; /*显示中断*/
; void display_int(void)
; {count2++;
	.dbline 103
	lds R24,_count2
	subi R24,255    ; addi 1
	sts _count2,R24
	.dbline 104
;  TCNT0=0xce;  //重赋初值
	ldi R24,206
	out 0x26,R24
	.dbline 105
;  PORTC|=0x0e;  //0000 1110
	in R24,0x8
	ori R24,14
	out 0x8,R24
	.dbline 106
;  PORTD|=0xd8; //1101 1000
	in R24,0xb
	ori R24,216
	out 0xb,R24
	.dbline 107
;  switch(count2)
	lds R16,_count2
	clr R17
	cpi R16,1
	ldi R30,0
	cpc R17,R30
	breq L23
X7:
	cpi R16,2
	ldi R30,0
	cpc R17,R30
	breq L24
X8:
	cpi R16,3
	ldi R30,0
	cpc R17,R30
	breq L25
X9:
	cpi R16,4
	ldi R30,0
	cpc R17,R30
	brne X13
	rjmp L26
X13:
X10:
	cpi R16,5
	ldi R30,0
	cpc R17,R30
	brne X14
	rjmp L27
X14:
X11:
	cpi R16,6
	ldi R30,0
	cpc R17,R30
	brne X15
	rjmp L28
X15:
X12:
	rjmp L20
L23:
	.dbline 109
;  {case 1:
;   	   PORTC&=0xf1; //L6  1111 0001
	in R24,0x8
	andi R24,241
	out 0x8,R24
	.dbline 110
;   	   PORTD&=distable[timeb6];
	ldi R24,<_distable
	ldi R25,>_distable
	lds R30,_timeb6
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	in R3,0xb
	and R3,R2
	out 0xb,R3
	.dbline 111
;   	   break;
	rjmp L21
L24:
	.dbline 113
;   case 2:
;   	   PORTC&=0xf3; //L5  1111 0011
	in R24,0x8
	andi R24,243
	out 0x8,R24
	.dbline 114
;  	   PORTD&=distable[timeb5];
	ldi R24,<_distable
	ldi R25,>_distable
	lds R30,_timeb5
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	in R3,0xb
	and R3,R2
	out 0xb,R3
	.dbline 115
;  	   break;
	rjmp L21
L25:
	.dbline 117
;   case 3:
;   	   PORTC&=0xf5; //L4  1111 0101
	in R24,0x8
	andi R24,245
	out 0x8,R24
	.dbline 118
;  	   PORTD&=distable[timeb4];
	ldi R24,<_distable
	ldi R25,>_distable
	lds R30,_timeb4
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	in R3,0xb
	and R3,R2
	out 0xb,R3
	.dbline 119
;  	   break;
	rjmp L21
L26:
	.dbline 121
;   case 4:
;        PORTC&=0xf7; //L3  1111 0111
	in R24,0x8
	andi R24,247
	out 0x8,R24
	.dbline 122
;  	   PORTD&=distable[timeb3];
	ldi R24,<_distable
	ldi R25,>_distable
	lds R30,_timeb3
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	in R3,0xb
	and R3,R2
	out 0xb,R3
	.dbline 123
;  	   break;
	rjmp L21
L27:
	.dbline 125
;   case 5:
;        PORTC&=0xf9; //L2  1111 1001
	in R24,0x8
	andi R24,249
	out 0x8,R24
	.dbline 126
;  	   PORTD&=distable[timeb2];
	ldi R24,<_distable
	ldi R25,>_distable
	lds R30,_timeb2
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	in R3,0xb
	and R3,R2
	out 0xb,R3
	.dbline 127
;  	   break;
	rjmp L21
L28:
	.dbline 129
;   case 6:
;        count2=0;
	clr R2
	sts _count2,R2
	.dbline 130
;   	   PORTC&=0xfb; //L1  1111 1011
	in R24,0x8
	andi R24,251
	out 0x8,R24
	.dbline 131
;  	   PORTD&=distable[timeb1];
	ldi R24,<_distable
	ldi R25,>_distable
	lds R30,_timeb1
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	in R3,0xb
	and R3,R2
	out 0xb,R3
	.dbline 132
;  	   break;	      
L20:
L21:
	.dbline -2
L19:
	.dbline 0 ; func end
	ld R2,y+
	OUT 63,R2
	ld R31,y+
	ld R30,y+
	ld R26,y+
	ld R25,y+
	ld R24,y+
	ld R17,y+
	ld R16,y+
	ld R3,y+
	ld R2,y+
	reti
	.dbend
	.dbfunc e PortInit _PortInit fV
	.even
_PortInit::
	.dbline -1
	.dbline 138
;  }
; }
; /*******************子函数***********************************/
; /*端口及中断初始化*/
; void PortInit(void)
; {DDRC = 0xff;
	.dbline 138
	ldi R24,255
	out 0x7,R24
	.dbline 139
;  PORTC=0xff;
	out 0x8,R24
	.dbline 140
;  DDRD=0xff;
	out 0xa,R24
	.dbline 141
;  PORTD=0x00;
	clr R2
	out 0xb,R2
	.dbline 143
;  /*T/C0*/
;  TCCR0A=0x00;
	out 0x24,R2
	.dbline 144
;  TIMSK0=0x01;
	ldi R24,1
	sts 110,R24
	.dbline 145
;  TCNT0=0xce;  //  (1024/16,000,000)*50=3.2ms
	ldi R24,206
	out 0x26,R24
	.dbline 146
;  TCCR0B=0x05; //   clk/1024
	ldi R24,5
	out 0x25,R24
	.dbline 148
;  /*T/C1*/
;  TCCR1A=0x00;
	sts 128,R2
	.dbline 149
;  TIMSK1=0x01;
	ldi R24,1
	sts 111,R24
	.dbline 150
;  TCNT1=0xfd8f;  //10ms
	ldi R24,64911
	ldi R25,253
	sts 132+1,R25
	sts 132,R24
	.dbline 151
;  TCCR1B=0x04; //  clk/256

⌨️ 快捷键说明

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