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

📄 cc1100.s

📁 mega128平台下
💻 S
📖 第 1 页 / 共 2 页
字号:
; 	   	halRfSendPacket(txBuffer_CCxx00, sizeof(txBuffer_CCxx00));
; 		Dly1mS(100);
; 	}
; */
; /*********************************************************/
; 	unsigned char halSpiReadReg(unsigned char addr) 
; 	{
; 		unsigned char value;
; 	        CLEAR_CLOCK();
	lds R24,101
	andi R24,254
	sts 101,R24
; 		Dly10us();Dly10us();
	xcall _Dly10us
	xcall _Dly10us
; 		CLEAR_CSN(); // CSn=0
	cbi 0x15,2
; 		addr|=READ_SINGLE;
	ori R20,128
; 		SPI_write(addr);
	mov R16,R20
	xcall _SPI_write
; 	        CLEAR_IN();
	lds R24,101
	andi R24,253
	sts 101,R24
; 		Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
	xcall _Dly10us
	xcall _Dly10us
	xcall _Dly10us
	xcall _Dly10us
	xcall _Dly10us
; 		value=0;
	clr R20
; 		value=SPI_read();
	xcall _SPI_read
	mov R20,R16
; 		Dly10us();Dly10us();Dly10us();
	xcall _Dly10us
	xcall _Dly10us
	xcall _Dly10us
; 		CLEAR_CLOCK();
	lds R24,101
	andi R24,254
	sts 101,R24
; 		CLEAR_IN();
	lds R24,101
	andi R24,253
	sts 101,R24
; 		SET_CSN(); // CSn=0 P_CSn=0;
	sbi 0x15,2
; 		return value;		
	mov R16,R20
L81:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
;          value -> R20
;              i -> R22
;          count -> R10
;         buffer -> R12,R13
;           addr -> R20
	.even
_halSpiReadBurstReg::
	xcall push_gset4
	movw R12,R18
	mov R20,R16
	ldd R10,y+8
; 	}
; /**************************************************/
; 	void halSpiReadBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
; 	{
; 		unsigned char i,value;
; 	        CLEAR_CLOCK();
	lds R24,101
	andi R24,254
	sts 101,R24
; 		Dly10us();Dly10us();
	xcall _Dly10us
	xcall _Dly10us
; 		CLEAR_CSN(); // CSn=0 P_CSn=0;
	cbi 0x15,2
; 		addr|=READ_BURST;
	ori R20,192
; 		SPI_write(addr);
	mov R16,R20
	xcall _SPI_write
; 		CLEAR_IN();
	lds R24,101
	andi R24,253
	sts 101,R24
; 		Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
	xcall _Dly10us
	xcall _Dly10us
	xcall _Dly10us
	xcall _Dly10us
	xcall _Dly10us
; 		value=0; 
	clr R20
; 		for(i=0;i<count;i++)
	clr R22
	xjmp L86
L83:
	xcall _SPI_read
	mov R20,R16
	mov R30,R22
	clr R31
	add R30,R12
	adc R31,R13
	std z+0,R20
L84:
	inc R22
L86:
	cp R22,R10
	brlo L83
; 		{
; 			value=SPI_read();
; 		        buffer[i]=value;
; 		}
; 		Dly10us();Dly10us();Dly10us();
	xcall _Dly10us
	xcall _Dly10us
	xcall _Dly10us
; 		CLEAR_CLOCK();
	lds R24,101
	andi R24,254
	sts 101,R24
; 		CLEAR_IN();
	lds R24,101
	andi R24,253
	sts 101,R24
; 		SET_CSN(); // CSn=0 P_CSn=0;
	sbi 0x15,2
L82:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
;         rd_pin -> <dead>
;          value -> R22
;           addr -> R20
	.even
_halSpiReadStatus::
	xcall push_gset2
	mov R20,R16
; 	}
; /**************************************************/
; 	unsigned char halSpiReadStatus(unsigned char addr) 
; 	{
; 		unsigned char value,rd_pin;
; 	  CLEAR_CSN(); // CSn=0	P_CSn=0;
	cbi 0x15,2
L88:
L89:
; 	  while(GET_OUT());
	xcall _GET_OUT
	cpi R16,0
	cpc R16,R17
	brne L88
X6:
; 		CLEAR_CLOCK(); //SCLK=0  //P_SCLK=0;
	lds R24,101
	andi R24,254
	sts 101,R24
; 		addr|=READ_BURST;
	ori R20,192
; 		SPI_write(addr);
	mov R16,R20
	xcall _SPI_write
; 		value=SPI_read();
	xcall _SPI_read
	mov R22,R16
; 		CLEAR_CLOCK(); //SCLK=0  //P_SCLK=0;
	lds R24,101
	andi R24,254
	sts 101,R24
; 		CLEAR_IN(); // SI=0 P_SI=0;
	lds R24,101
	andi R24,253
	sts 101,R24
; 	  SET_CSN();  //CSn=1	P_CSn=1;
	sbi 0x15,2
; 		return value;
L87:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.even
_halRfWriteRfSettings::
; 	}// halSpiReadStatus
; /**************************************************/
; 	void halRfWriteRfSettings() 
; 	{
L92:
; 	l_setCC1100:	
; 		halSpiWriteReg(CCxxx0_FSCTRL1, 0x0C);	
	ldi R18,12
	ldi R16,11
	xcall _halSpiWriteReg
; 		
; 		halSpiWriteReg(CCxxx0_FSCTRL0, 0x00);	
	clr R18
	ldi R16,12
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FREQ2, 0x10);
	ldi R18,16
	ldi R16,13
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FREQ1, 0x09);
	ldi R18,9
	ldi R16,14
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FREQ0, 0x7B);
	ldi R18,123
	ldi R16,15
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_MDMCFG4, 0xC6);
	ldi R18,198
	ldi R16,16
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_MDMCFG3, 0x83); 
	ldi R18,131
	ldi R16,17
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_MDMCFG2, 0x02);
	ldi R18,2
	ldi R16,18
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_MDMCFG1, 0x22);
	ldi R18,34
	ldi R16,19
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_MDMCFG0, 0xF8);
	ldi R18,248
	ldi R16,20
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_CHANNR, 0x0a);
	ldi R18,10
	ldi R16,10
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_DEVIATN, 0x30);
	ldi R18,48
	ldi R16,21
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FREND1, 0x56);
	ldi R18,86
	ldi R16,33
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FREND0, 0x10);
	ldi R18,16
	ldi R16,34
	xcall _halSpiWriteReg
; 		
; 		
; 		halSpiWriteReg(CCxxx0_MCSM0, 0x18);
	ldi R18,24
	ldi R16,24
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FOCCFG, 0x15);
	ldi R18,21
	ldi R16,25
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_BSCFG, 0x6C);
	ldi R18,108
	ldi R16,26
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_AGCCTRL2, 0x03);
	ldi R18,3
	ldi R16,27
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_AGCCTRL0, 0x91);
	ldi R18,145
	ldi R16,29
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FSCAL3, 0xA9);
	ldi R18,169
	ldi R16,35
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FSCAL2, 0x2A);
	ldi R18,42
	ldi R16,36
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FSCAL0, 0x0D);
	ldi R18,13
	ldi R16,38
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_FSTEST, 0x59);
	ldi R18,89
	ldi R16,41
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_TEST2, 0x86);
	ldi R18,134
	ldi R16,44
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_TEST1, 0x3D);
	ldi R18,61
	ldi R16,45
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_TEST0, 0x09);
	ldi R18,9
	ldi R16,46
	xcall _halSpiWriteReg
; 		
; 		
; 	  halSpiWriteReg(CCxxx0_IOCFG2, 0x24);
	ldi R18,36
	clr R16
	xcall _halSpiWriteReg
; 	  	  
; 	  halSpiWriteReg(CCxxx0_IOCFG0, 0x06);
	ldi R18,6
	ldi R16,2
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_PKTCTRL1, 0x04);
	ldi R18,4
	ldi R16,7
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_PKTCTRL0, 0x05);
	ldi R18,5
	ldi R16,8
	xcall _halSpiWriteReg
