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

📄 communication.s

📁 基于PIC单片机
💻 S
📖 第 1 页 / 共 5 页
字号:
	xcall _delay_nus
	.dbline 497
L255:
	.dbline 487
	inc R22
L257:
	.dbline 487
	cp R22,R20
	brlo L254
	.dbline 498
; 		 i2c_rd_buff[j-1]=TWDR;  //读取数
; 		 TWCR = (1<<TWEN)|                          // TWI Interface enabled
;                 (0<<TWIE)|(1<<TWINT)|               // Enable TWI Interupt and clear the flag to read next byte
;                 (1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|    // Send ACK after reception
;                 (0<<TWWC); 	
; 		 delay_nus(25);   //最低值! 
; 	 }	
; 	 if(TestAck()!= TWI_MRX_DATA_ACK  )  //ACK
	lds R24,113
	andi R24,248
	cpi R24,80
	breq L261
	.dbline 499
; 	     return 1;    //出错	
	ldi R16,1
	xjmp L243
L261:
	.dbline 500
;      i2c_rd_buff[num-1]=TWDR;  //读取数
	ldi R24,<_i2c_rd_buff-1
	ldi R25,>_i2c_rd_buff-1
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	lds R2,115
	std z+0,R2
	.dbline 501
; 	 TWCR = (1<<TWEN)|                          // TWI Interface enabled
	ldi R24,132
	sts 116,R24
	.dbline 505
;             (0<<TWIE)|(1<<TWINT)|               // Enable TWI Interupt and clear the flag to read next byte
;             (0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|    // Send NACK after reception
;             (0<<TWWC); 
; 	 delay_nus(25);	 //最低值!   
	ldi R16,25
	ldi R17,0
	xcall _delay_nus
	.dbline 506
; 	 if(TestAck()!= TWI_MRX_DATA_NACK )  //NACK
	lds R24,113
	andi R24,248
	cpi R24,88
	breq L264
	.dbline 507
; 	     return 1;    //出错		   
	ldi R16,1
	xjmp L243
L264:
	.dbline 508
; 	 Stop();   //I2C停止
	ldi R24,148
	sts 116,R24
	.dbline 509
; 	 return 0;   //整个过程正常时返回0	
	clr R16
	.dbline -2
L243:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r j 22 c
	.dbsym r num 20 c
	.dbsym r command 10 c
	.dbend
	.dbfunc e EEPROM_write _EEPROM_write fV
;           data -> R18
;        address -> R16,R17
	.even
_EEPROM_write::
	.dbline -1
	.dbline 515
; }
; 	
;                           //片内E2PROM的读写 自编
; //片内E2PROM写函数
; void EEPROM_write(unsigned int address,unsigned char data)
; {
L267:
	.dbline 517
L268:
	.dbline 516
;     while(EECR&(1<<EEWE))
	sbic 0x1c,1
	rjmp L267
	.dbline 518
; 	;
; 	EEAR=address;
	out 0x1f,R17
	out 0x1e,R16
	.dbline 519
; 	EEDR=data;
	out 0x1d,R18
	.dbline 520
; 	EECR|=(1<<EEMWE);
	sbi 0x1c,2
	.dbline 521
; 	EECR|=(1<<EEWE);
	sbi 0x1c,1
	.dbline -2
L266:
	.dbline 0 ; func end
	ret
	.dbsym r data 18 c
	.dbsym r address 16 i
	.dbend
	.dbfunc e EEPROM_read _EEPROM_read fc
;              i -> R20
;        address -> R16,R17
	.even
_EEPROM_read::
	xcall push_gset1
	.dbline -1
	.dbline 525
; }
; //片内E2PROM读函数
; unsigned char EEPROM_read(unsigned int address)
; {
L271:
	.dbline 528
L272:
	.dbline 527
;     uchar i;
;     while(EECR&(1<<EEWE))
	sbic 0x1c,1
	rjmp L271
	.dbline 529
; 	;
; 	EEAR=address;
	out 0x1f,R17
	out 0x1e,R16
	.dbline 530
; 	EECR|=(1<<EERE);
	sbi 0x1c,0
	.dbline 532
; 	//return EEDR;
; 	i=EEDR;
	in R20,0x1d
	.dbline 533
; 	return i;
	mov R16,R20
	.dbline -2
L270:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r address 16 i
	.dbend
	.area lit(rom, con, rel)
L275:
	.byte 1,2
	.byte 4,8
	.byte 16,32
	.byte 64,128
	.area text(rom, con, rel)
	.dbfile F:\AVR\zhulast\communication.c
	.dbfunc e atuo_search _atuo_search fV
;          temp2 -> R20
;          temp1 -> y+22
;        addrxyl -> y+21
;        addrxyh -> y+20
;         addrxy -> y+18
;              t -> y+16
;          temp6 -> R14
;          temp5 -> R12
;          temp4 -> R10
;          temp3 -> R22
;       xuanbit2 -> y+5
;              j -> y+15
;              i -> y+14
;              k -> y+13
	.even
_atuo_search::
	xcall push_gset5
	sbiw R28,23
	.dbline -1
	.dbline 538
; }	
; /***********************************************************************************/
; //自动搜索,存储下面接点的投用情况及投用类型
; void atuo_search(void)
; {
	.dbline 539
;     uint t=0;
	clr R0
	clr R1
	std y+17,R1
	std y+16,R0
	.dbline 540
;     uint addrxy=0;
	std y+19,R1
	std y+18,R0
	.dbline 541
; 	uchar addrxyh=0,addrxyl=0;
	std y+20,R0
	.dbline 541
	std y+21,R0
	.dbline 542
;     uchar k=0,i=0;
	std y+13,R0
	.dbline 542
	std y+14,R0
	.dbline 543
; 	uchar j=0;
	std y+15,R0
	.dbline 544
; 	uchar temp1=0,temp2=0;
	std y+22,R0
	.dbline 544
	clr R20
	.dbline 545
; 	uchar temp3=0,temp4=0,temp5=0,temp6=0;  //节点投用判断用
	clr R22
	.dbline 545
	clr R10
	.dbline 545
	clr R12
	.dbline 545
	clr R14
	.dbline 547
; 	//uchar autoc[5]={0xff,0xff,0xff,0xff,0xff};
; 	uchar xuanbit2[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
	ldi R24,<L275
	ldi R25,>L275
	movw R30,R28
	adiw R30,5
	ldi R16,8
	ldi R17,0
	st -y,R31
	st -y,R30
	st -y,R25
	st -y,R24
	xcall asgncblk
	.dbline 548
; 	for(k=0;k<4;k++)  //读取转换器的投用情况
	clr R0
	std y+13,R0
	xjmp L279
L276:
	.dbline 549
	.dbline 550
	ldd R16,y+13
	clr R17
	subi R16,248  ; offset = 8
	sbci R17,255
	xcall _EEPROM_read
	mov R2,R16
	ldi R24,<_canuse
	ldi R25,>_canuse
	ldd R30,y+13
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
	.dbline 551
	ldi R16,3
	ldi R17,0
	xcall _delay_nms
	.dbline 552
L277:
	.dbline 548
	ldd R0,y+13
	inc R0
	std y+13,R0
L279:
	.dbline 548
	ldd R24,y+13
	cpi R24,4
	brlo L276
	.dbline 553
; 	{
;         canuse[k]=EEPROM_read(0x0008+k)	  ;	
; 		delay_nms(3);
; 	}	
; 	for(fl=1;fl<=32;fl++)   //32个转换器  fu le
	ldi R24,1
	sts _fl,R24
	xjmp L283
L280:
	.dbline 554
; 	{
	.dbline 555
; 	    wdr();
	xcall _wdr
	.dbline 556
; 	    temp1=(fl-1)%8;  //余数
	ldi R17,8
	lds R16,_fl
	subi R16,1
	xcall mod8u
	std y+22,R16
	.dbline 557
; 		temp2=(fl-1)/8;  //商
	lds R20,_fl
	subi R20,1
	lsr R20
	lsr R20
	lsr R20
	.dbline 558
; 	    if((xuanbit2[temp1]&canuse[temp2])==0)      //表示对应的转换器投用
	ldi R24,<_canuse
	ldi R25,>_canuse
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	movw R24,R28
	adiw R24,5
	mov R30,R16
	clr R31
	add R30,R24
	adc R31,R25
	ldd R3,z+0
	and R3,R2
	breq X1
	xjmp L284
X1:
	.dbline 559
; 		{
	.dbline 560
; 		    write_MCP(TXB0SIDH,fl);         //接收方的地址
	lds R18,_fl
	ldi R16,49
	xcall _write_MCP
	.dbline 561
;    			write_MCP(TXB0SIDL,0x08);      //扩展帧格式   
	ldi R18,8
	ldi R16,50
	xcall _write_MCP
	.dbline 562
;    			write_MCP(TXB0EID8,0x00);         //标识发送方地址
	clr R18
	ldi R16,51
	xcall _write_MCP
	.dbline 563
;    			write_MCP(TXB0EID0,0x00);         //485节点地址
	clr R18
	ldi R16,52
	xcall _write_MCP
	.dbline 564
;    			write_MCP(TXB0DLC, 8);         //发送8个字节
	ldi R18,8
	ldi R16,53
	xcall _write_MCP
	.dbline 565
;    			write_MCP(TXB0D0, 0xab);  //命令字节1
	ldi R18,171
	ldi R16,54
	xcall _write_MCP
	.dbline 566
;    			write_MCP(TXB0D1, 0xba);  //命令字节2
	ldi R18,186
	ldi R16,55
	xcall _write_MCP
	.dbline 567
;    			write_MCP(TXB0D2, 0x00);         
	clr R18
	ldi R16,56
	xcall _write_MCP
	.dbline 568
;    			write_MCP(TXB0D3, 0x00);         
	clr R18
	ldi R16,57
	xcall _write_MCP
	.dbline 569
;    			write_MCP(TXB0D4, 0x00);         
	clr R18
	ldi R16,58
	xcall _write_MCP
	.dbline 570
;    			write_MCP(TXB0D5, 0x00);         
	clr R18
	ldi R16,59
	xcall _write_MCP
	.dbline 571
;    			write_MCP(TXB0D6, 0x00);         
	clr R18
	ldi R16,60
	xcall _write_MCP
	.dbline 572
;    			write_MCP(TXB0D7, 0x00);
	clr R18
	ldi R16,61
	xcall _write_MCP
	.dbline 573
; 			EIMSK&=~(1<<INT6) ;
	in R24,0x39
	andi R24,191
	out 0x39,R24
	.dbline 574
; 			UCSR1B&=~(1<<RXCIE1);  	
	lds R24,154
	andi R24,127
	sts 154,R24
	.dbline 575
; 			send_box_0();  //发送
	xcall _send_box_0
	.dbline 577
; 			//NOP();
; 			mcu_ok(1);   //灭
	ldi R16,1
	xcall _mcu_ok
	.dbline 578
; 			wdr();
	xcall _wdr
	.dbline 579
; 			delay_nms(1000);
	ldi R16,1000
	ldi R17,3
	xcall _delay_nms
	.dbline 580
; 			wdr();
	xcall _wdr
	.dbline 581
; 			delay_nms(1000);
	ldi R16,1000
	ldi R17,3
	xcall _delay_nms
	xjmp L287
L286:
	.dbline 583
; 			while(zhongbuff[0][2]!=0xac)    //一直等待
; 			{
	.dbline 584
; 			    t++;
	ldd R24,y+16
	ldd R25,y+17
	adiw R24,1
	std y+17,R25
	std y+16,R24
	.dbline 585
; 				if(t>65000)
	ldi R24,65000
	ldi R25,253
	ldd R0,y+16
	ldd R1,y+17
	cp R24,R0
	cpc R25,R1
	brsh L290
	.dbline 586
; 				{
	.dbline 587
; 				    t=0;
	clr R0
	clr R1
	std y+17,R1
	std y+16,R0
	.dbline 588
; 					break;
	xjmp L288
L290:
	.dbline 590
L287:
	.dbline 582
	lds R24,_zhongbuff+2
	cpi R24,172
	brne L286
L288:
	.dbline 591
; 				}
; 			}
; 			if( zhongbuff[0][2]==0xac)
	lds R24,_zhongbuff+2
	cpi R24,172
	breq X2
	xjmp L292
X2:
	.dbline 592
; 			{
	.dbline 593
; 			    t=0;
	clr R0
	clr R1
	std y+17,R1
	std y+16,R0
	.dbline 594
; 			    zhongbuff[0][2]=0;   	
	clr R2
	sts _zhongbuff+2,R2
	.dbline 595
; 				for(k=0;k<5;k++)
	std y+13,R0
	xjmp L299
L296:
	.dbline 596
	ldi R24,<_zhongbuff+3
	ldi R25,>_zhongbuff+3
	ldd R30,y+13
	clr R31
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldi R24,<_autoc
	ldi R25,>_autoc
	ldd R30,y+13
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
L297:
	.dbline 595
	ldd R0,y+13
	inc R0
	std y+13,R0
L299:
	.dbline 595
	ldd R24,y+13
	cpi R24,5
	brlo L296
	.dbline 600
; 			    	autoc[k]=zhongbuff[0][k+3];    //此转换器下接点的投用情况
; 			    //n可以作为对应转换器的地址	
; 			    //保存节点的投用情况及投用类型
; 			    //要做的工作
; 				for(k=0;k<6;k++)    //清零
	clr R0
	std y+13,R0
	xjmp L304
L301:
	.dbline 601
	ldi R24,<_zhongbuff+2
	ldi R25,>_zhongbuff+2
	ldd R30,y+13
	clr R31
	add R30,R24
	adc R31,R25
	clr R2
	std z+0,R2
L302:
	.dbline 600
	ldd R0,y+13
	inc R0
	std y+13,R0
L304:
	.dbline 600
	ldd R24,y+13
	cpi R24,6
	brlo L301
	.dbline 602
; 			        zhongbuff[0][k+2]=0;  	
; 			    for(k=0;k<4;k++)   //存节点的投用情况
	clr R0
	std y+13,R0
	xjmp L309
L306:
	.dbline 603
	ldi R24,<_autoc+1
	ldi R25,>_autoc+1
	ldd R30,y+13
	clr R31
	add R30,R24
	adc R31,R25
	ldd R18,z+0
	lds R2,_fl
	ldi R24,4
	mul R24,R2
	ldd R16,y+13
	clr R17
	subi R16,244  ; offset = 12
	sbci R17,255
	add R16,R0
	adc R17,R1
	xcall _EEPROM_write
L307:
	.dbline 602
	ldd R0,y+13
	inc R0
	std y+13,R0
L309:
	.dbline 602
	ldd R24,y+13
	cpi R24,4
	brlo L306
	.dbline 604
; 			        EEPROM_write(0x000c+k+fl*4,autoc[k+1]);
; 				EEPROM_write(0x0090+fl,autoc[0]);	
	lds R18,_autoc
	lds R16,_fl
	clr R17
	subi R16,112  ; offset = 144
	sbci R17,255
	xcall _EEPROM_write
	.dbline 605
; 			} 
L292:
	.dbline 606
; 			EIMSK|=(1<<INT6) ;
	in R24,0x39
	ori R24,64
	out 0x39,R24
	.dbline 607
; 			UCSR1B|=(1<<RXCIE1); 
	lds R24,154
	ori R24,128
	sts 154,R24
	.dbline 608
; 		}
L284:
	.dbline 609
	ldi R16,10
	ldi R17,0
	xcall _delay_nms
	.dbline 610
	clr R16
	xcall _mcu_ok
	.dbline 611
L281:
	.dbline 553
	lds R24,_fl
	subi R24,255    ; addi 1
	sts _fl,R24
L283:
	.dbline 553
	ldi R24,32
	lds R2,_fl
	cp R24,R2
	brlo X3
	xjmp L280
X3:
	.dbline 612
; 		delay_nms(10);
; 		mcu_ok(0);   //亮
; 	}	 
; 	for(k=0;k<33;k++)  //读取所有485节点的投用情况		
	clr R0
	std y+13,R0
	xjmp L314
L311:
	.dbline 613
; 	{
	.dbline 614
; 	    wdr();
	xcall _wdr
	.dbline 615
; 	    for(j=0;j<4;j++)
	clr R0
	std y+15,R0
	xjmp L318
L315:
	.dbline 616
	ldi R24,4
	ldd R0,y+13
	mul R24,R0
	ldd R16,y+15
	clr R17
	subi R16,244  ; offset = 12
	sbci R17,255
	add R16,R0
	adc R17,R1
	push R0
	push R1
	xcall _EEPROM_read
	pop R3
	pop R2
	mov R4,R16
	ldi R24,<_detuse
	ldi R25,>_detuse
	add R2,R24
	adc R3,R25
	ldd R30,y+15
	clr R31
	add R30,R2
	adc R31,R3
	std z+0,R4
L316:
	.dbline 615
	ldd R0,y+15
	inc R0
	std y+15,R0
L318:
	.dbline 615
	ldd R24,y+15
	cpi R24,4
	brlo L315
	.dbline 617
L312:
	.dbline 612
	ldd R0,y+13
	inc R0
	std y+13,R0
L314:
	.dbline 612
	ldd R24,y+13
	cpi R24,33
	brlo L311
	.dbline 618
; 	        detuse[k][j]= EEPROM_read(0x000c+j+k*4); 
; 	}	
; 	for(k=0;k<33;k++) //读取每个转换器下1-8#探测器 联动选择情况字节段	
	clr R0
	std y+13,R0
	xjmp L322
L319:
	.dbline 619
	ldd R16,y+13
	clr R17
	subi R16,112  ; offset = 144
	sbci R17,255
	xcall _EEPROM_read
	mov R2,R16
	ldi R24,<_det_link
	ldi R25,>_det_link
	ldd R30,y+13
	clr R31
	add R30,R24
	adc R31,R25
	std z+0,R2
L320:
	.dbline 618
	ldd R0,y+13
	inc R0
	std y+13,R0

⌨️ 快捷键说明

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