📄 cc2420.s
字号:
.module cc2420.c
.area text(rom, con, rel)
.dbfile C:\AVR\cc2420驱动程序\code\cc2420.c
.dbfunc e Write_Command _Write_Command fc
; statueval -> R20
; command -> R20
.even
_Write_Command::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 12
; #include "cc2420.h"
; #include "spi.h"
; #include "common.h"
;
; /*******************************************
; *函数功能:写命令寄存器
; *输入参数:命令字
; *输出参数:无
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Write_Command(unsigned char command)
; {
.dbline 15
; unsigned char statueval;
;
; enable_spi(); //使能SPI口
xcall _enable_spi
.dbline 16
; statueval=SpiWrite(command);
mov R16,R20
xcall _SpiWrite
mov R20,R16
.dbline 17
; disable_spi(); //禁止SPI口
xcall _disable_spi
.dbline 19
;
; return statueval;
mov R16,R20
.dbline -2
L1:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r statueval 20 c
.dbsym r command 20 c
.dbend
.dbfunc e Read_Status _Read_Status fc
; statuevalue -> R20
.even
_Read_Status::
xcall push_gset1
.dbline -1
.dbline 29
; }
;
; /*******************************************
; *函数功能:读状态寄存器
; *输入参数:无
; *输出参数:无
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Read_Status(void)
; {
.dbline 31
; unsigned char statuevalue;
; statuevalue=Write_Command(SNOP); //空操作命令,为了读取当前状态寄存器的值
clr R16
xcall _Write_Command
mov R20,R16
.dbline 32
; return statuevalue;
.dbline -2
L2:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r statuevalue 20 c
.dbend
.dbfunc e Write_ConfigureWord _Write_ConfigureWord fc
; statuevalue -> R20
; DataL -> y+4
; DataH -> R22
; Addr -> R20
.even
_Write_ConfigureWord::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 44
; }
;
; /*******************************************
; *函数功能:写配置字
; *输入参数:Addr:配置寄存器的地址;
; DataH:配置字的高字节;
; DataL:配置字的低字节;
; *输出参数:无
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Write_ConfigureWord(unsigned char Addr,unsigned char DataH,unsigned char DataL)
; {
.dbline 48
; unsigned char statuevalue;
;
; // enable_spi(); //使能SPI口 以具体情况而定使能/禁止SPI口放在何处
; statuevalue=SpiWrite(Addr); //发送配置寄存器的地址,同时返回当前状态寄存器的值
mov R16,R20
xcall _SpiWrite
mov R20,R16
.dbline 49
; SpiWrite(DataH); //发送配置字的高字节
mov R16,R22
xcall _SpiWrite
.dbline 50
; SpiWrite(DataL); //发送配置字的低字节
ldd R16,y+4
xcall _SpiWrite
.dbline 53
; // disable_spi(); //禁止SPI口
;
; return statuevalue;
mov R16,R20
.dbline -2
L3:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r statuevalue 20 c
.dbsym l DataL 4 c
.dbsym r DataH 22 c
.dbsym r Addr 20 c
.dbend
.dbfunc e Read_ConfigureWord _Read_ConfigureWord fc
; statuevalue -> R20
; DataL -> y+4
; DataH -> R22,R23
; Addr -> R20
.even
_Read_ConfigureWord::
xcall push_gset2
movw R22,R18
mov R20,R16
.dbline -1
.dbline 64
; }
;
; /*******************************************
; *函数功能:读配置字
; *输入参数:Addr:配置寄存器的地址;
; *输出参数:DataH:配置字的高字节;
; DataL:配置字的低字节;
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Read_ConfigureWord(unsigned char Addr,unsigned char *DataH,unsigned char *DataL)
; {
.dbline 67
; unsigned char statuevalue;
;
; Addr|=0x40; //读标志位为1
ori R20,64
.dbline 68
; enable_spi(); //使能SPI口 以具体情况而定使能/禁止SPI口放在何处
xcall _enable_spi
.dbline 69
; statuevalue=SpiWrite(Addr); //发送配置寄存器的地址,同时返回当前状态寄存器的值
mov R16,R20
xcall _SpiWrite
mov R20,R16
.dbline 70
; *DataH=SpiWrite(0xff); //读配置字的高字节
ldi R16,255
xcall _SpiWrite
movw R30,R22
std z+0,R16
.dbline 71
; *DataL=SpiWrite(0xff); //读配置字的低字节
ldi R16,255
xcall _SpiWrite
mov R2,R16
ldd R30,y+4
ldd R31,y+5
std z+0,R2
.dbline 72
; disable_spi(); //禁止SPI口
xcall _disable_spi
.dbline 74
;
; return statuevalue;
mov R16,R20
.dbline -2
L4:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r statuevalue 20 c
.dbsym l DataL 4 pc
.dbsym r DataH 22 pc
.dbsym r Addr 20 c
.dbend
.dbfunc e Read_RXFIFO _Read_RXFIFO fc
; Addr -> R20
; statuevalue -> R20
; i -> R22
; p_Data -> R10,R11
; Data_Num -> R12
.even
_Read_RXFIFO::
xcall push_gset4
movw R10,R18
mov R12,R16
.dbline -1
.dbline 84
; }
;
; /*******************************************
; *函数功能:读RXFIFO
; *输入参数:Data_Num:欲读取的字节个数
; *输出参数:p_Data:存储数据的缓存首地址;
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Read_RXFIFO(unsigned char Data_Num,unsigned char *p_Data)
; {
.dbline 87
; unsigned char statuevalue,Addr,i;
;
; Addr=RXFIFO|0x40; //读标志位为1
ldi R20,127
.dbline 88
; enable_spi(); //使能SPI口
xcall _enable_spi
.dbline 89
; statuevalue=SpiWrite(Addr);
mov R16,R20
xcall _SpiWrite
mov R20,R16
.dbline 91
;
; for(i=0;i<Data_Num;i++)
clr R22
xjmp L9
L6:
.dbline 92
.dbline 93
ldi R16,255
xcall _SpiWrite
mov R30,R22
clr R31
add R30,R10
adc R31,R11
std z+0,R16
.dbline 94
L7:
.dbline 91
inc R22
L9:
.dbline 91
cp R22,R12
brlo L6
.dbline 96
; {
; *(p_Data+i)=SpiWrite(0xff);
; }
;
; disable_spi(); //禁止SPI口
xcall _disable_spi
.dbline 98
;
; return statuevalue;
mov R16,R20
.dbline -2
L5:
xcall pop_gset4
.dbline 0 ; func end
ret
.dbsym r Addr 20 c
.dbsym r statuevalue 20 c
.dbsym r i 22 c
.dbsym r p_Data 10 pc
.dbsym r Data_Num 12 c
.dbend
.dbfunc e Read_RXFIFO_Byte _Read_RXFIFO_Byte fc
; Addr -> R20
; readvalue -> R20
.even
_Read_RXFIFO_Byte::
xcall push_gset1
.dbline -1
.dbline 108
; }
;
; /*******************************************
; *函数功能:读一字节RXFIFO
; *输入参数:无
; *输出参数:无
; *返 回 值:读取的数据
; ********************************************/
; unsigned char Read_RXFIFO_Byte(void)
; {
.dbline 111
; unsigned char readvalue,Addr;
;
; Addr=RXFIFO|0x40; //读标志位为1
ldi R20,127
.dbline 112
; enable_spi(); //使能SPI口
xcall _enable_spi
.dbline 113
; SpiWrite(Addr);
mov R16,R20
xcall _SpiWrite
.dbline 114
; readvalue=SpiWrite(0xff);
ldi R16,255
xcall _SpiWrite
mov R20,R16
.dbline 115
; disable_spi(); //禁止SPI口
xcall _disable_spi
.dbline 116
; return readvalue;
mov R16,R20
.dbline -2
L10:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r Addr 20 c
.dbsym r readvalue 20 c
.dbend
.dbfunc e Write_TXFIFO _Write_TXFIFO fc
; statuevalue -> R20
; i -> R22
; p_Data -> R10,R11
; Data_Num -> R12
.even
_Write_TXFIFO::
xcall push_gset4
movw R10,R18
mov R12,R16
.dbline -1
.dbline 126
; }
;
; /*******************************************
; *函数功能:写TXFIFO
; *输入参数:Data_Num:欲写入的字节个数
; *输出参数:p_Data:存储数据的缓存首地址;
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Write_TXFIFO(unsigned char Data_Num,unsigned char *p_Data)
; {
.dbline 129
; unsigned char statuevalue,i;
;
; enable_spi(); //使能SPI口
xcall _enable_spi
.dbline 130
; SpiWrite(TXFIFO);
ldi R16,62
xcall _SpiWrite
.dbline 132
;
; for (i=0;i<Data_Num;i++)
clr R22
xjmp L15
L12:
.dbline 133
; {
.dbline 134
; statuevalue=SpiWrite(*(p_Data+i));
mov R30,R22
clr R31
add R30,R10
adc R31,R11
ldd R16,z+0
xcall _SpiWrite
mov R20,R16
.dbline 136
;
; if ((statuevalue&(1<<TX_UNDERFLOE))!=0x00) //发生下溢
sbrs R16,5
rjmp L16
.dbline 137
; {
.dbline 138
; Write_Command(SFLUSHTX);
ldi R16,9
xcall _Write_Command
.dbline 139
; enable_spi(); //重新使能SPI口
xcall _enable_spi
.dbline 140
; }
L16:
.dbline 141
L13:
.dbline 132
inc R22
L15:
.dbline 132
cp R22,R12
brlo L12
.dbline 143
; }
;
; disable_spi(); //禁止SPI口
xcall _disable_spi
.dbline 144
; return statuevalue;
mov R16,R20
.dbline -2
L11:
xcall pop_gset4
.dbline 0 ; func end
ret
.dbsym r statuevalue 20 c
.dbsym r i 22 c
.dbsym r p_Data 10 pc
.dbsym r Data_Num 12 c
.dbend
.dbfunc e Write_TXFIFO_Byte _Write_TXFIFO_Byte fc
; statuevalue -> R20
; p_Data -> R20
.even
_Write_TXFIFO_Byte::
xcall push_gset1
mov R20,R16
.dbline -1
.dbline 154
; }
;
; /*******************************************
; *函数功能:写一字节TXFIFO
; *输入参数:p_Data:要写入的数据
; *输出参数:无
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Write_TXFIFO_Byte(unsigned char p_Data)
; {
.dbline 157
; unsigned char statuevalue;
;
; enable_spi(); //使能SPI口
xcall _enable_spi
.dbline 158
; SpiWrite(TXFIFO);
ldi R16,62
xcall _SpiWrite
.dbline 159
; statuevalue=SpiWrite(p_Data);
mov R16,R20
xcall _SpiWrite
mov R20,R16
.dbline 160
; disable_spi(); //禁止SPI口
xcall _disable_spi
.dbline 161
; return statuevalue;
mov R16,R20
.dbline -2
L18:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r statuevalue 20 c
.dbsym r p_Data 20 c
.dbend
.dbfunc e Write_RAM _Write_RAM fc
; statuevalue -> R20
; i -> R22
; p_Data -> R10,R11
; Data_Num -> R12
; AddrL -> R22
; AddrH -> R20
.even
_Write_RAM::
xcall push_gset4
mov R22,R18
mov R20,R16
ldd R12,y+8
ldd R10,y+10
ldd R11,y+11
.dbline -1
.dbline 174
; }
;
; /*******************************************
; *函数功能:写RAM
; *输入参数:p_Data:存储数据的缓存首地址;
; Data_Num:要写入的字节数
; AddrH:在选定的RAM存储块中确定RAM地址
; AddrL:选择RAM存储块
; *输出参数:无
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Write_RAM(unsigned char AddrH,unsigned char AddrL,unsigned char Data_Num,unsigned char *p_Data)
; {
.dbline 176
; unsigned char statuevalue,i;
; AddrH|=0X80; //访问RAM位置1
ori R20,128
.dbline 177
; AddrL<<=6;
lsl R22
lsl R22
lsl R22
lsl R22
lsl R22
lsl R22
.dbline 178
; AddrL&=0XDF; //读写操作位置0,表示写操作
andi R22,223
.dbline 180
;
; enable_spi(); //使能SPI口
xcall _enable_spi
.dbline 181
; statuevalue=SpiWrite(AddrH);
mov R16,R20
xcall _SpiWrite
mov R20,R16
.dbline 182
; SpiWrite(AddrL);
mov R16,R22
xcall _SpiWrite
.dbline 184
;
; for (i=0;i<Data_Num;i++)
clr R22
xjmp L23
L20:
.dbline 185
.dbline 186
mov R30,R22
clr R31
add R30,R10
adc R31,R11
ldd R16,z+0
xcall _SpiWrite
.dbline 187
L21:
.dbline 184
inc R22
L23:
.dbline 184
cp R22,R12
brlo L20
.dbline 189
; {
; SpiWrite(*(p_Data+i));
; }
;
; disable_spi(); //禁止SPI口
xcall _disable_spi
.dbline 190
; return statuevalue;
mov R16,R20
.dbline -2
L19:
xcall pop_gset4
.dbline 0 ; func end
ret
.dbsym r statuevalue 20 c
.dbsym r i 22 c
.dbsym r p_Data 10 pc
.dbsym r Data_Num 12 c
.dbsym r AddrL 22 c
.dbsym r AddrH 20 c
.dbend
.dbfunc e Write_RAM_Byte _Write_RAM_Byte fc
; statuevalue -> R20
; p_Data -> y+4
; AddrL -> R22
; AddrH -> R20
.even
_Write_RAM_Byte::
xcall push_gset2
mov R22,R18
mov R20,R16
.dbline -1
.dbline 202
; }
;
; /*******************************************
; *函数功能:写一字节RAM
; *输入参数:p_Data:要写入的数据
; AddrH:在选定的RAM存储块中确定RAM地址
; AddrL:选择RAM存储块
; *输出参数:无
; *返 回 值:状态寄存器的值
; ********************************************/
; unsigned char Write_RAM_Byte(unsigned char AddrH,unsigned char AddrL,unsigned char p_Data)
; {
.dbline 204
; unsigned char statuevalue;
; AddrH|=0X80; //访问RAM位置1
ori R20,128
.dbline 205
; AddrL<<=6;
lsl R22
lsl R22
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -