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

📄 240x8515.asm

📁 通信
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;---------------------------------------------------------------------------------------------------
; The nRF2401 2.4GHz Multi Channel Software
;
;
; This software and any related documentation is provided "as is" without any
; warranty of any kind, either express or implied, including, without
; limitation, the implied warranties or merchantability, fitness for a
; particular purpose, and noninfringment. The entire risk arising out of use
; of this software remains with you.
;
;
;---------------------------------------------------------------------------------------------------
.include "8515def.inc" ; microcontroller spesific definitions
;---------------------------------------------------------------------------------------------------
;own definitions, register alias and constants
;---------------------------------------------------------------------------------------------------
.equ		CLK1  	=	0
.equ		CS	=	2
.equ		Data	=	3
.equ		CE	=	4
.equ		Clk2	=	5
.equ		Dout2	=	6

.equ		DR2	=	2
.equ		DR1	=	3
.equ		PWR_UP	=	5

.equ		LED1	=	4
.equ		LED2	=	5
.equ		LED3	=	6
.equ		LED4	=	7

.equ		SPIADDRESS=	0x60
.equ		TXDATAADDRESS=	0x80
.equ		RXDATAADDRESS=	0x90

.equ		Fclk	=	3686400
.equ		BitRate =	19200
.equ		BRR	=	(Fclk/(16*Bitrate))-1

.equ		timerdiv=	1
.equ		timerval=	256-(Fclk/timerdiv)/100000			; timeout each 10us

.def		Temp	=	r16
.def		Address	=	r17
.def		Data1	=	r18
.def		tempi	=	r19
.def		Counter	=	r20
.def		BitCnt	=	r21	
.def		ByteCnt =       r22
.def		flags   =       r23

;********************************************************************
; Interrupt vectors
;********************************************************************
rjmp 		reset
rjmp 		Ext_Int0
reti 				; not used
reti 				; not used
reti 				; not used
reti 				; not used
reti 				; not used
rjmp 		Tim0_OVF
reti 				; not used
rjmp 		UART_RXC
reti 				; not used
reti 				; not used
reti 				; not used
;********************************************************************
Ext_Int0:   	ldi     tempi,0x00
	    	out	GIMSK,tempi	    	; disable INT0 & INT1
		rjmp    reset

Tim0_OVF:	nop	
		in	flags,sreg
		reti

UART_RXC:	in	flags,sreg
		reti
;********************************************************************************************************
; Main routine
;********************************************************************************************************
Reset:		ldi	tempi,Low(RAMEND)
		out	SPL,tempi		; Set stack pointer to last internal RAM location
		ldi	tempi,High(RAMEND)
		out	SPH,tempi

; PortA, PA.0~PA.3 as input button, PA.4~PA.7 as output LED
		ldi	tempi, 0b11110000	; pin 4-7 are output, 0-3 are input, portA	
		out	DDRA,tempi
                ldi     tempi,0xff
                out     PortA,tempi             ;close all LED
;
		cli
; PortB, PB.0~PB.7 , reserve for channel select
		ldi	tempi, 0b00000000	; pin 4-7 are output, 0-3 are input, portB	
		out	DDRB,tempi
                ldi     tempi,0xff
                out     PortB,tempi             ;Pullup PortB
                
; Port C is for 2401 control interface	
		ldi	tempi, 0b10111111	; pin 5-7 are output, 0-4 are input, portD
		out	DDRC,tempi
		sbi	PortC,6			; Pullup on PIN6 of Port C, for DataOut2
		clr     tempi                   ; ini 2401 control port on power on
		out 	PortC,tempi	

; Port D is for 2401 control interface	
		ldi	tempi, 0b11100000	; pin 5-7 are output, 0-4 are input, portD
		out	DDRD,tempi
		sbi	PortD,2			; Pullup on PIN2, Port D.  DR2
		sbi	PortD,3			; Pullup on PIN3, Port D.  DR1

;self check
                ldi     tempi,0x00
                out     PortA,tempi              ;on all LED
 
;config nRF2401				
		rcall	nRF2401_ON
		rcall	BuildSPIWord
		rcall	SPInRF2401
		rcall	CE_High
		rcall   RXEN_HIGH
