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

📄 zuopin.s

📁 18b20的程序
💻 S
字号:
	.module zuopin.c
	.area text(rom, con, rel)
	.dbfile K:\作品\新建文件夹\zuopin.c
	.dbfunc e delay_us _delay_us fV
	.even
_delay_us::
	.dbline -1
	.dbline 7
; // Target : M8
; // Crystal: 8.0000Mhz    //8M晶振
; #include <iom8v.h> 
; #include <macros.h> 
; 
; void delay_us()     //微秒延时程序(1us)
; {
	.dbline 8
;  asm("nop");
	nop
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay _delay fV
;           time -> R20,R21
	.even
_delay::
	rcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 11
; }	
; void delay(unsigned int time)    
; {
	rjmp L4
L3:
	.dbline 13
	.dbline 13
	rcall _delay_us
	.dbline 14
	subi R20,1
	sbci R21,0
	.dbline 15
L4:
	.dbline 12
; while(time)
	cpi R20,0
	cpc R20,R21
	brne L3
X0:
	.dbline -2
L2:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r time 20 i
	.dbend
	.dbfunc e init_1820 _init_1820 fV
	.even
_init_1820::
	.dbline -1
	.dbline 19
;   { delay_us();
;     time--;
;    }
; }	
;    
; void init_1820()    //初始化18b20
; {
	.dbline 20
;   PORTD|=0X80;   //总线置1
	sbi 0x12,7
	.dbline 21
;   delay(10);
	ldi R16,10
	ldi R17,0
	rcall _delay
	.dbline 22
;   PORTD&=~0x80;  //总线置0 
	cbi 0x12,7
	.dbline 23
;   delay(1200);    // 延时等待
	ldi R16,1200
	ldi R17,4
	rcall _delay
	.dbline 24
;   DDRD&=~0x80;  
	cbi 0x11,7
	.dbline 25
;   PORTD|=0x80;   //总线置1
	sbi 0x12,7
	.dbline 26
;   delay(50);   
	ldi R16,50
	ldi R17,0
	rcall _delay
	.dbline 27
;   DDRD|=0x80; 
	sbi 0x11,7
	.dbline 28
;   PORTD|=0x80; 
	sbi 0x12,7
	.dbline 29
;   delay(200);   
	ldi R16,200
	ldi R17,0
	rcall _delay
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e write_1820 _write_1820 fV
;              i -> R20
;           temp -> R22
	.even
_write_1820::
	rcall push_gset2
	mov R22,R16
	.dbline -1
	.dbline 32
; } 
; void write_1820(unsigned char temp)   //写数据
; {   
	.dbline 33
;   unsigned char i=0; 
	clr R20
	.dbline 34
;   for(;i<8;i++) 
	rjmp L11
L8:
	.dbline 35
;   { 
	.dbline 36
;     PORTD&=~0X80; 
	cbi 0x12,7
	.dbline 37
;     if(temp&(1<<i))   //写数据,从低位开始 
	ldi R16,1
	mov R17,R20
	rcall lsl8
	mov R2,R22
	and R2,R16
	breq L12
	.dbline 38
;     PORTD|=0X80; 
	sbi 0x12,7
	rjmp L13
L12:
	.dbline 40
;     else 
;     PORTD&=~0X80; 
	cbi 0x12,7
L13:
	.dbline 41
	ldi R16,50
	ldi R17,0
	rcall _delay
	.dbline 42
	sbi 0x12,7
	.dbline 43
L9:
	.dbline 34
	inc R20
L11:
	.dbline 34
	cpi R20,8
	brlo L8
	.dbline 44
;     delay(50);  
;     PORTD|=0X80; 
;   } 
;   PORTD|=0X80; 
	sbi 0x12,7
	.dbline -2
L7:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r temp 22 c
	.dbend
	.dbfunc e read_1820 _read_1820 fc
;              n -> R20
;              m -> R22
;              i -> R10
	.even
_read_1820::
	rcall push_gset3
	.dbline -1
	.dbline 48
; } 
; 
; unsigned char read_1820() //读数据
; {   
	.dbline 49
;  unsigned char m,i=0,n=0;     
	clr R10
	.dbline 49
	clr R20
	.dbline 50
;   for(;i<8;i++) 
	rjmp L18
L15:
	.dbline 51
;     { 
	.dbline 52
;     PORTD&=~0X80;
	cbi 0x12,7
	.dbline 53
; 	delay(5); 
	ldi R16,5
	ldi R17,0
	rcall _delay
	.dbline 54
;     PORTD|=0X80; 
	sbi 0x12,7
	.dbline 55
;     DDRD&=~0X80; 
	cbi 0x11,7
	.dbline 56
;     m=(PIND&0X80);   //读数据,从低位开始 
	in R22,0x10
	andi R22,128
	.dbline 57
;     if(m) 
	breq L19
	.dbline 58
;     n|=(1<<i); 
	ldi R16,1
	mov R17,R10
	rcall lsl8
	or R20,R16
	rjmp L20
L19:
	.dbline 60
;     else 
;     n&=~(1<<i); 
	ldi R16,1
	mov R17,R10
	rcall lsl8
	mov R2,R16
	com R2
	and R20,R2
L20:
	.dbline 61
	ldi R16,80
	ldi R17,0
	rcall _delay
	.dbline 62
	sbi 0x11,7
	.dbline 63
L16:
	.dbline 50
	inc R10
L18:
	.dbline 50
	mov R24,R10
	cpi R24,8
	brlo L15
	.dbline 64
;     delay(80); 
;     DDRD|=0X80; 
;   } 
;   return (n); 
	mov R16,R20
	.dbline -2
L14:
	rcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r n 20 c
	.dbsym r m 22 c
	.dbsym r i 10 c
	.dbend
	.dbfunc e temperature_read _temperature_read fV
;       tempture -> <dead>
;           teml -> R22
;           temh -> R20
;              i -> R20
	.even
_temperature_read::
	rcall push_gset2
	.dbline -1
	.dbline 67
; } 
; void temperature_read()  //读取温度值
; {
	.dbline 70
;   unsigned char tempture;
;   unsigned char i,temh,teml; 
;   init_1820();     //复位18b20 
	rcall _init_1820
	.dbline 71
;   write_1820(0xcc);   // 发出转换命令 
	ldi R16,204
	rcall _write_1820
	.dbline 72
;   write_1820(0x44);    //启动温度转换
	ldi R16,68
	rcall _write_1820
	.dbline 73
;   delay(400); 
	ldi R16,400
	ldi R17,1
	rcall _delay
	.dbline 74
;   init_1820();    
	rcall _init_1820
	.dbline 75
;   write_1820(0xcc); //发出读命令 
	ldi R16,204
	rcall _write_1820
	.dbline 76
;   write_1820(0xbe);  //读数据
	ldi R16,190
	rcall _write_1820
	.dbline 77
;   teml=read_1820(); 
	rcall _read_1820
	mov R22,R16
	.dbline 78
;   temh=read_1820(); 
	rcall _read_1820
	mov R20,R16
	.dbline 79
;   UDR=teml;
	out 0xc,R22
	.dbline 80
;   delay(150);
	ldi R16,150
	ldi R17,0
	rcall _delay
	.dbline 81
;   UDR=temh;
	out 0xc,R20
	.dbline 82
;   for(i=0;i<100;i++)   //延时等待
	clr R20
	rjmp L25
L22:
	.dbline 83
	ldi R16,500
	ldi R17,1
	rcall _delay
L23:
	.dbline 82
	inc R20
L25:
	.dbline 82
	cpi R20,100
	brlo L22
	.dbline -2
L21:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l tempture 1 c
	.dbsym r teml 22 c
	.dbsym r temh 20 c
	.dbsym r i 20 c
	.dbend
	.dbfunc e uart0_init _uart0_init fV
	.even
_uart0_init::
	.dbline -1
	.dbline 91
;   delay(500);     
; }
; //UART0 initialize
; // desired baud rate: 9600
; // actual: baud rate:9615 (0.2%)
; // char size: 8 bit
; // parity: Disabled
; void uart0_init(void)     //初始化uart
; {
	.dbline 92
;  UCSRB = 0x00; //disable while setting baud rate
	clr R2
	out 0xa,R2
	.dbline 93
;  UCSRA = 0x00;
	out 0xb,R2
	.dbline 94
;  UCSRC = BIT(URSEL) | 0x06;
	ldi R24,134
	out 0x20,R24
	.dbline 95
;  UBRRL = 0x33; //set baud rate lo
	ldi R24,51
	out 0x9,R24
	.dbline 96
;  UBRRH = 0x00; //set baud rate hi
	out 0x20,R2
	.dbline 97
;  UCSRB = 0x18;
	ldi R24,24
	out 0xa,R24
	.dbline -2
L26:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 101
; }
; 
; void main(void) //主函数 
; { 
	.dbline 102
; delay(1000); 
	ldi R16,1000
	ldi R17,3
	rcall _delay
	.dbline 103
; DDRD=0Xff; 
	ldi R24,255
	out 0x11,R24
	.dbline 104
; PORTD=0Xff; 
	out 0x12,R24
	.dbline 105
; uart0_init();
	rcall _uart0_init
	rjmp L29
L28:
	.dbline 107
	rcall _temperature_read
L29:
	.dbline 106
	rjmp L28
X1:
	.dbline -2
L27:
	.dbline 0 ; func end
	ret
	.dbend

⌨️ 快捷键说明

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