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

📄 240x8515.lst

📁 nrf2041,通讯的基本程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
          .equ	PIND7	=7
          .equ	PIND6	=6
          .equ	PIND5	=5
          .equ	PIND4	=4
          .equ	PIND3	=3
          .equ	PIND2	=2
          .equ	PIND1	=1
          .equ	PIND0	=0
         
          .equ	SPIE	=7
          .equ	SPE	=6
          .equ	DORD	=5
          .equ	MSTR	=4
          .equ	CPOL	=3
          .equ	CPHA	=2
          .equ	SPR1	=1
          .equ	SPR0	=0
         
          .equ	SPIF	=7
          .equ	WCOL	=6
         
          .equ	RXC	=7
          .equ	TXC	=6
          .equ	UDRE	=5
          .equ	FE	=4
          .equ	OR	=3
         
          .equ	RXCIE	=7
          .equ	TXCIE	=6
          .equ	UDRIE	=5
          .equ	RXEN	=4
          .equ	TXEN	=3
          .equ	CHR9	=2
          .equ	RXB8	=1
          .equ	TXB8	=0
         
          .equ	ACD	=7
          .equ	ACO	=5
          .equ	ACI	=4
          .equ	ACIE	=3
          .equ	ACIC	=2
          .equ	ACIS1	=1
          .equ	ACIS0	=0
         
          .def	XL	=r26
          .def	XH	=r27
          .def	YL	=r28
          .def	YH	=r29
          .def	ZL	=r30
          .def	ZH	=r31
         
          .equ 	RAMEND  =$25F	;Last On-Chip SRAM Location
          .equ	XRAMEND =$FFFF
          .equ	E2END	=$1FF
          .equ	FLASHEND=$FFF
         
         
          .equ	INT0addr=$001	;External Interrupt0 Vector Address
          .equ	INT1addr=$002	;External Interrupt1 Vector Address
          .equ	ICP1addr=$003	;Input Capture1 Interrupt Vector Address
          .equ	OC1Aaddr=$004	;Output Compare1A Interrupt Vector Address
          .equ	OC1Baddr=$005	;Output Compare1B Interrupt Vector Address
          .equ	OVF1addr=$006	;Overflow1 Interrupt Vector Address
          .equ	OVF0addr=$007	;Overflow0 Interrupt Vector Address
          .equ	SPIaddr =$008	;SPI Interrupt Vector Address
          .equ	URXCaddr=$009	;UART Receive Complete Interrupt Vector Address
          .equ	UDREaddr=$00a	;UART Data Register Empty Interrupt Vector Address
          .equ	UTXCaddr=$00b	;UART Transmit Complete Interrupt Vector Address
          .equ	ACIaddr =$00c	;Analog Comparator Interrupt Vector Address
         ;---------------------------------------------------------------------------------------------------
         ;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
         ;********************************************************************
000000 c014      rjmp 		reset
000001 c00b      rjmp 		Ext_Int0
000002 9518      reti 				; not used
000003 9518      reti 				; not used
000004 9518      reti 				; not used
000005 9518      reti 				; not used
000006 9518      reti 				; not used
000007 c008      rjmp 		Tim0_OVF
000008 9518      reti 				; not used
000009 c009      rjmp 		UART_RXC
00000a 9518      reti 				; not used
00000b 9518      reti 				; not used
00000c 9518      reti 				; not used
         ;********************************************************************
00000d e030      Ext_Int0:   	ldi     tempi,0x00
00000e bf3b      	    	out	GIMSK,tempi	    	; disable INT0 & INT1
00000f c005      		rjmp    reset
         
000010 0000      Tim0_OVF:	nop	
000011 b77f      		in	flags,sreg
000012 9518      		reti
         
000013 b77f      UART_RXC:	in	flags,sreg
000014 9518      		reti
         ;********************************************************************************************************
         ; Main routine
         ;********************************************************************************************************
000015 e53f      Reset:		ldi	tempi,Low(RAMEND)
000016 bf3d      		out	SPL,tempi		; Set stack pointer to last internal RAM location
000017 e032      		ldi	tempi,High(RAMEND)
000018 bf3e      		out	SPH,tempi
         
         ; PortA, PA.0~PA.3 as input button, PA.4~PA.7 as output LED
000019 ef30      		ldi	tempi, 0b11110000	; pin 4-7 are output, 0-3 are input, portA	
00001a bb3a      		out	DDRA,tempi
00001b ef3f                      ldi     tempi,0xff
00001c bb3b                      out     PortA,tempi             ;close all LED
         ;
00001d 94f8      		cli
         ; PortB, PB.0~PB.7 , reserve for channel select
00001e e030      		ldi	tempi, 0b00000000	; pin 4-7 are output, 0-3 are input, portB	
00001f bb37      		out	DDRB,tempi
000020 ef3f                      ldi     tempi,0xff
000021 bb38                      out     PortB,tempi             ;Pullup PortB
                         
         ; Port C is for 2401 control interface	