; 		halSpiWriteReg(CCxxx0_ADDR, 0x00);
	clr R18
	ldi R16,9
	xcall _halSpiWriteReg
; 		
; 		halSpiWriteReg(CCxxx0_PKTLEN, 0x1F); // hejie ,接收数据长度
	ldi R18,31
	ldi R16,6
	xcall _halSpiWriteReg
; 		//halSpiWriteReg(CCxxx0_PKTLEN, 0xFF);
; 		
; 		halSpiWriteReg(CCxxx0_MCSM2, 0x08);  // CCxxx0_MCSM2 修改限制时间 默认为07 修改为00
	ldi R18,8
	ldi R16,22
	xcall _halSpiWriteReg
; 		//halSpiWriteReg(CCxxx0_FIFOTHR, 0x07);
; 		
; 	 
; 		if(halSpiReadReg(CCxxx0_MDMCFG1)!=0x22){
	ldi R16,19
	xcall _halSpiReadReg
	cpi R16,34
	breq L93
; 		 // led1On();
; 		goto l_setCC1100;
	xjmp L92
L93:
L91:
	.dbline 0 ; func end
	ret
	.area vector(rom, abs)
	.org 8
	jmp _cc1100_rx_isr
	.area text(rom, con, rel)
;   packetLength -> R20
	.even
_cc1100_rx_isr::
	xcall push_lset
	xcall push_gset1
	sbiw R28,1
; 		}
; 	}
; /**************************************************/   
; 
;   //接收到数据中断
; 
;   #pragma interrupt_handler cc1100_rx_isr:3
;  void	cc1100_rx_isr()
; 	  {		    	    
; 		    unsigned char packetLength;		
; 		    //led2Toggle();
; 		  	packetLength = halSpiReadReg(CCxxx0_RXFIFO);		  	
	ldi R16,255
	xcall _halSpiReadReg
	mov R20,R16
; 		  	rxBuffer[0]=packetLength;		  	
	sts _rxBuffer,R20
; 		  	if(rxBuffer[0] <= 32)
	ldi R24,32
	cp R24,R16
	brlo L96
; 		    {
; 		    		halSpiReadBurstReg(CCxxx0_RXFIFO, &rxBuffer[1], packetLength);
	std y+0,R20
	ldi R18,<_rxBuffer+1
	ldi R19,>_rxBuffer+1
	ldi R16,255
	xcall _halSpiReadBurstReg
; 		    		post(CC1100_receive);
	ldi R16,<PL_CC1100_receive
	ldi R17,>PL_CC1100_receive
	xcall _post
; 		    }
	xjmp L97
L96:
; 		    else
; 		    {
; 		    	 halSpiStrobe(CCxxx0_SFRX);
	ldi R16,58
	xcall _halSpiStrobe
; 		    }
L97:
; 		    halSpiStrobe(CCxxx0_SFRX);
	ldi R16,58
	xcall _halSpiStrobe
; 		    halSpiStrobe(CCxxx0_SRX);			   			        	  				  	    			      		  		   
	ldi R16,52
	xcall _halSpiStrobe
L95:
	adiw R28,1
	xcall pop_gset1
	xcall pop_lset
	.dbline 0 ; func end
	reti
;            nnn -> R20,R21
	.even
_CC1100_init::
	xcall push_gset1
	sbiw R28,1
; 	  }
; /**************************************************/ 
; //extern led2On();
; 	//初始化
; 	uint8_t CC1100_init()
; 	{
; 		uint16_t nnn;
; 		
; 		SET_CSN();
	sbi 0x15,2
; 		CLEAR_CLOCK();
	lds R24,101
	andi R24,254
	sts 101,R24
; 		CLEAR_IN();
	lds R24,101
	andi R24,253
	sts 101,R24
; 	
; 		CC1100_setInterrupt(0x00);
	clr R16
	clr R17
	xcall _CC1100_setInterrupt
; 		CC1100_POR();
	xcall _CC1100_POR
	clr R20
	clr R21
	xjmp L103
L100:
L101:
	subi R20,255  ; offset = 1
	sbci R21,255
L103:
; 		for(nnn=0;nnn<500;nnn++);
	cpi R20,244
	ldi R30,1
	cpc R21,R30
	brlo L100
; 			
; 		halRfWriteRfSettings();
	xcall _halRfWriteRfSettings
; 		   // led2On();
; 		halSpiWriteBurstReg(CCxxx0_PATABLE, paTable, sizeof(paTable));
	ldi R24,8
	std y+0,R24
	ldi R18,<_paTable
	ldi R19,>_paTable
	ldi R16,62
	xcall _halSpiWriteBurstReg
; 		
; 		CC1100_setInterrupt(0x00);
	clr R16
	clr R17
	xcall _CC1100_setInterrupt
; 		CC1100_setStrobe(CCxxx0_SIDLE);
	ldi R16,54
	ldi R17,0
	xcall _CC1100_setStrobe
; 		
; 		return 1;
	ldi R16,1
L99:
	adiw R28,1
	xcall pop_gset1
	.dbline 0 ; func end
	ret
;          state -> R20
	.even
_CC1100_setStrobe::
	xcall push_gset1
	mov R20,R16
; 	} 
; 	//设置状态
; 	uint8_t CC1100_setStrobe(uint8_t state)
; 	{
; 		halSpiStrobe(state);
	mov R16,R20
	xcall _halSpiStrobe
; 		Dly1mS(5);
	ldi R16,5
	ldi R17,0
	xcall _Dly1mS
; 		return 1;
	ldi R16,1
L104:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
;          value -> R22
;        address -> R20
	.even
_CC1100_setRegister::
	xcall push_gset2
	mov R22,R18
	mov R20,R16
; 	}
; 	//写寄存器
; 	uint8_t CC1100_setRegister(uint8_t address,uint8_t value)
; 	{
; 		halSpiWriteReg(address,value);
	mov R18,R22
	mov R16,R20
	xcall _halSpiWriteReg
; 		return 1;
	ldi R16,1
L105:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
;        address -> R20
	.even
_CC1100_readRegister::
	xcall push_gset1
	mov R20,R16
; 	}
;     //读寄存器	
; 	uint8_t CC1100_readRegister(uint8_t address)
; 	{		
; 		rd_reg = halSpiReadReg(address);
	mov R16,R20
	xcall _halSpiReadReg
	sts _rd_reg,R16
; 		return rd_reg;
L106:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
;        address -> R20
	.even
_CC1100_readStatus::
	xcall push_gset1
	mov R20,R16
; 	}
; 	//读状态
; 	uint8_t CC1100_readStatus(uint8_t address)
; 	{		
; 		return halSpiReadStatus(address);
	mov R16,R20
	xcall _halSpiReadStatus
L107:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
;          count -> y+5
;         buffer -> R22,R23
;           addr -> R20
	.even
_CC1100_readBurstReg::
	xcall push_gset2
	movw R22,R18
	mov R20,R16
	sbiw R28,1
; 		
; 	}
; 	//连续读
; 	uint8_t CC1100_readBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
; 	{		
; 		 halSpiReadBurstReg(addr, buffer, count);
	ldd R0,y+5
	std y+0,R0
	movw R18,R22
	mov R16,R20
	xcall _halSpiReadBurstReg
; 		return 1;
	ldi R16,1
L108:
	adiw R28,1
	xcall pop_gset2
	.dbline 0 ; func end
	ret
;           flag -> R20
	.even
_CC1100_setInterrupt::
	xcall push_gset1
	mov R20,R16
; 	}
; 	//halSpiReadStatus
; 	//设置中断
; 	uint8_t CC1100_setInterrupt(uint8_t flag)
; 	{
; 		if(flag==0x00)
	tst R20
	brne L110
; 		{
; 			EIFR=0x02;EICRA=0x08;EICRB=0x00;EIMSK=0x00;
	ldi R24,2
	out 0x38,R24
	ldi R24,8
	sts 106,R24
	clr R2
	out 0x3a,R2
	out 0x39,R2
; 		}
	xjmp L111
L110:
; 		else if(flag==0x01)
	cpi R20,1
	brne L112
; 		{
; 			EIFR=0x02;EICRA=0x08;EICRB=0x00;EIMSK=0x02;
	ldi R24,2
	out 0x38,R24
	ldi R24,8
	sts 106,R24
	clr R2
	out 0x3a,R2
	ldi R24,2
	out 0x39,R24
; 			halSpiStrobe(CCxxx0_SRX);
	ldi R16,52
	xcall _halSpiStrobe
; 		}
	xjmp L113
L112:
; 		else if(flag==0x02)
	cpi R20,2
	brne L114
; 		{
; 			halSpiStrobe(CCxxx0_SRX); 
	ldi R16,52
	xcall _halSpiStrobe
; 		}		
L114:
L113:
L111:
; 		return 1;
	ldi R16,1
L109:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
;           size -> R22
;          txPtr -> R20,R21
	.even
_CC1100_sendRFburst::
	xcall push_gset2
	mov R22,R18
	movw R20,R16
; 	}
; 	
; 	//extern led1On();
; 	//连续发
; 	uint8_t CC1100_sendRFburst(uint8_t *txPtr,uint8_t size)
; 	{
; 		//led1On();
; 		CC1100_setInterrupt(0x00); //关中断
	clr R16
	xcall _CC1100_setInterrupt
; 		halSpiStrobe(CCxxx0_SIDLE);
	ldi R16,54
	xcall _halSpiStrobe
; 	   	halRfSendPacket(txPtr, size);
	mov R18,R22
	movw R16,R20
	xcall _halRfSendPacket
; 		//Dly1mS(100);
; 		if(SEND_DONE==0x01) //表明发送完成
	lds R24,_SEND_DONE
	cpi R24,1
	brne L117
; 		{
; 			SEND_DONE=0x00;
	clr R2
	sts _SEND_DONE,R2
; 			//led2On();
; 			CC1100_sendDone(1);
	ldi R16,1
	ldi R17,0
	xcall _CC1100_sendDone
; 			CC1100_setInterrupt(0x01); //开中断
	ldi R16,1
	xcall _CC1100_setInterrupt
; 		}
L117:
; 		return 1;
	ldi R16,1
L116:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
;      channr_NO -> R20
	.even
_CC1100_change_channr::
	xcall push_gset1
	mov R20,R16
; 	}
; /*
; 	uint8_t CC1100_sendDone()
; 	{
; 		return success;
; 	}
; 	uint8_t CC1100_receive(uint8_t *msg)
; 	{
; 		return msg;
; 	}
; */
; //更改通道号
; void CC1100_change_channr(unsigned char channr_NO)
; {
;   halSpiWriteReg(CCxxx0_CHANNR,channr_NO );
	mov R18,R20
	ldi R16,10
	xcall _halSpiWriteReg
L119:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.area bss(ram, con, rel)
_rd_reg::
	.blkb 1
_rxBuffer::
	.blkb 32
	.area func_lit
PL_CC1100_receive:	.word `_CC1100_receive

⌨️ 快捷键说明

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