📄 nrf2401.s
字号:
.module nrf2401.c
.area data(ram, con, rel)
_TxBuf::
.blkb 2
.area idata
.byte 'e,'f
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'g,'h
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'i,'j
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'k,'l
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'm,'n
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'o,'p
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'q,'r
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 's,'t
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'u,'v
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 'w,'x
.area data(ram, con, rel)
.dbfile F:\programme\nrf2401\nrf2401.c
.dbsym e TxBuf _TxBuf A[20:20]c
.area text(rom, con, rel)
.dbfile F:\programme\nrf2401\nrf2401.c
.dbfunc e nrf2401A_WR _nrf2401A_WR fV
; i -> R20
; temp -> R22
; val -> R16
.even
_nrf2401A_WR::
rcall push_gset2
.dbline -1
.dbline 76
; #include "config.h"
;
; //extern void DelayMs(uchar ms);
; //extern void DelayUs(uint us);
;
; //注意:
; //1、nef2401A配置字是先写第15字节的!!
; //2、发送后要延时等发送结束后才能转回接收模式,否则数据发送不出
;
;
; #define SIZE 20 //最大数据包长度 32-ADDR4-CRC2=26Byte 25
; #define ADDRSIZE 4 //地址长度Byte
;
; #define CH_NO 2 //频段编号
;
; #define BPS_1M //编译控制:1M or 250Kbps
;
; uchar TxBuf[SIZE]={101,102,103,104,105,106,107,108,109,110,
; 111,112,113,114,115,116,117,118,119,120};
; uchar RxBuf[SIZE];
;
; /*-------------------------------------------------------------------------------------------
; nrf2401A配置寄存器宏定义
; nrf2401A配置寄存器(15Byte)
; 工作频率f=2.4G+CH_NO*1MHz
; -------------------------------------------------------------------------------------------*/
; #define RX_ADDRESS 0xCCCCCCCC //接收有效地址(本方)
; #define TX_ADDRESS 0xCCCCCCCC //发送有效地址(对方)
;
; #define CH_NO_FREQ CH_NO<<1 //工作频段 Byte1.7-2
; #define RX_EN 1 //接收发送切换 Byte1.0 1接收 0发送
;
; #define RX2EN_YES 128 //第2接收通道使能1 Byte2.7
; #define RX2EN_NO 0 //第2接收通道使能0 Byte2.7
; #define CM_SHOCK 64 //收发模式ShockBurst Byte2.6
; #define CM_DIRECT 0 //收发模式DirectMode Byte2.6
; #define RFDR_1M 32 //空中Baud=1M Byte2.5
; #define RFDR_250K 0 //空中Baud=250K Byte2.5
; #define XOF_20MHz 4*4 //晶体振荡器频率20MHz Byte2.4~2
; #define XOF_16MHz 3*4 //晶体振荡器频率16MHz
; #define XOF_12MHz 2*4 //晶体振荡器频率12MHz
; #define XOF_8MHz 1*4 //晶体振荡器频率8MHz
; #define XOF_4MHz 0*4 //晶体振荡器频率4MHz
; #define PA_PWR_0 0 //输出功率-20dBm Byte2.1~0
; #define PA_PWR_1 1 //输出功率-10dBm
; #define PA_PWR_2 2 //输出功率-5dBm
; #define PA_PWR_3 3 //输出功率 0dBm
;
; #define ADDR_W (ADDRSIZE<<5) //地址位数 Byte3.7~2
; #define CRC_MODE_16BIT 2 //CRC16模式 Byte3.1 1
; #define CRC_MODE_8BIT 0 //CRC8模式 Byte3.1
; #define CRC_EN 1 //CRC使能 Byte3.0 1
; #define CRC16_EN 3 //CRC16模式使能
; #define CRC8_EN 1 //CRC8模式使能
;
; #define RX_ADDRESS_0 RX_ADDRESS & 0xff //通道1接收有效地址第1字节 Byte4
; #define RX_ADDRESS_1 (RX_ADDRESS >> 8) & 0xff //通道1接收有效地址第2字节 Byte5
; #define RX_ADDRESS_2 (RX_ADDRESS >> 16) & 0xff //通道1接收有效地址第3字节 Byte6
; #define RX_ADDRESS_3 RX_ADDRESS >> 24 //通道1接收有效地址第4字节 Byte7
; #define RX_ADDRESS_4 0 //通道1接收有效地址第5字节 Byte8
;
; #define RX_ADDRESS2 0 //Byte9,10,11,12,13字节为通道2接收地址
;
; #define DATA1_W SIZE*8 //接收通道1数据包长度,Bit计算 Byte14
; #define DATA2_W SIZE*8 //接收通道2数据包长度,Bit计算 Byte15
;
; #define TX_ADDRESS_4 0 //发送有效地址第5字节
; #define TX_ADDRESS_3 TX_ADDRESS >> 24 //发送有效地址第4字节
; #define TX_ADDRESS_2 (TX_ADDRESS >> 16) & 0xff //发送有效地址第3字节
; #define TX_ADDRESS_1 (TX_ADDRESS >> 8) & 0xff //发送有效地址第2字节
; #define TX_ADDRESS_0 TX_ADDRESS & 0xff //发送有效地址第1字节
;
;
; //写1Byte
; void nrf2401A_WR(uchar val)
; {uchar temp,i;
.dbline 78
; //MSB first 高位开始,先输出DATA,然后CLK_Up,再CLK_Dn
; SET(DDRC,DATA);//置DATA输出
sbi 0x14,3
.dbline 79
; temp=val;
mov R22,R16
.dbline 81
;
; for (i=0;i<8;i++)
clr R20
rjmp L5
L2:
.dbline 82
; {
.dbline 83
; if ((temp&0x80)>0)
clr R2
mov R24,R22
andi R24,128
cp R2,R24
brsh L6
.dbline 84
; SET(PORTC,DATA);
sbi 0x15,3
rjmp L7
L6:
.dbline 86
; else
; CLR(PORTC,DATA);
cbi 0x15,3
L7:
.dbline 88
nop
.dbline 89
sbi 0x15,1
.dbline 90
nop
.dbline 91
nop
.dbline 92
nop
.dbline 93
nop
.dbline 94
cbi 0x15,1
.dbline 96
lsl R22
.dbline 97
L3:
.dbline 81
inc R20
L5:
.dbline 81
cpi R20,8
brlo L2
.dbline -2
L1:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r temp 22 c
.dbsym r val 16 c
.dbend
.dbfunc e nrf2401A_RD _nrf2401A_RD fc
; i -> R16
; temp -> R18
.even
_nrf2401A_RD::
.dbline -1
.dbline 102
;
; NOP();
; SET(PORTC,CLK1);
; NOP();
; NOP();
; NOP();
; NOP();
; CLR(PORTC,CLK1);
;
; temp=temp<<1;
; }
; }
;
; //读1Byte
; uchar nrf2401A_RD()
; {uchar temp=0,i;
.dbline 102
clr R18
.dbline 104
; //MSB first 高位开始,先读入DATA,然后CLK_Up,再CLK_Dn
; CLR(DDRC,DATA);//置DATA输入
cbi 0x14,3
.dbline 105
; temp=0;
.dbline 107
;
; for (i=0;i<8;i++)
clr R16
rjmp L12
L9:
.dbline 108
; {
.dbline 109
; temp=temp<<1;
lsl R18
.dbline 110
; if ((PINC&(1<<DATA)))
sbis 0x13,3
rjmp L13
.dbline 111
; temp=temp|0x01;
ori R18,1
rjmp L14
L13:
.dbline 112
; else temp=temp&0xfe;
andi R18,254
L14:
.dbline 114
sbi 0x15,1
.dbline 115
nop
.dbline 116
nop
.dbline 117
nop
.dbline 118
cbi 0x15,1
.dbline 119
L10:
.dbline 107
inc R16
L12:
.dbline 107
cpi R16,8
brlo L9
.dbline 121
;
; SET(PORTC,CLK1);
; NOP();
; NOP();
; NOP();
; CLR(PORTC,CLK1);
; }
;
; return temp;
mov R16,R18
.dbline -2
L8:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbsym r temp 18 c
.dbend
.dbfunc e nrf2401A_StandBy _nrf2401A_StandBy fV
.even
_nrf2401A_StandBy::
.dbline -1
.dbline 126
; }
;
; //PwrDown->StandBy
; void nrf2401A_StandBy()
; {
.dbline 127
; SET(PORTB,PWR);
sbi 0x18,6
.dbline 128
; CLR(PORTD,CE);
cbi 0x12,4
.dbline 129
; CLR(PORTB,CS);
cbi 0x18,1
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_Off _nrf2401A_Off fV
.even
_nrf2401A_Off::
.dbline -1
.dbline 134
; }
;
; //->PwrDown
; void nrf2401A_Off()
; {
.dbline 135
; CLR(PORTB,PWR);
cbi 0x18,6
.dbline 136
; CLR(PORTD,CE);
cbi 0x12,4
.dbline 137
; CLR(PORTB,CS);
cbi 0x18,1
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_RwOn _nrf2401A_RwOn fV
.even
_nrf2401A_RwOn::
.dbline -1
.dbline 142
; }
;
; //配置模式
; void nrf2401A_RwOn()
; {
.dbline 143
; SET(PORTB,PWR);
sbi 0x18,6
.dbline 144
; CLR(PORTD,CE);
cbi 0x12,4
.dbline 145
; SET(PORTB,CS);
sbi 0x18,1
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_Run _nrf2401A_Run fV
.even
_nrf2401A_Run::
.dbline -1
.dbline 150
; }
;
; //工作模式
; void nrf2401A_Run()
; {
.dbline 151
; SET(PORTC,PWR);
sbi 0x15,6
.dbline 152
; CLR(PORTB,CS); //first
cbi 0x18,1
.dbline 153
; SET(PORTD,CE);
sbi 0x12,4
.dbline -2
L18:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_Config _nrf2401A_Config fV
.even
_nrf2401A_Config::
.dbline -1
.dbline 156
; }
; void nrf2401A_Config(void)
; {
.dbline 157
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -