📄 nrf2401a.s
字号:
.module nrf2401A.C
.area text(rom, con, rel)
.dbfile D:\IccAvr\Pei\PTR4000\nrf2401A.C
.dbfunc e nrf2401A_WR _nrf2401A_WR fV
; i -> R20
; temp -> R22
; val -> R16
.even
_nrf2401A_WR::
xcall push_gset2
.dbline -1
.dbline 74
; #include "config.h"
;
; extern void DelayMs(uchar ms);
; extern void DelayUs(uint us);
;
; //注意:
; //1、nef2401A配置字是先写第15字节的!!
; //2、发送后要延时等发送结束后才能转回接收模式,否则数据发送不出
;
;
; #define SIZE 25 //最大数据包长度 32-ADDR4-CRC2=26Byte
; #define ADDRSIZE 4 //地址长度Byte
;
; #define CH_NO 2 //频段编号
;
; #define BPS_1M //编译控制:1M or 250Kbps
;
; uchar TxBuf[SIZE],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 76
; //MSB first 高位开始,先输出DATA,然后CLK_Up,再CLK_Dn
; SET(DDRA,DATA);//置DATA输出
sbi 0x1a,5
.dbline 77
; temp=val;
mov R22,R16
.dbline 79
;
; for (i=0;i<8;i++)
clr R20
xjmp L5
L2:
.dbline 80
; {
.dbline 81
; if ((temp&0x80)>0)
clr R2
mov R24,R22
andi R24,128
cp R2,R24
brsh L6
.dbline 82
; SET(PORTA,DATA);
sbi 0x1b,5
xjmp L7
L6:
.dbline 84
; else
; CLR(PORTA,DATA);
cbi 0x1b,5
L7:
.dbline 86
nop
.dbline 87
sbi 0x1b,4
.dbline 88
nop
.dbline 89
cbi 0x1b,4
.dbline 91
lsl R22
.dbline 92
L3:
.dbline 79
inc R20
L5:
.dbline 79
cpi R20,8
brlo L2
.dbline -2
L1:
xcall 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 97
;
; NOP();
; SET(PORTA,CLK);
; NOP();
; CLR(PORTA,CLK);
;
; temp=temp<<1;
; }
; }
;
; //读1Byte
; uchar nrf2401A_RD()
; {uchar temp,i;
.dbline 99
; //MSB first 高位开始,先读入DATA,然后CLK_Up,再CLK_Dn
; CLR(DDRA,DATA);//置DATA输入
cbi 0x1a,5
.dbline 100
; temp=0;
clr R18
.dbline 102
;
; for (i=0;i<8;i++)
clr R16
xjmp L12
L9:
.dbline 103
; {
.dbline 104
; temp=temp<<1;
lsl R18
.dbline 105
; if ((PINA&(1<<DATA))>0)
clr R2
in R24,0x19
andi R24,32
cp R2,R24
brsh L13
.dbline 106
; temp=temp|1;
ori R18,1
L13:
.dbline 108
nop
.dbline 109
sbi 0x1b,4
.dbline 110
nop
.dbline 111
cbi 0x1b,4
.dbline 112
L10:
.dbline 102
inc R16
L12:
.dbline 102
cpi R16,8
brlo L9
.dbline 114
;
; NOP();
; SET(PORTA,CLK);
; NOP();
; CLR(PORTA,CLK);
; }
;
; 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 119
; }
;
; //PwrDown->StandBy
; void nrf2401A_StandBy()
; {
.dbline 120
; SET(PORTA,PWR2);
sbi 0x1b,0
.dbline 121
; CLR(PORTA,CE);
cbi 0x1b,1
.dbline 122
; CLR(PORTA,CS);
cbi 0x1b,2
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_Off _nrf2401A_Off fV
.even
_nrf2401A_Off::
.dbline -1
.dbline 127
; }
;
; //->PwrDown
; void nrf2401A_Off()
; {
.dbline 128
; CLR(PORTA,PWR2);
cbi 0x1b,0
.dbline 129
; CLR(PORTA,CE);
cbi 0x1b,1
.dbline 130
; CLR(PORTA,CS);
cbi 0x1b,2
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_RwOn _nrf2401A_RwOn fV
.even
_nrf2401A_RwOn::
.dbline -1
.dbline 135
; }
;
; //配置模式
; void nrf2401A_RwOn()
; {
.dbline 136
; SET(PORTA,PWR2);
sbi 0x1b,0
.dbline 137
; CLR(PORTA,CE);
cbi 0x1b,1
.dbline 138
; SET(PORTA,CS);
sbi 0x1b,2
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_Run _nrf2401A_Run fV
.even
_nrf2401A_Run::
.dbline -1
.dbline 144
;
; }
;
; //工作模式
; void nrf2401A_Run()
; {
.dbline 145
; SET(PORTA,PWR2);
sbi 0x1b,0
.dbline 146
; CLR(PORTA,CS);//first
cbi 0x1b,2
.dbline 147
; SET(PORTA,CE);
sbi 0x1b,1
.dbline -2
L18:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_Config _nrf2401A_Config fV
.even
_nrf2401A_Config::
.dbline -1
.dbline 153
;
; }
;
; //配置nRF2401A
; void nrf2401A_Config(void)
; {
.dbline 154
; nrf2401A_RwOn();//配置状态
xcall _nrf2401A_RwOn
.dbline 156
;
; nrf2401A_WR(DATA2_W);
ldi R16,200
xcall _nrf2401A_WR
.dbline 157
; nrf2401A_WR(DATA1_W);
ldi R16,200
xcall _nrf2401A_WR
.dbline 158
; nrf2401A_WR(RX_ADDRESS2);
clr R16
xcall _nrf2401A_WR
.dbline 159
; nrf2401A_WR(RX_ADDRESS2);
clr R16
xcall _nrf2401A_WR
.dbline 160
; nrf2401A_WR(RX_ADDRESS2);
clr R16
xcall _nrf2401A_WR
.dbline 161
; nrf2401A_WR(RX_ADDRESS2);
clr R16
xcall _nrf2401A_WR
.dbline 162
; nrf2401A_WR(RX_ADDRESS2);
clr R16
xcall _nrf2401A_WR
.dbline 163
; nrf2401A_WR(RX_ADDRESS_4);
clr R16
xcall _nrf2401A_WR
.dbline 164
; nrf2401A_WR(RX_ADDRESS_3);
ldi R16,204
xcall _nrf2401A_WR
.dbline 165
; nrf2401A_WR(RX_ADDRESS_2);
ldi R16,204
xcall _nrf2401A_WR
.dbline 166
; nrf2401A_WR(RX_ADDRESS_1);
ldi R16,204
xcall _nrf2401A_WR
.dbline 167
; nrf2401A_WR(RX_ADDRESS_0);
ldi R16,204
xcall _nrf2401A_WR
.dbline 168
; nrf2401A_WR(CRC16_EN|ADDR_W);//CRC16,AddrWidth
ldi R16,131
xcall _nrf2401A_WR
.dbline 171
;
; #ifdef BPS_1M
; nrf2401A_WR(PA_PWR_3|XOF_16MHz|RFDR_1M|CM_SHOCK);//0dbm,16M,1Mbps,ShockBurst
ldi R16,111
xcall _nrf2401A_WR
.dbline 176
; #else
; nrf2401A_WR(PA_PWR_3|XOF_16MHz|CM_SHOCK);//0dbm,16M,250Kbps,ShockBurst
; #endif
;
; nrf2401A_WR(CH_NO_FREQ|RX_EN); //RxMode,Chan
ldi R16,5
xcall _nrf2401A_WR
.dbline 178
;
; nrf2401A_StandBy();//执行配置
xcall _nrf2401A_StandBy
.dbline -2
L19:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_RxOn _nrf2401A_RxOn fV
.even
_nrf2401A_RxOn::
.dbline -1
.dbline 183
; }
;
; //接收模式
; void nrf2401A_RxOn()
; {
.dbline 184
; nrf2401A_RwOn();
xcall _nrf2401A_RwOn
.dbline 185
; nrf2401A_WR(CH_NO_FREQ|RX_EN); //RxMode,Chan
ldi R16,5
xcall _nrf2401A_WR
.dbline 186
; nrf2401A_Run();
xcall _nrf2401A_Run
.dbline -2
L20:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_TxOn _nrf2401A_TxOn fV
.even
_nrf2401A_TxOn::
.dbline -1
.dbline 191
; }
;
; //发送模式
; void nrf2401A_TxOn()
; {
.dbline 192
; nrf2401A_RwOn();
xcall _nrf2401A_RwOn
.dbline 193
; nrf2401A_WR(CH_NO_FREQ); //TxMode,Chan
ldi R16,4
xcall _nrf2401A_WR
.dbline 194
; nrf2401A_Run();
xcall _nrf2401A_Run
.dbline -2
L21:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_Init _nrf2401A_Init fV
.even
_nrf2401A_Init::
.dbline -1
.dbline 199
; }
;
; //初始化nrf2401A
; void nrf2401A_Init()
; {
.dbline 200
; CLR(PORTA,CLK);//
cbi 0x1b,4
.dbline 201
; nrf2401A_StandBy();
xcall _nrf2401A_StandBy
.dbline 202
; DelayMs(10);//!!!must >3ms
ldi R16,10
xcall _DelayMs
.dbline 203
; nrf2401A_Config();
xcall _nrf2401A_Config
.dbline 205
;
; nrf2401A_RxOn();//接收状态
xcall _nrf2401A_RxOn
.dbline -2
L22:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_SetTxAddr _nrf2401A_SetTxAddr fV
.even
_nrf2401A_SetTxAddr::
.dbline -1
.dbline 211
; }
;
;
; //写Tx地址
; void nrf2401A_SetTxAddr()
; {
.dbline 212
; nrf2401A_WR(TX_ADDRESS_3);
ldi R16,204
xcall _nrf2401A_WR
.dbline 213
; nrf2401A_WR(TX_ADDRESS_2);
ldi R16,204
xcall _nrf2401A_WR
.dbline 214
; nrf2401A_WR(TX_ADDRESS_1);
ldi R16,204
xcall _nrf2401A_WR
.dbline 215
; nrf2401A_WR(TX_ADDRESS_0);
ldi R16,204
xcall _nrf2401A_WR
.dbline -2
L23:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_SetData _nrf2401A_SetData fV
; i -> R20
.even
_nrf2401A_SetData::
xcall push_gset1
.dbline -1
.dbline 221
;
; }
;
; //写Tx数据
; void nrf2401A_SetData()
; {uchar i;
.dbline 223
;
; for (i=0;i<SIZE;i++)
clr R20
xjmp L28
L25:
.dbline 224
ldi R24,<_TxBuf
ldi R25,>_TxBuf
mov R30,R20
clr R31
add R30,R24
adc R31,R25
ldd R16,z+0
xcall _nrf2401A_WR
L26:
.dbline 223
inc R20
L28:
.dbline 223
cpi R20,25
brlo L25
.dbline -2
L24:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
.dbfunc e nrf2401A_SendData _nrf2401A_SendData fV
.even
_nrf2401A_SendData::
.dbline -1
.dbline 230
; nrf2401A_WR(TxBuf[i]);
;
; }
;
; //发送TxBuf中的数据
; void nrf2401A_SendData()
; {
.dbline 231
; nrf2401A_TxOn();
xcall _nrf2401A_TxOn
.dbline 232
; SET(PORTA,CE);
sbi 0x1b,1
.dbline 233
; nrf2401A_SetTxAddr();//写发送地址
xcall _nrf2401A_SetTxAddr
.dbline 234
; nrf2401A_SetData();//写数据
xcall _nrf2401A_SetData
.dbline 235
; CLR(PORTA,CE);//启动发送
cbi 0x1b,1
.dbline -2
L29:
.dbline 0 ; func end
ret
.dbend
.dbfunc e nrf2401A_ReadData _nrf2401A_ReadData fV
; i -> R20
.even
_nrf2401A_ReadData::
xcall push_gset1
.dbline -1
.dbline 243
; //发送完毕后进入StandBy
;
; }
;
;
; //读出接收到的数据
; void nrf2401A_ReadData()
; {uchar i;
.dbline 244
; for (i=0;i<SIZE;i++)
clr R20
xjmp L34
L31:
.dbline 245
.dbline 246
xcall _nrf2401A_RD
ldi R24,<_RxBuf
ldi R25,>_RxBuf
mov R30,R20
clr R31
add R30,R24
adc R31,R25
std z+0,R16
.dbline 247
L32:
.dbline 244
inc R20
L34:
.dbline 244
cpi R20,25
brlo L31
.dbline -2
L30:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbend
.area bss(ram, con, rel)
.dbfile D:\IccAvr\Pei\PTR4000\nrf2401A.C
_RxBuf::
.blkb 25
.dbsym e RxBuf _RxBuf A[25:25]c
_TxBuf::
.blkb 25
.dbsym e TxBuf _TxBuf A[25:25]c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -