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

📄 mdfan.lst

📁 用24L01的2.4Ghz无线控制风扇的源程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
     1  000000             ;*************************************************************************************
     2  000000             ;IC Body:SN8P2613
     3  000000             ;Author :Huang QingBei
     4  000000             ;Discription:This file is composed of the main control program of MD fan.
     5  000000             ;Resources:Use INT0 to receive IRQ form nRF24L01,T0 to time,TC0 to create buzzer.
     6  000000             ;Version:1.0
     7  000000             ;Version History:
     8  000000             ;*************************************************************************************
     9  000000             CHIP	SN8P2613
    10  000000             //{{SONIX_CODE_OPTION
    11  000000             	.Code_Option	LVD		LVD_H		; 2.4V Reset Enable LVD36 bit of PFLAG for 3.6V Low Voltage Indicator
    12  000000             	.Code_Option	Reset_Pin	Reset
    13  000000             	.Code_Option	Watch_Dog	Disable
    14  000000             	.Code_Option	High_Clk	IHRC_16M	; Internal 16M RC Oscillator
    15  000000             	.Code_Option	Fcpu		Fosc/16
    16  000000             	.Code_Option	Security	Enable
    17  000000             	.Code_Option	Noise_Filter	Enable
    18  000000             //}}SONIX_CODE_OPTION
    19  000000             
    20  000000             
    21  000000             ;--------------------------Constants Definition-----------------------
    22  000000             
    23  000000             ; SPI(nRF24L01) commands
    24  E 00000000         	READ_REG	EQU	0x00  ; Define read command to register
    25  E 00000020         	WRITE_REG	EQU     0x20  ; Define write command to register
    26  E 00000061         	RD_RX_PLOAD	EQU     0x61  ; Define RX payload register address
    27  E 000000A0         	WR_TX_PLOAD	EQU     0xA0  ; Define TX payload register address
    28  E 000000E1         	FLUSH_TX	EQU     0xE1  ; Define flush TX register command
    29  E 000000E2         	FLUSH_RX	EQU     0xE2  ; Define flush RX register command
    30  E 000000E3         	REUSE_TX_PL	EQU     0xE3  ; Define reuse TX payload register command
    31  E 000000FF         	NO_Operation	EQU     0xFF  ; Define No Operation, might be used to read status register
    32  000000             
    33  000000             ; SPI(nRF24L01) registers(addresses)
    34  E 00000000         	CONFIG		EQU	0x00  ; 'Config' register address
    35  E 00000001         	EN_AA		EQU     0x01  ; 'Enable Auto Acknowledgment' register address
    36  E 00000002         	EN_RXADDR	EQU     0x02  ; 'Enabled RX addresses' register address
    37  E 00000003         	SETUP_AW	EQU     0x03  ; 'Setup address width' register address
    38  E 00000004         	SETUP_RETR	EQU     0x04  ; 'Setup Auto. Retrans' register address
    39  E 00000005         	RF_CH		EQU     0x05  ; 'RF channel' register address
    40  E 00000006         	RF_SETUP	EQU     0x06  ; 'RF setup' register address
    41  E 00000007         	STATUS		EQU     0x07  ; 'Status' register address
    42  E 00000008         	OBSERVE_TX	EQU     0x08  ; 'Observe TX' register address
    43  E 00000009         	CD		EQU     0x09  ; 'Carrier Detect' register address
    44  E 0000000A         	RX_ADDR_P0	EQU     0x0A  ; 'RX address pipe0' register address
    45  E 0000000B         	RX_ADDR_P1	EQU     0x0B  ; 'RX address pipe1' register address
    46  E 0000000C         	RX_ADDR_P2	EQU     0x0C  ; 'RX address pipe2' register address
    47  E 0000000D         	RX_ADDR_P3	EQU     0x0D  ; 'RX address pipe3' register address
    48  E 0000000E         	RX_ADDR_P4	EQU     0x0E  ; 'RX address pipe4' register address
    49  E 0000000F         	RX_ADDR_P5	EQU     0x0F  ; 'RX address pipe5' register address
    50  E 00000010         	TX_ADDR		EQU     0x10  ; 'TX address' register address
    51  E 00000011         	RX_PW_P0	EQU     0x11  ; 'RX payload width, pipe0' register address
    52  E 00000012         	RX_PW_P1	EQU     0x12  ; 'RX payload width, pipe1' register address
    53  E 00000013         	RX_PW_P2	EQU     0x13  ; 'RX payload width, pipe2' register address
    54  E 00000014         	RX_PW_P3	EQU     0x14  ; 'RX payload width, pipe3' register address
    55  E 00000015         	RX_PW_P4	EQU     0x15  ; 'RX payload width, pipe4' register address
    56  E 00000016         	RX_PW_P5	EQU     0x16  ; 'RX payload width, pipe5' register address
    57  E 00000017         	FIFO_STATUS	EQU     0x17  ; 'FIFO Status Register' register address
    58  000000             
    59  E 00000070         	MASK_IRQ_FLAGS  EQU     0x70	;bit mask of all INT in "Status" register
    60  E 00000040         	MASK_RX_DR_FLAG EQU     0x40
    61  E 00000020         	MASK_TX_DS_FLAG EQU     0x20
    62  E 00000010         	MASK_MAX_RT_FLAG EQU    0x10
    63  E 0000000E         	RX_P_NO         EQU     0x0e
    64  000000             
    65  000000             ;User difined constants
    66  E 0000000F         	FREQ_TABLE_SIZE	EQU	15	;total 15 channels
    67  E 00000005         	TX_ADDR_LENGTH	EQU	5	;5 bytes Tx address
    68  000000             ;we use the following address when communicating with Writer
    69  E 00000040         	TX_ADDR0_DEF	EQU	0x40	;default address
    70  E 00000050         	TX_ADDR1_DEF	EQU	0x50
    71  E 00000060         	TX_ADDR2_DEF	EQU	0x60
    72  E 00000070         	TX_ADDR3_DEF	EQU	0x70
    73  E 00000080         	TX_ADDR4_DEF	EQU	0x80
    74  000000             ;Rx address of fan
    75  000000             	;RX_ADDR0_DEF	EQU	0x04	;default address
    76  000000             	;RX_ADDR1_DEF	EQU	0x05
    77  000000             	;RX_ADDR2_DEF	EQU	0x06
    78  E 00000007         	RX_ADDR3_DEF	EQU	0x07
    79  E 00000008         	RX_ADDR4_DEF	EQU	0x08
    80  000000             	
    81  E 00000001         	RX_PLOAD_WIDTH	EQU	1	;1 byte command
    82  000000             
    83  E 00000002         	TX_CH_DEF	EQU	2	;default channel 2
    84  E 00000004         	TX_PLOAD_WIDTH	EQU	4	;3 bytes access code and 1 byte command
    85  000000             ;T0 source is slow clock,it vary according to Vcc and temperature,so if we adjust 
    86  000000             ;the value of Vcc,we must adjust these values to make it interupt every 8 second.
    87  E 00000000         	T0_RATE		EQU	00000000B
    88  E 00000028         	T0C_VALUE	EQU	40
    89  000000             ;normal mode,Fcpu=Fosc/16=1MHz(1us).Ftc0out=4kHz(Buzzer),Ftc0=2*Ftc0out=8kHz(125us).
    90  000000             ;TC0RATE=111,TC0CLOCK=Fcpu/2=0.5MHz(2us),TC0C=256-(0.125*10^-3*1*10^6/2)=193
    91  000000             ;The TC0 rate control bits exist in bit4~bit6 of TC0M. The
    92  000000             ; value is from x000xxxxb~x111xxxxb.
    93  E 00000070         	TC0_RATE	EQU	01110000B
    94  E 000000C1         	TC0C_VALUE	EQU	193
    95  000000             
    96  000000             ;normal mode,Fcpu=Fosc/16=1MHz(1us).Ftc0out=1kHz(Buzzer),Ftc0=2*Ftc0out=2kHz(500us).
    97  000000             ;TC0RATE=101,TC0CLOCK=Fcpu/8=0.125MHz(8us),TC0C=256-(0.5*10^-3*1*10^6/8)=193
    98  000000             ;The TC0 rate control bits exist in bit4~bit6 of TC0M. The
    99  000000             ; value is from x000xxxxb~x111xxxxb.
   100  E 00000050         	TC0_RATE_1k	EQU	01010000B
   101  E 000000C1         	TC0C_VALUE_1k	EQU	193
   102  000000             
   103  E 00000014         	BEEP_TIME_L	EQU	20	;beep long time 50ms*20=1000ms
   104  E 00000002         	BEEP_TIME_S	EQU	2	;beep short time 50ms*2=100ms
   105  000000             	
   106  000000             ;Define nRF24L01 interrupt flag's	
   107  E 00000000         	IDLE            EQU	0x00  	;Idle, no interrupt pending
   108  E 00000010         	MAX_RT          EQU	0x10  	;Max #of TX retrans interrupt
   109  E 00000020         	TX_DS           EQU	0x20  	;TX data sent interrupt
   110  E 00000040         	RX_DR           EQU	0x40  	;RX data received
   111  000000             
   112  000000             ;command
   113  E 000000E0         	MASK_COMM_MODE			EQU	11100000B
   114  E 00000007         	MASK_COMM_KEY			EQU	00000111B
   115  E 00000001         	MASK_COMM_KEY_POWER		EQU	00000001B	;bit mask corresponding to button "Power"
   116  E 00000002         	MASK_COMM_KEY_SPEED		EQU	00000010B	;bit mask corresponding to button "Speed"
   117  E 00000004         	MASK_COMM_KEY_TIME		EQU	00000100B	;bit mask corresponding to button "Time"
   118  000000             
   119  E 00000000         	COMM_MODE_NORMAL_KEY		EQU	00000000B	;normal key pressed event
   120  000000             	;COMM_MODE_ACCESS_CODE_REQ	EQU	00100000B	;request from Remote
   121  000000             	;COMM_MODE_ACCESS_CODE_REP	EQU	01000000B	;reply to Remote
   122  E 00000060         	COMM_MODE_ACCESS_CODE_WRI	EQU	01100000B	;write by Control Panel
   123  E 00000080         	COMM_MODE_ACCESS_CODE_READ	EQU	10000000B	;request from Control Panel
   124  E 000000A0         	COMM_MODE_ACCESS_CODE_RETURN	EQU	10100000B	;return to Control Panel
   125  E 000000E0         	COMM_MODE_TEST_BOARD		EQU	11100000B	;Control Panel “Board Test”Command to Fan
   126  000000             
   127  000000             
   128  000000             ;power
   129  E 00000000         	POWER_ON	EQU	0
   130  E 00000001         	POWER_OFF	EQU	1
   131  000000             ;speed
   132  E 00000000         	SPEED_LO	EQU	0
   133  E 00000001         	SPEED_MID	EQU	1
   134  E 00000002         	SPEED_HI	EQU	2
   135  000000             ;time
   136  E 00000000         	TIME_NONE	EQU	0
   137  E 00000001         	TIME_2H		EQU	1
   138  E 00000002         	TIME_4H		EQU	2
   139  E 00000003         	TIME_8H		EQU	3
   140  000000             ;timer_count
   141  E 00000000         	TIMER_COUNT_NONE	EQU	0	;no timer
   142  E 00000004         	TIMER_COUNT_2H		EQU	4	;0.5hour*4=2hour
   143  E 00000008         	TIMER_COUNT_4H		EQU	8	;0.5hour*8=4hour
   144  E 00000010         	TIMER_COUNT_8H		EQU	16	;0.5hour*16=8hour
   145  000000             
   146  000000             ;access code request time allowed (form reset)
   147  E 00000006         	ACC_CODE_TIME_ALLOWED	EQU	6	;counter_m=6,10s*6=60s
   148  000000             
   149  000000             
   150  000000             ;-------------------------------------------------------------------
   151  000000             
   152  000000             ;--------------------------Variables Definition---------------------
   153  000000             .DATA
   154  000000             
   155  E 00000000         	AccBuf		EQU 	00h
   156  E 00000001         	PFlagBuf	EQU 	01h
   157  E 00000002         	counter_h	EQU	02h		;high counter,30min per unit
   158  E 00000003         	counter_m	EQU	03h		;middle counter,10s per unit
   159  000000             	;counter_l	EQU	04h		;low counter,50 ms per unit
   160  E 00000005         	irq_source	EQU	05h		;IRQ from nRF24L01,can be TX_DS,RX_DR,MAX_RT
   161  E 00000006         	flag		EQU	06h		;all kinds of flags
   162  E 00000007         	pload_width	EQU	07h		;pay load data width
   163  E 00000008         	local_access_code0	EQU	08h	;hold the 1st byte of accss code
   164  E 00000009         	local_access_code1	EQU	09h	;hole the 2nd byte of access code
   165  E 0000000A         	local_access_code2	EQU	0ah	;hole the 3nd byte of access code
   166  E 0000000B         	power		EQU	0bh		;button 'ON/OFF' state machine
   167  E 0000000C         	speed		EQU	0ch		;button 'Speed' state machine
   168  E 0000000D         	time		EQU	0dh		;button 'Time' state machine
   169  E 0000000E         	timer_count	EQU	0eh		;hold the timer limit
   170  E 0000000F         	channel		EQU	0fh		;hold the current channel value
   171  000000             	
   172  E 00000010         	spi_data	EQU	10h		;input parameter of SPI_RW subroutine
   173  E 00000011         	bit_count	EQU	11h	
   174  E 00000012         	spi_reg_addr	EQU	12h		;input parameter of SPI_Read_Reg and SPI_Write_Reg subroutine
   175  E 00000013         	spi_value	EQU	13h		;input parameter of SPI_Read_Reg subroutine and output parameter SPI_Read_Write subroutine
   176  E 00000014         	spi_status	EQU	14h		;output parameter SPI_Read_Write subroutine
   177  E 00000015         	status_temp	EQU	15h		;to hold the value of "Status" register
   178  E 00000016         	ptr_table	EQU	16h		;pointer to channel table
   179  E 00000017         	temp0		equ	17h
   180  E 00000018         	temp1		equ	18h
   181  E 00000019         	temp2		equ	19h
   182  000000             
   183  E 0000001A         	EEPROMflag	equ 	1ah
   184  E 0000001B         	DataBuffer	equ 	1bh
   185  E 0000001C         	WorkingState	equ 	1ch
   186  E 0000001D         	ErrorCount	equ	1dh
   187  E 0000001E         	test_data0	equ	1eh
   188  E 0000001F         	test_data1	equ	1fh
   189  000000             
   190  E 00000020         	data_buf	EQU	20h
   191  E 00000020         	command		EQU	data_buf	;explain what action to take
   192  E 00000021         	access_code0	EQU	data_buf+1	;received from user,should be compared with local one
   193  E 00000022         	access_code1	EQU	data_buf+2	;received from user,should be compared with local one
   194  E 00000023         	access_code2	EQU	data_buf+3	;received from user,should be compared with local one
   195  000000             	
   196  000000             ;-------------------------------------------------------------------
   197  000000             
   198  000000             ;---------------------------Port Definition-------------------------
   199  000000             
   200  000000             ;---------------------------Bit Flag Definition---------------------
   201  E 00000006         	F_10S_ARRIVED	EQU	flag.0
   202  E 00010006         	F_CHECK_CD	EQU	flag.1
   203  000000             	
   204  E 00000020         	BIT_KEY_POWER	EQU	command.0
   205  E 00010020         	BIT_KEY_SPEED	EQU	command.1
   206  E 00020020         	BIT_KEY_TIME	EQU	command.2
   207  000000             
   208  000000             
   209  000000             
   210  000000             ;Contral pin
   211  E 000700D1         	PIN_CTRL_LO	EQU	P1.7	;output
   212  E 000600D1         	PIN_CTRL_MID	EQU	P1.6	;output
   213  E 000500D1         	PIN_CHIP_RESET	EQU	P1.5
   214  E 000400D1         	PIN_CTRL_HI	EQU	P1.4	;output
   215  000000             ;EEPROM I2C pin	
   216  E 000300D1         	PIN_I2C_SDA	EQU	P1.3	;output
   217  E 000200D1         	PIN_I2C_SCL	EQU	P1.2	;output
   218  000000             ;LED pin
   219  E 000100D5         	PIN_LED_8H	EQU	P5.1	;output
   220  E 000000D5         	PIN_LED_4H	EQU	P5.0	;output
   221  E 000000D0         	PIN_LED_2H	EQU	P0.0	;output
   222  E 000400D1         	PIN_LED_HI	EQU	PIN_CTRL_HI	;multiplex with ctrl pin
   223  E 000000D1         	PIN_LED_MID	EQU	P1.0	;PIN_CTRL_MID
   224  E 000100D1         	PIN_LED_LO	EQU	P1.1	;PIN_CTRL_LO
   225  000000             
   226  000000             ;nRF24L01 pin
   227  E 000100D0         	PIN_IRQ_nRF24L01 EQU	P0.1	;input,Interrupt signal, from nRF24L01 
   228  E 000700D5         	PIN_SPI_MISO	EQU	P5.7	;input,Master In, Slave Out pin
   229  E 000600D5         	PIN_CE_nRF24L01	EQU	P5.6	;output,Chip Enable pin signal	 
   230  E 000500D5         	PIN_SPI_CLK	EQU	P5.5	;output,Serial Clock pin
   231  E 000400D5         	PIN_BUZZER	EQU	P5.4	;output
   232  E 000300D5         	PIN_SPI_CSN	EQU	P5.3	;output,Slave Select pin(to CSN, nRF24L01)	
   233  E 000200D5         	PIN_SPI_MOSI	EQU	P5.2	;output,Master Out, Slave In pin 
   234  000000             
   235  000000             ;---------------------------------------------
   236  E 000300D1         	SDA		equ	PIN_I2C_SDA
   237  E 000300C1         	SDA_IoSet	equ	@INT(PIN_I2C_SDA)-0x10.@BIT(PIN_I2C_SDA)
   238  E 000200D1         	SCL		equ	PIN_I2C_SCL
   239  E 000200C1         	SCL_IoSet	equ	@INT(PIN_I2C_SCL)-0x10.@BIT(PIN_I2C_SCL)
   240  000000             
   241  E 0000001A         	I2CackFlag	equ	EEPROMflag.0
   242  E 0001001A         	I2CjoinErrorFlag	equ	EEPROMflag.1
   243  E 0002001A         	I2Csave		equ	EEPROMflag.2
   244  000000             ;--------------------------------------------------------------------
   245  000000             
   246  000000             ;-----------------------------Code Section---------------------------
   247  000000             .CODE
   248  000000             
   249  000000             	ORG 	00h
   250  000000   8322(2)  	jmp	Reset
   251  000001             
   252  000008             	ORG 	08h
   253  000008   8427(2)  	jmp 	ISR

⌨️ 快捷键说明

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