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

📄 240x8515.asm

📁 通信
💻 ASM
📖 第 1 页 / 共 2 页
字号:
		ldi	temp,15		; Number of bytes
		st	Z+,temp
		ldi	temp,0x50	; MSB	; RX receiver 2, datalength 80bit(10 byte)
		st	Z+,temp
		ldi	temp,0x50	; MSB-1 ; RX receiver 1, datalength 80bit(10 byte)
		st	Z+,temp
		ldi	temp,0x00	; MSB-2
		st	Z+,temp
		ldi	temp,0xCC	; MSB-3
		st	Z+,temp
		ldi	temp,0xCC	; MSB-4
		st	Z+,temp
		ldi	temp,0xCC	; MSB-5
		st	Z+,temp
		ldi	temp,0xCC	; MSB-6
		st	Z+,temp
		ldi	temp,0x00	; MSB-7
		st	Z+,temp
		ldi	temp,0xCC	; MSB-8   ;RX receiver 1 address   High byte
		st	Z+,temp
		ldi	temp,0xCC	; MSB-9   ;RX receiver 1 address   High byte
		st	Z+,temp
		ldi	temp,0xCC	; MSB-10  ;RX receiver 1 address   Low byte
		st	Z+,temp
		ldi	temp,0xCC	; MSB-11  ;RX receiver 1 address   Low  byte
		st	Z+,temp
;		ldi	temp,0x82	; MSB-12  ;this is for 32 bit address(Bit7-Bit2), 16bit CRC(Bit1), CRC disable(Bit0) for ES chip
		ldi	temp,0x83	; MSB-12  ;this is for 32 bit address(Bit7-Bit2), 16bit CRC(Bit1), CRC enable(Bit0) for final chip	
		st	Z+,temp
		ldi	temp,0x4F	; MSB-13  ;One receiver(Bit7), shock Mode(Bit6), datarate(Bit5) 250K, crystal(Bit4-Bit2), RF Power(Bit1-Bit0)
;		ldi	temp,0x6F	; MSB-13  ;One receiver(Bit7), shock Mode(Bit6), datarate(Bit5) 1M, crystal(Bit4-Bit2), RF Power(Bit1-Bit0)
		st	Z+,temp
		ldi	temp,0x05	; MSB-14  ;Channel Number(Bit7-Bit1), RX/TX mode(Bit0)
		st	Z+,temp
;		sei
		ret
;*************************************************************************************************************
BuildShockWord:	
		cli	
		ldi	Zl,TXDATAADDRESS	
		clr	Zh
		ldi	temp,14		; Number of bytes
		st	Z+,temp
		ldi	temp,0xCC	; MSB    ;RX receiver 1 address   High byte
		st	Z+,temp
		ldi	temp,0xCC	; MSB-1  ;RX receiver 1 address   High  byte
		st	Z+,temp
		ldi	temp,0xCC	; MSB-2  ;RX receiver 1 address   Low byte
		st	Z+,temp
		ldi	temp,0xCC	; MSB-3  ;RX receiver 1 address   Low  byte
		st	Z+,temp			
;		mov	temp,data1	; MSB-4  ;data byte 9
		st	Z+,data1
		ldi	temp,0x02	; MSB-5  ; data byte 8
		st	Z+,temp
		ldi	temp,0x03	; MSB-6  ; data byte 7
		st	Z+,temp
		ldi	temp,0x04	; MSB-7  ; data byte 6
		st	Z+,temp
		ldi	temp,0x05	; MSB-8  ; data byte 5
		st	Z+,temp
		ldi	temp,0x06	; MSB-9  ; data byte 4
		st	Z+,temp
		ldi	temp,0x07	; MSB-10 ; data byte 3
		st	Z+,temp
		ldi	temp,0x08	; MSB-11 ; data byte 2
		st	Z+,temp
		ldi	temp,0x09	; MSB-12 ; data byte 1
		st	Z+,temp
		ldi	temp,0x010	; MSB-13 ; data byte 0   
		st	Z+,temp
;		sei
		ret
;********************************************** SPInRF2401 START *******************************************
;***********************************************************************************************************
SPInRF2401:	cli				; Disable Interupts to prevent interupt handling
;		push	r16			; Save registers
;		push	r17			; Save registers
;		push	r18			; Save registers
		ldi	Zl,SPIADDRESS		; Load	Address for where SPI data starts
		clr	Zh			; Load	Address for where SPI data starts
		sbi	DDRC,DATA		; Set data as output (low)
		sbi	DDRC,CLK1		; Set clock as output (low)
		cbi	PORTC,CE		; Disable CE
		sbi	PORTC,CS		; Enable CS
		ld	ByteCnt,Z+		; Number of bytes to be programmed in "ByteCnt"
		
Highloop:	ld	temp,Z+			; Data in "temp"
		ldi	BitCnt,8		; "BitCnt" tracks number of programmed bits

LowLoop:	sbrs	temp,7			; Check if first bit is HIGH
		cbi	PORTC,DATA		; NO: Set Data low
		sbrc	temp,7			; Check if first bit is LOW
		sbi	PORTC,DATA		; NO: Set Data high
		rcall	DoSPIClock		; Call "DoClock" to generate a clock pulse
		dec	BitCnt			; Decrement "BitCnt"
		lsl	temp			; Left Shift to get next bit
		cpi	BitCnt,0		; Chcek if all bits are written in this byte
		brne	Lowloop			; NO: Write next one

		dec	ByteCnt			; YES: Decrement "ByteCnt"
		cpi	ByteCnt,0		; Check if all bytes are written in this SPI round
		brne	Highloop		; NO: Get next byte and write it out

