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

📄 uartqq.asm

📁 增强型单片机c8051f230与2.4G射频芯片所组成的无线通信系统
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;---------------------------------------------------------------
; CYGNAL Integrated Products 
;
; Assembly Code Configuration Tool: F230 INITIALIZATION/CONFIGURATION CODE
;----------------------------------------------------------------
; This file is read only. To insert the code into your  
; application, simply cut and paste or use the "Save As" 
; command in the file menu to save the file in your project 
; directory. 
;----------------------------------------------------------------


;----------------------------------------------------------------
; GLOBAL VARIABLES AND ASSIGNMENTS
;----------------------------------------------------------------

$INCLUDE(C8051F200.INC)	; Register definition file.
			PWR_UP BIT P2.5
			CE		 BIT P2.6
			CS		 BIT P2.7
			DR1    BIT P0.2

;----------------------------------------------------------------
; INTERRUPT VECTOR CODE
;----------------------------------------------------------------

      org 00h
      LJMP Config

			ORG 0023H
			LJMP UART

			ORG 0033H
			LJMP SPI

      org 0B3h      ; End of Interrupt Vector space.
Config:

;----------------------------------------------------------------
; Watchdog Timer Configuration
;
; WDTCN.[7:0]: WDT Control
;   Writing 0xA5 enables and reloads the WDT.
;   Writing 0xDE followed within 4 clocks by 0xAD disables the WDT
;   Writing 0xFF locks out disable feature.
;
; WDTCN.[2:0]: WDT timer interval bits
;   NOTE! When writing interval bits, bit 7 must be a 0.
;
;  Bit 2 | Bit 1 | Bit 0
;------------------------     
;    1   |   1   |   1      Timeout interval = 1048576 x Tsysclk
;    1   |   1   |   0      Timeout interval =  262144 x Tsysclk
;    1   |   0   |   1      Timeout interval =   65636 x Tsysclk
;    1   |   0   |   0      Timeout interval =   16384 x Tsysclk
;    0   |   1   |   1      Timeout interval =    4096 x Tsysclk
;    0   |   1   |   0      Timeout interval =    1024 x Tsysclk
;    0   |   0   |   1      Timeout interval =     256 x Tsysclk
;    0   |   0   |   0      Timeout interval =      64 x Tsysclk 
;------------------------

	mov WDTCN, #007h	; Watchdog Timer Control Register
    mov WDTCN, #0DEh    ; Disable WDT    mov WDTCN, #0ADh
; Configure the PRTnMX Registers

	mov PRT0MX, #001h ; PRT0MX:	Initial Reset Value
	mov PRT1MX, #000h ; PRT1MX: Initial Reset Value
	mov PRT2MX, #041h ; PRT2MX: Initial Reset Value

; Select Pin I/0

; NOTE: Some peripheral I/O pins can function as either inputs or 
; outputs, depending on the configuration of the peripheral. By default,
; the configuration utility will configure outputs as push-pull.  

; Port configuration (1 = Push Pull Output)

	mov PRT0CF, #001h ; Output configuration for P0 
	mov PRT1CF, #000h ; Output configuration for P1 
	mov PRT2CF, #0F7h ; Output configuration for P2 
	mov PRT3CF, #000h ; Output configuration for P3 



	mov P0MODE, #0FFh ; Input Configuration for P0
	mov P1MODE, #0FFh ; Input Configuration for P1
	mov P2MODE, #0FFh ; Input Configuration for P2
	mov P3MODE, #0FFh ; Input Configuration for P3

; View port pinout

		; The current MUX configuration results in the 
		; following port pinout assignment:
		; Port 0
		; P0.0 = UART0 TX        (Push-Pull Output)(Digital)		; P0.1 = UART0 RX        (Open-Drain Output/Input)(Digital)		; P0.2 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P0.3 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P0.4 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P0.5 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P0.6 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P0.7 = GP I/O          (Open-Drain Output/Input)(Digital)

		; Port 1
		; P1.0 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P1.1 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P1.2 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P1.3 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P1.4 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P1.5 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P1.6 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P1.7 = GP I/O          (Open-Drain Output/Input)(Digital)
					
		; Port 2		
		; P2.0 = SPI Bus SCK     (Push-Pull Output)(Digital)		; P2.1 = SPI Bus MISO    (Push-Pull Output)(Digital)		; P2.2 = SPI Bus MOSI    (Push-Pull Output)(Digital)		; P2.3 = SPI Bus NSS     (Open-Drain Output/Input)(Digital)		; P2.4 = GP I/O          (Push-Pull Output)(Digital)
		; P2.5 = GP I/O          (Push-Pull Output)(Digital)
		; P2.6 = GP I/O          (Push-Pull Output)(Digital)
		; P2.7 = GP I/O          (Push-Pull Output)(Digital)

		; Port 3		
		; P3.0 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P3.1 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P3.2 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P3.3 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P3.4 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P3.5 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P3.6 = GP I/O          (Open-Drain Output/Input)(Digital)
		; P3.7 = GP I/O          (Open-Drain Output/Input)(Digital)

					
;----------------------------------------------------------------
; Oscillator Configuration
;----------------------------------------------------------------

	mov OSCXCN, #067h	; External Oscillator Control Register	
    clr A                  ;osc    djnz ACC, $            ;wait for    djnz ACC, $            ;at least 1msOX_WAIT:    mov A, OSCXCN    jnb ACC.7, OX_WAIT     ;poll XTLVLD
	mov OSCICN, #088h	; Internal Oscillator Control Register

	
;----------------------------------------------------------------
; Reference Control Register Configuration
;----------------------------------------------------------------

	mov REF0CN, #000h	; Reference Control Register

;----------------------------------------------------------------
; SPI Configuration
;----------------------------------------------------------------

	mov SPI0CN, #002h	; SPI Control Register
	mov SPI0CFG, #007h	; SPI Configuration Register
	mov SPI0CKR, #011h	; SPI Clock Rate Register
    orl SPI0CN, #001
;----------------------------------------------------------------
; Comparators Register Configuration
;
; Bit 7  | Bit 6  | Bit 5  | Bit 4  | Bit 3 | Bit 2 | Bit 1 | Bit 0
;------------------------------------------------------------------     
;   R/W	 |    R   |  R/W   |  R/W   |  R/W  |  R/W  |  R/W  |  R/W
;------------------------------------------------------------------
; Enable | Output | Rising | Falling|  Positive     |  Negative    
;        | State  | Edge   | Edge   |  Hysterisis   |  Hysterisis    
;        | Flag   | Int.   | Int.   |  00: Disable  |  00: Disable
;        |        | Flag   | Flag   |  01:  5mV     |  01:  5mV  
;        |        |        |        |  10: 10mV     |  10: 10mV
;        |        |        |        |  11: 20mV     |  11: 20mV 
; ----------------------------------------------------------------

	mov CPT0CN, #000h	; Comparator 0 Control Register
	

	mov CPT1CN, #000h	; Comparator 1 Control Register
	
	;Comp1 marker

;----------------------------------------------------------------
; UART Configuration
;----------------------------------------------------------------

	mov SCON, #050h		; Serial Port Control Register
    anl SCON, #0FCh    ; clear interrupt pending flags	mov PCON, #000h		; Power Control Register

;----------------------------------------------------------------
; Timer Configuration
;----------------------------------------------------------------

	mov CKCON, #010h	; Clock Control Register
	mov TH0, #000h		; Timer 0 High Byte
	mov TL0, #000h		; Timer 0 Low Byte
	mov TH1, #0FAh		; Timer 1 High Byte
	mov TL1, #0FAh		; Timer 1 Low Byte
	mov TMOD, #020h		; Timer Mode Register
	mov TCON, #040h		; Timer Control Register 

	mov RCAP2H, #000h	; Timer 2 Capture Register High Byte
	mov RCAP2L, #000h	; Timer 2 Capture Register Low Byte
	mov TH2, #000h		; Timer 2 High Byte	
	mov TL2, #000h		; Timer 2 Low Byte	
	mov T2CON, #000h	; Timer 2 Control Register	

;---------------------------------------------------------------
; Reset Source Configuration
;
; Bit 7  | Bit 6  | Bit 5  | Bit 4  | Bit 3 | Bit 2 | Bit 1 | Bit 0
;------------------------------------------------------------------     
;        |   R    |  R/W   |  R/W   |   R   |   R   |  R/W  |  R
;------------------------------------------------------------------
;Reserved|NOT     | Comp.0 | S/W    | WDT   | Miss. | POR   | HW
;        |USED    | Reset/ | Reset  | Reset | Clock | Force | Pin
;        |        | Enable | Force  | Flag  | Detect| &     | Reset
;        |        | Flag   | &      |       | Flag  | Flag  | Flag
;        |        |        | Flag   |       |       |
;------------------------------------------------------------------ 
;
; NOTE! : Comparator 0 must be enabled before it is enabled as a 
; reset source.
;------------------------------------------------------------------

	mov RSTSRC, #000h	; Reset Source Register


;----------------------------------------------------------------
; Interrupt Configuration
;----------------------------------------------------------------

	mov IE, #010h		;Interrupt Enable
	mov IP, #000h		;Interrupt Priority
	mov EIE1, #001h		;Extended Interrupt Enable 1
	mov EIE2, #000h		;Extended Interrupt Enable 2
	mov EIP1, #000h		;Extended Interrupt Priority 1
	mov EIP2, #000h		;Extended Interrupt Priority 2

	

; other initialization code here...



;-----------------------------------------------------------------
; MAIN PROGRAM CODE
;-----------------------------------------------------------------
Main:	
		MOV SP,#69H
					;	MOV R4,#0FFH
;>>>>>>>>>>>>>>>>>>>>>>>  nRF2401配置开始  >>>>>>>>>>>>>>>>>>>>>>>	
		CLR	PWR_UP							
		CLR CE
		CLR CS
		ACALL DELAY3MS   
		SETB PWR_UP
		ACALL DELAY3MS
		SETB CS
		ACALL DELAY5US 
		MOV DPTR,#TABLE
		ACALL NRFPZ
		CLR CS									;nRF2401开始配置
  	ACALL DELAY3MS					;等待配置延时     
		ACALL DELAY3MS       
		SETB DR1								;DR1写1,准备接受接收数据
;.......................  nRF2401配置结束  .......................

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		SETB CE									;启动收发模式,这里为发送模式
		SETB EA                 ;开放中断
		MOV		49H,#20					  ;UART接收计数
		MOV		4AH,#4BH					;UART接收缓冲区首地址
CXUN:
		MOV A,PCON
		JB ACC.6,GF4						;UART接收标志
		MOV C,DR1
		MOV 20H.1,C
		JBC 20H.1,BZ						;2401接收标志
		AJMP CXUN
GF4:
		ANL PCON,#0BFH
		MOV		49H,#20				;UART接收计数

⌨️ 快捷键说明

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