;
                rcall	delay100
                ldi     tempi,0xff
                out     PortA,tempi              ;close all LED       
;                
		rcall	TXEN_LOW	; set TX mode
		rcall	BuildShockWord  
		rcall	ShockBurst		
		rcall  	Delay10  	;delay for LED light	
		rcall	RXEN_HIGH	                         

;
Main:		rcall 	CheckButtons 	; check if the button is pressed
		sbic	PinD,DR1	; Check if DR1 is high (any received from nRF2401)	
		rcall	ReceiveShock					
		rjmp	main				
;******************************************************************************************************
; Check Button routine
;******************************************************************************************************
CheckButtons: 	in      temp,PinA
		cpi     temp,0xff
		breq    Chkbttret	
		lsl     temp
		lsl     temp
		lsl     temp
		lsl     temp
		mov     data1,temp	; put the button data in dada package	
		out     PortA,data1	; Turn On the LED
		rcall	TXEN_LOW	; set TX mode
		rcall	BuildShockWord  
		rcall	ShockBurst		
		rcall  	Delay100  	;delay for LED light	
		rcall	RXEN_HIGH		
;		
                ldi     tempi,0xff	;close LED display
                out     PortA,tempi	
Chkbttret: 	ret
;********************************************************************************************************
;*****************************************************************************************************
; Delay subroutine.
;*****************************************************************************************************
Delay100:  	clr	bitcnt
		clr	counter
DL1:		inc	counter
DL2:		inc	bitcnt
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		nop
		cpi	bitcnt,0xff
		brne	DL2
		clr	bitcnt
		cpi	counter,0xff
		brne	DL1
		ret		
;*********************************************************************************************************
; Delay subroutine.
;*********************************************************************************************************
Delay10:  	clr	bitcnt
		clr	counter
DL3:		inc	counter
DL4:		inc	bitcnt
		nop
		nop
		cpi	bitcnt,0xff
		brne	DL4
		clr	bitcnt
		cpi	counter,0x0f
		brne	DL3
		ret		
;************************************************** TXEN START **********************************************
TXEN_LOW:	cbi	PortC,CE	; Set CE LOW
		sbi	DDRC,DATA	; Set Data as output	
		sbi	PortC,CS	; Set CS HIGH
		cbi	PortC,DATA	; Set Data LOW
		rcall	DoSPIClock	; Make one SPIClock cycle
		cbi	PortC,CS	; Set CS LOW		
		sbi	PortC,CE	; Set CE HIGH
		ret
;************************************************* TXEN END ************************************************
;************************************************* RXEN START **********************************************
RXEN_HIGH:	cbi	PortC,CE		; Set CE LOW
		sbi	DDRC,DATA		; Set Data as output	
		sbi	PortC,CS		; Set CS HIGH
		sbi	PortC,DATA		; Set Data HIGH
		rcall	DoSPIClock		; Make one SPIClock cycle
		cbi	PortC,CS		; Set CS LOW	
		cbi	DDRC,DATA		; Set Data as input	
		sbi	PortC,CE		; Set CE HIGH
		ret
;************************************************* RXEN END ************************************************
;******************************************** nRF2401_ON START *********************************************
nRF2401_ON:	sbi	PortD,PWR_UP		; Set Power_Up HIGH	
		ret
;*********************************************** nRF2401_ON END ********************************************
;********************************************** nRF2401_OFF START ******************************************
nRF2401_OFF:	cbi	PortD,PWR_UP		; Set Power_Up LOW
		ret
;********************************************** nRF2401_OFF END *******************************************
;************************************************ CE_High START *******************************************
CE_High:	sbi	PortC,CE		; Set CE HIGH	
		ret
;************************************************* CE_High END ********************************************
;************************************************ CE_Low START ********************************************
CE_Low:		cbi	PortC,CE		; Set CE LOW
		ret
;************************************************* CE_Low  END ********************************************
;**********************************************************************************************************				
BuildSPIWord:	cli	
		ldi	Zl,SPIADDRESS	
		clr	Zh

⌨️ 快捷键说明

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