SPIReturn:	cbi	PORTC,CS		; Disable CS	
		cbi	PORTC,DATA		; Set Data low
		cbi	DDRC,DATA		; Set data as input (low)
		cbi	DDRC,CLK1		; Set data as input (low)
;		pop	r18			; Restore registers
;		pop	r17			; Restore registers
;		pop	r16			; Restore registers
;		sei				; Enable Interupts
		ret

DoSPIClock:	sbi	PORTC,CLK1
		nop
		nop
		cbi	PORTC,CLK1
		ret
;********************************************** SPInRF2401 END ********************************************
;********************************************* ShockBurst START *******************************************
;**********************************************************************************************************
ShockBurst:	cli
	;	push	r16			; Save registers
	;	push	r17			; Save registers
	;	push	r18			; Save registers	

GOGO:		sbi	DDRC,Data		; Set data as output (low)
		sbi	DDRC,Clk1		; Set CLK1 as output (low)
		cbi	PORTC,CS		; Pull CS low
		sbi	PORTC,CE		; Enable CE
		ldi	Zl,TXDATAADDRESS	; Load	Address for where data starts
		clr	Zh			; Load	Address for where data starts
		ld	ByteCnt,Z+		; Load number of bytes to be send
BurstLoop1:	ld	temp,Z+			; Load databyte in temp
		rcall	SendData		; Call SendData
		dec	ByteCnt			; Check if all bytes are sendt
		cpi	ByteCnt,0
		brne	BurstLoop1		; NO: Loop around and do it again

BurstReturn:	cbi	PORTC,CE		; Disable CE (TX Starts!);
		cbi	PORTC,Data		; Set Data low
		cbi	DDRC,Data		; Set data as input (low)
;		cbi	DDRC,Clk1		; Set Clock as input (low)
NOGOGO:	;	pop	r18			; Restore registers
	;	pop	r17			; Restore registers
	;	pop	r16			; Restore registers
;		sei
		ret

SendData:	ldi	BitCnt,8		; Load number of bits in 'BitCnt'
LowLoopburst:	sbrs	temp,7			
		cbi	PORTC,Data		; Set Data low
		sbrc	temp,7
		sbi	PORTC,Data		; Set Data high
		rcall	DoSPIClock
		dec	BitCnt
		lsl	temp
		cpi	BitCnt,0
		brne	Lowloopburst	
		ret
;*********************************************************************************************
;****************************** ReceiveShock START *******************************************
;*********************************************************************************************
ReceiveShock:	cli

Rxnext:	;	push	r16			; Save registers
	;	push	r17			; Save registers
	;	push	r18			; Save registers	
		cbi	DDRC,Data		; Set data as input
		sbi	DDRC,Clk1		; Set clock as output
		cbi	PortC,Data		; Set data tri state
		ldi	Zl,RXDATAADDRESS
		clr	Zh
		clr	ByteCnt		
R1:		clr	temp
		clr	BitCnt	
in1loop:	lsl	temp			; shift left to receive next bit
		sbi	PORTC,Clk1		; set clock high
		nop
		nop				; wait one clk cycle
		sbic	PinC,Data		; check if Data=low		
		ori	temp,1			; no - set bit high
		cbi	PORTC,Clk1		; set clock low
		nop				; wait one clk cycle

		inc	BitCnt			; increment bit counter
		cpi	BitCnt,8		; 
		brne	in1loop
		nop
		inc	ByteCnt
		st	Z+,temp				
		sbis	PinD,DR1		; check if DR1 is still high
		rjmp	Receiveret		; no, jump to receive return
		rjmp	R1
		
Receiveret:	nop			
SendToPORTA:	ldi	Zl,RXDATAADDRESS	; Load	Address for where data starts
		clr	Zh			; Load	Address for where data starts
;		ldi	ByteCnt,11		; Load number of bytes to be send
SendLoop:	ld	temp,Z			; Load databyte in temp
		out     PortA,temp		; Turn On the LED
;
		rcall 	delay100    		;		
                ldi  	temp,0xff		;2003.1.9
                out  	PortA,temp			

		ret
;************************************* ReceiveShock END *********************************
;****************************************************************************************
;****************************************************************************************
BuildTestWord:	cli	
		ldi	Zl,TXDATAADDRESS	;"WIRELESS.."
		clr	Zh
		ldi	temp,0x57	; MSB    ;RX receiver 1 address   High byte
		st	Z+,temp
		ldi	temp,0x49	; MSB-1  ;RX receiver 1 address   High  byte
		st	Z+,temp
		ldi	temp,0x52	; MSB-2  ;RX receiver 1 address   Low byte
		st	Z+,temp
		ldi	temp,0x45	; MSB-3  ;RX receiver 1 address   Low  byte
		st	Z+,temp			
		ldi	temp,0x4c	; MSB-4  ; data byte 9
		st	Z+,temp
		ldi	temp,0x45	; MSB-5  ; data byte 8
		st	Z+,temp
		ldi	temp,0x53	; MSB-6  ; data byte 7
		st	Z+,temp
		ldi	temp,0x53	; MSB-7  ; data byte 6
		st	Z+,temp
		ldi	temp,0x2e	; MSB-8  ; data byte 5
		st	Z+,temp
		ldi	temp,0x2e	; MSB-9  ; data byte 4
		st	Z+,temp
;		sei
		ret
;***************************************************************************************************
			

⌨️ 快捷键说明

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