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

📄 communication.s

📁 基于PIC单片机
💻 S
📖 第 1 页 / 共 5 页
字号:
	.module communication.c
	.area data(ram, con, rel)
_errorflag::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile F:\AVR\zhulast\communication.c
	.dbsym e errorflag _errorflag c
_fl::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile F:\AVR\zhulast\communication.c
	.dbsym e fl _fl c
_nnn::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile F:\AVR\zhulast\communication.c
	.dbsym e nnn _nnn c
	.area text(rom, con, rel)
	.dbfile F:\AVR\zhulast\communication.c
	.dbfunc e delay_1us _delay_1us fV
	.even
_delay_1us::
	.dbline -1
	.dbline 25
; /*******************************************************************/
; #include "allhead.h"
; 
; uchar tx_buff[12];              //存放要发向转换器的数
; uchar  errorflag  = 0;                                     //485出错
; uchar fl=0;             //服了(fule),自动搜索用!
; extern uchar can_cuo_flag[32];                  //转换器故障 用
; //TWI 相关全局变量
; uchar i2c_rd_buff[32];   //i2c读出的数最初存放的地方
; uchar i2c_wt_buff[35];   //写
; uchar fhz;               //读写完返回值0或1
; uchar autoc[5];
; 
; uchar nnn=0;
; extern uchar canuse[4];
; extern uchar zhongbuff[33][10];
; extern uchar detuse[33][4];
; extern uchar det_link[33];
; extern uchar keyc;
; extern uchar jiemian;
; extern uchar denglu;
; extern uchar gal3data;
; //延时1us;晶振为8M时1us延时函数
; void delay_1us(void)
; {
	.dbline 26
;   asm("nop");
	nop
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay_nus _delay_nus fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nus::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 30
; }
; //延时n us
; void delay_nus(unsigned int n)
; {
	.dbline 32
;   unsigned int i;
;   for(i=0;i<n;i++)
	clr R20
	clr R21
	xjmp L6
L3:
	.dbline 33
	xcall _delay_1us
L4:
	.dbline 32
	subi R20,255  ; offset = 1
	sbci R21,255
L6:
	.dbline 32
	cp R20,R22
	cpc R21,R23
	brlo L3
	.dbline -2
L2:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e delay_1ms _delay_1ms fV
;              i -> R16,R17
	.even
_delay_1ms::
	.dbline -1
	.dbline 37
;     delay_1us();
; } 
; //延时1ms;
; void delay_1ms(void)
; {
	.dbline 39
;   unsigned int i;
;   for(i=1;i<(unsigned int)(xtal*143-2);i++)
	ldi R16,1
	ldi R17,0
	xjmp L11
L8:
	.dbline 40
L9:
	.dbline 39
	subi R16,255  ; offset = 1
	sbci R17,255
L11:
	.dbline 39
	cpi R16,43
	ldi R30,6
	cpc R17,R30
	brlo L8
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e delay_nms _delay_nms fV
;              j -> R20,R21
;              n -> R22,R23
	.even
_delay_nms::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 44
;   ;
; }
; //延时n ms
; void delay_nms(unsigned int n)
; {
	.dbline 46
;   unsigned int j;
;   wdr();
	xcall _wdr
	.dbline 47
;   for(j=0;j<n;j++)
	clr R20
	clr R21
	xjmp L16
L13:
	.dbline 48
	xcall _delay_1ms
L14:
	.dbline 47
	subi R20,255  ; offset = 1
	sbci R21,255
L16:
	.dbline 47
	cp R20,R22
	cpc R21,R23
	brlo L13
	.dbline -2
L12:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r j 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e reset_MCP _reset_MCP fV
	.even
_reset_MCP::
	.dbline -1
	.dbline 52
;     delay_1ms();
; }
; //复位MCP
; void reset_MCP(void)
; {  
	.dbline 54
;   //unsigned char 
;   PORTB&=~(1<<CS_CAN);			 //	CS  Low -> MCP enable
	cbi 0x18,0
	.dbline 55
;   SPDR=RESET_MCP;			    //	send Reset command
	ldi R24,192
	out 0xf,R24
L18:
	.dbline 57
L19:
	.dbline 56
;   while(!(SPSR & (1<<SPIF)))
	sbis 0xe,7
	rjmp L18
	.dbline 58
;   ; 	                       //	wait
;   PORTB|=(1<<CS_CAN);		  //	CS  High -> MCP disable
	sbi 0x18,0
	.dbline 59
;   delay_1ms();		         //	waiting
	xcall _delay_1ms
	.dbline -2
L17:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e write_MCP _write_MCP fV
;          value -> R18
;         adress -> R16
	.even
_write_MCP::
	.dbline -1
	.dbline 63
; }
; //写函数
; void write_MCP(unsigned char adress, unsigned char value)
; {
	.dbline 64
;   PORTB&=~(1<<CS_CAN);				//	CS  Low -> MCP enable
	cbi 0x18,0
	.dbline 65
;   SPDR=0x02;					//	sende Write command
	ldi R24,2
	out 0xf,R24
L22:
	.dbline 66
L23:
	.dbline 66
;   while(!(SPSR & (1<<SPIF)));	//	warten bis das Byte gesendet wurde
	sbis 0xe,7
	rjmp L22
	.dbline 67
;   SPDR=adress;					//	Addresse senden
	out 0xf,R16
L25:
	.dbline 68
L26:
	.dbline 68
;   while(!(SPSR & (1<<SPIF)));	//	warten bis das Byte gesendet wurde
	sbis 0xe,7
	rjmp L25
	.dbline 69
;   SPDR=value;					//	Wert senden
	out 0xf,R18
L28:
	.dbline 70
L29:
	.dbline 70
;   while(!(SPSR & (1<<SPIF)));	//	warten bis das Byte gesendet wurde
	sbis 0xe,7
	rjmp L28
	.dbline 71
;   PORTB|=(1<<CS_CAN);					//	CS  High -> MCP disable
	sbi 0x18,0
	.dbline -2
L21:
	.dbline 0 ; func end
	ret
	.dbsym r value 18 c
	.dbsym r adress 16 c
	.dbend
	.dbfunc e read_MCP _read_MCP fc
;        spidata -> R20
;         adress -> R16
	.even
_read_MCP::
	xcall push_gset1
	.dbline -1
	.dbline 75
; }
; //读函数
; unsigned char read_MCP(unsigned char adress)
; {
	.dbline 77
; 	unsigned char spidata;
; 	PORTB&=~(1<<CS_CAN);				//	CS  Low -> MCP enable
	cbi 0x18,0
	.dbline 78
; 	SPDR=0x03;					//	sende Read command
	ldi R24,3
	out 0xf,R24
L32:
	.dbline 79
L33:
	.dbline 79
; 	while(!(SPSR&(1<<SPIF)));	//	wait
	sbis 0xe,7
	rjmp L32
	.dbline 80
; 	SPDR=adress;					//	adress send
	out 0xf,R16
L35:
	.dbline 81
L36:
	.dbline 81
; 	while(!(SPSR&(1<<SPIF)));	//	wait
	sbis 0xe,7
	rjmp L35
	.dbline 82
; 	SPDR=0xAA;					//	不懂
	ldi R24,170
	out 0xf,R24
L38:
	.dbline 83
L39:
	.dbline 83
; 	while(!(SPSR&(1<<SPIF)));	//	wait
	sbis 0xe,7
	rjmp L38
	.dbline 84
; 	spidata = SPDR;				//	Data return
	in R20,0xf
	.dbline 85
; 	PORTB|=(1<<CS_CAN);				//	CS  High -> MCP disable
	sbi 0x18,0
	.dbline 86
; 	return (spidata);
	mov R16,R20
	.dbline -2
L31:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r spidata 20 c
	.dbsym r adress 16 c
	.dbend
	.dbfunc e bit_modify _bit_modify fV
;          value -> R20
;             cc -> R18
;         adress -> R16
	.even
_bit_modify::
	xcall push_gset1
	ldd R20,y+2
	.dbline -1
	.dbline 90
; }
; //位调整函数
; void bit_modify(unsigned char adress,unsigned char cc, unsigned char value)
; {  
	.dbline 91
;     PORTB&=~(1<<CS_CAN);		   //	CS  Low -> MCP enable
	cbi 0x18,0
	.dbline 92
;     SPDR=0x05;					   //	bit modify Write command
	ldi R24,5
	out 0xf,R24
L42:
	.dbline 93
L43:
	.dbline 93
; 	while(!(SPSR & (1<<SPIF)));	   //	
	sbis 0xe,7
	rjmp L42
	.dbline 94
; 	SPDR=adress;				   //	sende Write command
	out 0xf,R16
L45:
	.dbline 95
L46:
	.dbline 95
; 	while(!(SPSR & (1<<SPIF)));	   //	
	sbis 0xe,7
	rjmp L45
	.dbline 96
; 	SPDR=cc;					   //	sende Write command
	out 0xf,R18
L48:
	.dbline 97
L49:
	.dbline 97
; 	while(!(SPSR & (1<<SPIF)));	   //	warten bis das Byte gesendet wurde
	sbis 0xe,7
	rjmp L48
	.dbline 98
; 	SPDR=value;					  //	sende Write command
	out 0xf,R20
L51:
	.dbline 99
L52:
	.dbline 99
; 	while(!(SPSR & (1<<SPIF)));	 //	
	sbis 0xe,7
	rjmp L51
	.dbline 100
;     PORTB|=(1<<CS_CAN);					//	CS  High -> MCP disable
	sbi 0x18,0
	.dbline -2
L41:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r value 20 c
	.dbsym r cc 18 c
	.dbsym r adress 16 c
	.dbend
	.dbfunc e send_box_0 _send_box_0 fV
	.even
_send_box_0::
	.dbline -1
	.dbline 104
; }
;  //发送缓冲器0
; void send_box_0(void)   //此处好像应该加发送缓冲器空标志查询!!!!!
; {
	.dbline 105
; 	write_MCP (TXB0CTRL, 0x0B);			//	sende Telegramm mit h鯿hster Priori
	ldi R18,11
	ldi R16,48
	xcall _write_MCP
	.dbline 107
; 	//0x0B--缓冲区等待报文发送,最高的报文发送优先级
; 	PORTB&=~(1<<CS_CAN);				//	CS  Low -> MCP enable
	cbi 0x18,0
	.dbline 108
; 	SPDR=(RTS | 0x01);			//	sende Mailbox Nummer 0
	ldi R24,129
	out 0xf,R24
L55:
	.dbline 109
L56:
	.dbline 109
; 	while(!(SPSR & (1<<SPIF)));	//	warten bis das Byte gesendet wurde
	sbis 0xe,7
	rjmp L55
	.dbline 110
; 	PORTB|=(1<<CS_CAN);					//	CS  High -> MCP disable
	sbi 0x18,0
	.dbline -2
L54:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e remotesend _remotesend fV
;        id_addr -> R20
	.even
_remotesend::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 114
; }
; //数据请求数据帧函数
; void remotesend(uchar id_addr)
; {
	.dbline 115
;     NOP();
	nop
	.dbline 116
;     write_MCP(TXB0SIDH,id_addr);//接收方的地址,
	mov R18,R20
	ldi R16,49
	xcall _write_MCP
	.dbline 118
;    // write_MCP(TXB0SIDL,0x48);   //扩展帧格式 且4就表示是发送请求命令
; 	write_MCP(TXB0SIDL,0xc8);   //扩展帧格式 且4就表示是发送请求命令
	ldi R18,200
	ldi R16,50
	xcall _write_MCP
	.dbline 119
;     write_MCP(TXB0EID8,0x00);   //标识发送方地址主控制器为0x00
	clr R18
	ldi R16,51
	xcall _write_MCP
	.dbline 120
;     write_MCP(TXB0EID0,0x00);   //   
	clr R18
	ldi R16,52
	xcall _write_MCP
	.dbline 121
;     write_MCP(TXB0DLC, 0x08);    //发送8个字节
	ldi R18,8
	ldi R16,53
	xcall _write_MCP
	.dbline 122
;     write_MCP(TXB0D0,  0x00);  //
	clr R18
	ldi R16,54
	xcall _write_MCP
	.dbline 123
;     write_MCP(TXB0D1,  0x00);  //
	clr R18
	ldi R16,55
	xcall _write_MCP
	.dbline 124
;     write_MCP(TXB0D2,  0x00);  //
	clr R18
	ldi R16,56
	xcall _write_MCP
	.dbline 125
;     write_MCP(TXB0D3,  0x00);  //
	clr R18
	ldi R16,57
	xcall _write_MCP
	.dbline 126
;     write_MCP(TXB0D4,  0x00);  //
	clr R18
	ldi R16,58
	xcall _write_MCP
	.dbline 127
;     write_MCP(TXB0D5,  0x00);  //
	clr R18
	ldi R16,59
	xcall _write_MCP
	.dbline 128
;     write_MCP(TXB0D6,  0x00);  //
	clr R18
	ldi R16,60
	xcall _write_MCP
	.dbline 129
;     write_MCP(TXB0D7,  0x00);
	clr R18
	ldi R16,61
	xcall _write_MCP
	.dbline 130
; 	send_box_0();
	xcall _send_box_0
	.dbline 131
; 	NOP();
	nop
	.dbline -2
L58:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r id_addr 20 c
	.dbend
	.dbfunc e fill_msg_box_0 _fill_msg_box_0 fV
	.even
_fill_msg_box_0::
	.dbline -1
	.dbline 135
; }
; //装载报文 TXB0
; void fill_msg_box_0(void)
; {  
	.dbline 136
;    tx_buff[9]=8;   
	ldi R24,8
	sts _tx_buff+9,R24
	.dbline 137
;    write_MCP(TXB0SIDH,tx_buff[1]);         //接收方的地址
	lds R18,_tx_buff+1
	ldi R16,49
	xcall _write_MCP
	.dbline 138
;    write_MCP(TXB0SIDL,tx_buff[7]);         //扩展帧格式   
	lds R18,_tx_buff+7
	ldi R16,50
	xcall _write_MCP
	.dbline 139
;    write_MCP(TXB0EID8,tx_buff[8]);         //标识发送方地址
	lds R18,_tx_buff+8
	ldi R16,51
	xcall _write_MCP
	.dbline 140
;    write_MCP(TXB0EID0,tx_buff[2]);         //485节点地址
	lds R18,_tx_buff+2
	ldi R16,52
	xcall _write_MCP
	.dbline 141
;    write_MCP(TXB0DLC, tx_buff[9]);         //发送8个字节
	lds R18,_tx_buff+9
	ldi R16,53
	xcall _write_MCP
	.dbline 142
;    write_MCP(TXB0D0,  tx_buff[2]);         //485NA节点地址
	lds R18,_tx_buff+2
	ldi R16,54
	xcall _write_MCP
	.dbline 143
;    write_MCP(TXB0D1,  tx_buff[0]);         //命令字节
	lds R18,_tx_buff
	ldi R16,55
	xcall _write_MCP
	.dbline 144
;    write_MCP(TXB0D2,  tx_buff[3]);         //高报点高字节
	lds R18,_tx_buff+3
	ldi R16,56
	xcall _write_MCP
	.dbline 145
;    write_MCP(TXB0D3,  tx_buff[4]);         //高报点低字节
	lds R18,_tx_buff+4
	ldi R16,57
	xcall _write_MCP
	.dbline 146
;    write_MCP(TXB0D4,  tx_buff[5]);         //低报点高字节
	lds R18,_tx_buff+5
	ldi R16,58
	xcall _write_MCP
	.dbline 147
;    write_MCP(TXB0D5,  tx_buff[6]);         //低报点低字节
	lds R18,_tx_buff+6
	ldi R16,59
	xcall _write_MCP
	.dbline 148
;    write_MCP(TXB0D6, tx_buff[10]);         //校验
	lds R18,_tx_buff+10
	ldi R16,60
	xcall _write_MCP
	.dbline 149
;    write_MCP(TXB0D7, tx_buff[11]);
	lds R18,_tx_buff+11
	ldi R16,61
	xcall _write_MCP
	.dbline -2
L59:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Usart_Transmit_Data _Usart_Transmit_Data fV
;            aaa -> R20,R21
;              i -> R18
;           data -> R16
	.even
_Usart_Transmit_Data::
	xcall push_gset1
	.dbline -1
	.dbline 153
; } 
; //485收发函数
; void Usart_Transmit_Data(uchar data,uchar i) 
; {  
	.dbline 154
;    int aaa=0;
	clr R20
	clr R21
	.dbline 155
;    cs_485_send();           
	in R24,0x3
	andi R24,251
	out 0x3,R24
	.dbline 156
	ldi R20,1000
	ldi R21,3
L74:
	.dbline 156
L75:
	.dbline 156
;    for(aaa=1000;aaa>0;aaa--);//等待PB3引脚稳定 1000
	subi R20,1
	sbci R21,0
	.dbline 156
	clr R2
	clr R3
	cp R2,R20
	cpc R3,R21
	brlt L74
L78:
	.dbline 158
L79:
	.dbline 157
;    while(!(UCSR0A&(1<<UDRE0)))
	sbis 0xb,5
	rjmp L78
	.dbline 159
;    ;
;    if(i==1)
	cpi R18,1
	brne L81
	.dbline 160
;       UCSR0B|=(1<<TXB80);  //发送地址
	sbi 0xa,0
	xjmp L82
L81:
	.dbline 162
;    else
;    {
	.dbline 163
;       UCSR0B&=~(1<<TXB80); //发送数据
	cbi 0xa,0
	.dbline 164
;    }
L82:
	.dbline 165
;    UDR0=data;
	out 0xc,R16
L83:
	.dbline 167
L84:
	.dbline 166
;    while(!(UCSR0A&(1<<TXC0)))
	sbis 0xb,6
	rjmp L83
	.dbline 168
;    ;
;    UCSR0A|=1<<TXC0;
	sbi 0xb,6
	.dbline 169
;    cs_485_receive();
	sbi 0x3,2
	.dbline -2
L73:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r aaa 20 I
	.dbsym r i 18 c
	.dbsym r data 16 c
	.dbend
	.dbfunc e usart_transmits _usart_transmits fV
;            bbb -> R22,R23
;             pr -> R20,R21
;              p -> R18,R19
;              n -> R16
	.even
_usart_transmits::
	xcall push_gset2
	.dbline -1
	.dbline 173
; } 
; //发送多个字节函数
; void usart_transmits(unsigned char n, unsigned char *p)
; {

⌨️ 快捷键说明

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