000022 eb3f      		ldi	tempi, 0b10111111	; pin 5-7 are output, 0-4 are input, portD
000023 bb34      		out	DDRC,tempi
000024 9aae      		sbi	PortC,6			; Pullup on PIN6 of Port C, for DataOut2
000025 2733      		clr     tempi                   ; ini 2401 control port on power on
000026 bb35      		out 	PortC,tempi	
         
         ; Port D is for 2401 control interface	
000027 ee30      		ldi	tempi, 0b11100000	; pin 5-7 are output, 0-4 are input, portD
000028 bb31      		out	DDRD,tempi
000029 9a92      		sbi	PortD,2			; Pullup on PIN2, Port D.  DR2
00002a 9a93      		sbi	PortD,3			; Pullup on PIN3, Port D.  DR1
         
         ;self check
00002b e030                      ldi     tempi,0x00
00002c bb3b                      out     PortA,tempi              ;on all LED
          
         ;config nRF2401				
00002d d051      		rcall	nRF2401_ON
00002e d058      		rcall	BuildSPIWord
00002f d09c      		rcall	SPInRF2401
000030 d052      		rcall	CE_High
000031 d044      		rcall   RXEN_HIGH
         ;
000032 d01c                      rcall	delay100
000033 ef3f                      ldi     tempi,0xff
000034 bb3b                      out     PortA,tempi              ;close all LED       
         ;                
000035 d038      		rcall	TXEN_LOW	; set TX mode
000036 d074      		rcall	BuildShockWord  
000037 d0b4      		rcall	ShockBurst		
000038 d029      		rcall  	Delay10  	;delay for LED light	
000039 d03c      		rcall	RXEN_HIGH	                         
         
         ;
00003a d003      Main:		rcall 	CheckButtons 	; check if the button is pressed
00003b 9983      		sbic	PinD,DR1	; Check if DR1 is high (any received from nRF2401)	
00003c d0cb      		rcall	ReceiveShock					
00003d cffc      		rjmp	main				
         ;******************************************************************************************************
         ; Check Button routine
         ;******************************************************************************************************
00003e b309      CheckButtons: 	in      temp,PinA
00003f 3f0f      		cpi     temp,0xff
000040 f069      		breq    Chkbttret	
000041 0f00      		lsl     temp
000042 0f00      		lsl     temp
000043 0f00      		lsl     temp
000044 0f00      		lsl     temp
000045 2f20      		mov     data1,temp	; put the button data in dada package	
000046 bb2b      		out     PortA,data1	; Turn On the LED
000047 d026      		rcall	TXEN_LOW	; set TX mode
000048 d062      		rcall	BuildShockWord  
000049 d0a2      		rcall	ShockBurst		
00004a d004      		rcall  	Delay100  	;delay for LED light	
00004b d02a      		rcall	RXEN_HIGH		
         ;		
00004c ef3f                      ldi     tempi,0xff	;close LED display
00004d bb3b                      out     PortA,tempi	
00004e 9508      Chkbttret: 	ret
         ;********************************************************************************************************
         ;*****************************************************************************************************
         ; Delay subroutine.
         ;*****************************************************************************************************
00004f 2755      Delay100:  	clr	bitcnt
000050 2744      		clr	counter
000051 9543      DL1:		inc	counter
000052 9553      DL2:		inc	bitcnt
000053 0000      		nop
000054 0000      		nop
000055 0000      		nop
000056 0000      		nop
000057 0000      		nop
000058 0000      		nop
000059 0000      		nop
00005a 0000      		nop
00005b 0000      		nop
00005c 3f5f      		cpi	bitcnt,0xff
00005d f7a1      		brne	DL2
00005e 2755      		clr	bitcnt
00005f 3f4f      		cpi	counter,0xff
000060 f781      		brne	DL1
000061 9508      		ret		
         ;*********************************************************************************************************
         ; Delay subroutine.
         ;*********************************************************************************************************
000062 2755      Delay10:  	clr	bitcnt
000063 2744      		clr	counter
000064 9543      DL3:		inc	counter
000065 9553      DL4:		inc	bitcnt
000066 0000      		nop
000067 0000      		nop
000068 3f5f      		cpi	bitcnt,0xff
000069 f7d9      		brne	DL4
00006a 2755      		clr	bitcnt
00006b 304f      		cpi	counter,0x0f
00006c f7b9      		brne	DL3
00006d 9508      		ret		
         ;************************************************** TXEN START **********************************************
00006e 98ac      TXEN_LOW:	cbi	PortC,CE	; Set CE LOW
00006f 9aa3      		sbi	DDRC,DATA	; Set Data as output	
000070 9aaa      		sbi	PortC,CS	; Set CS HIGH
000071 98ab      		cbi	PortC,DATA	; Set Data LOW
000072 d074      		rcall	DoSPIClock	; Make one SPIClock cycle
000073 98aa      		cbi	PortC,CS	; Set CS LOW		
000074 9aac      		sbi	PortC,CE	; Set CE HIGH
000075 9508      		ret
         ;************************************************* TXEN END ************************************************
         ;************************************************* RXEN START **********************************************
000076 98ac      RXEN_HIGH:	cbi	PortC,CE		; Set CE LOW
000077 9aa3      		sbi	DDRC,DATA		; Set Data as output	
000078 9aaa      		sbi	PortC,CS		; Set CS HIGH

⌨️ 快捷键说明

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