📄 cc1100.s
字号:
.module cc1100.c
.area lit(rom, con, rel)
_rfSettings::
.byte 0
.byte 11
.byte 0
.byte 16
.byte 167
.byte 98
.byte 45
.byte 59
.byte 115
.byte 162
.byte 248
.byte 0
.byte 0
.byte 182
.byte 16
.byte 24
.byte 29
.byte 28
.byte 199
.byte 0
.byte 178
.byte 234
.byte 10
.byte 0
.byte 17
.byte 89
.byte 136
.byte 49
.byte 11
.byte 6
.byte 6
.byte 5
.byte 69
.byte 240
.byte 240
.dbfile E:\学习基地\IMPORT~1\CC1100-RF-Design\cc1100-design\Firmware\M8_cc1100_receive\cc1100.c
.dbsym e rfSettings _rfSettings kX
.area text(rom, con, rel)
.dbfile E:\学习基地\IMPORT~1\CC1100-RF-Design\cc1100-design\Firmware\M8_cc1100_receive\cc1100.c
.dbfunc e delay _delay fV
; i -> R20,R21
; s -> R16,R17
.even
_delay::
rcall push_gset1
.dbline -1
.dbline 105
; /*C**************************************************************************
; * NAME: cc1100.c
; *----------------------------------------------------------------------------
; * Copyright (c) 2007 endylu
; *----------------------------------------------------------------------------
; * RELEASE: M8-cc1100
; * REVISION: 1.0
; *----------------------------------------------------------------------------
; * PURPOSE:
; * This file include cc1100 receive and send function
; *****************************************************************************/
;
; /*_____ I N C L U D E S ____________________________________________________*/
;
; #include <iom8v.h>
; #include <macros.h>
; #include "main.h"
; /*_____ M A C R O S ________________________________________________________*/
;
;
; /*_____ D E F I N I T I O N ________________________________________________*/
;
;
; //------------------------------------------------------------------------------------------------------
; // Chipcon
; // Product = CC1100
; // Chip version = E
; // Crystal accuracy = 40 ppm
; // X-tal frequency = 26 MHz
; // RF output power = 0 dBm
; // RX filterbandwidth = 540.000000 kHz
; // Deviation = 0.000000
; // Datarate = 250.000000 kbps
; // Modulation = (7) MSK
; // Manchester enable = (0) Manchester disabled
; // RF Frequency = 433.000000 MHz
; // Channel spacing = 199.951172 kHz
; // Channel number = 0
; // Optimization = Sensitivity
; // Sync mode = (3) 30/32 sync word bits detected
; // Format of RX/TX data = (0) Normal mode, use FIFOs for RX and TX
; // CRC operation = (1) CRC calculation in TX and CRC check in RX enabled
; // Forward Error Correction = (0) FEC disabled
; // Length configuration = (1) Variable length packets, packet length configured by the first received byte after sync word.
; // Packetlength = 255
; // Preamble count = (2) 4 bytes
; // Append status = 1
; // Address check = (0) No address check
; // FIFO autoflush = 0
; // Device address = 0
; // GDO0 signal selection = ( 6) Asserts when sync word has been sent / received, and de-asserts at the end of the packet
; // GDO2 signal selection = (11) Serial Clock
; const RF_SETTINGS rfSettings = {
; 0x00,
; 0x0B, // FSCTRL1 Frequency synthesizer control.
; 0x00, // FSCTRL0 Frequency synthesizer control.
; 0x10, // FREQ2 Frequency control word, high byte.
; 0xA7, // FREQ1 Frequency control word, middle byte.
; 0x62, // FREQ0 Frequency control word, low byte.
; 0x2D, // MDMCFG4 Modem configuration.
; 0x3B, // MDMCFG3 Modem configuration.
; 0x73, // MDMCFG2 Modem configuration.
; 0xa2, // MDMCFG1 Modem configuration.
; 0xF8, // MDMCFG0 Modem configuration.
;
; 0x00, // CHANNR Channel number.
; 0x00, // DEVIATN Modem deviation setting (when FSK modulation is enabled).
; 0xB6, // FREND1 Front end RX configuration.
; 0x10, // FREND0 Front end RX configuration.
; 0x18, // MCSM0 Main Radio Control State Machine configuration.
; 0x1D, // FOCCFG Frequency Offset Compensation Configuration.
; 0x1C, // BSCFG Bit synchronization Configuration.
; 0xC7, // AGCCTRL2 AGC control.
; 0x00, // AGCCTRL1 AGC control.
; 0xB2, // AGCCTRL0 AGC control.
;
; 0xEA, // FSCAL3 Frequency synthesizer calibration.
; 0x0A, // FSCAL2 Frequency synthesizer calibration.
; 0x00, // FSCAL1 Frequency synthesizer calibration.
; 0x11, // FSCAL0 Frequency synthesizer calibration.
; 0x59, // FSTEST Frequency synthesizer calibration.
; 0x88, // TEST2 Various test settings.
; 0x31, // TEST1 Various test settings.
; 0x0B, // TEST0 Various test settings.
; 0x06, //IOCFG2 GDO2 output pin configuration.
; 0x06, // IOCFG0 GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.
;
; 0x05, // PKTCTRL1 Packet automation control.
; 0x45, // PKTCTRL0 Packet automation control.
; ID_Oneself, // ADDR Device address.
; 0xf0, // PKTLEN Packet length.
; };
;
; /*_____ D E C L A R A T I O N ______________________________________________*/
;
;
;
; //*****************************************************************************************
; //函数名:delay(unsigned int s)
; //输入:时间
; //输出:无
; //功能描述:普通廷时
; //*****************************************************************************************
; void delay(unsigned int s)
; {
.dbline 107
clr R20
clr R21
rjmp L5
L2:
.dbline 107
L3:
.dbline 107
subi R20,255 ; offset = 1
sbci R21,255
L5:
.dbline 107
; unsigned int i;
; for(i=0; i<s; i++);
cp R20,R16
cpc R21,R17
brlo L2
.dbline 108
clr R20
clr R21
rjmp L9
L6:
.dbline 108
L7:
.dbline 108
subi R20,255 ; offset = 1
sbci R21,255
L9:
.dbline 108
; for(i=0; i<s; i++);
cp R20,R16
cpc R21,R17
brlo L6
.dbline -2
L1:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r i 20 i
.dbsym r s 16 i
.dbend
.dbfunc e halWait _halWait fV
; timeout -> R16,R17
.even
_halWait::
.dbline -1
.dbline 112
; }
;
;
; void halWait(INT16U timeout) {
L11:
.dbline 113
; do {
.dbline 114
; _nop_();
nop
.dbline 115
; _nop_();
nop
.dbline 116
; _nop_();
nop
.dbline 117
; _nop_();
nop
.dbline 118
; _nop_();
nop
.dbline 119
; _nop_();
nop
.dbline 120
; _nop_();
nop
.dbline 121
; _nop_();
nop
.dbline 122
; _nop_();
nop
.dbline 123
; _nop_();
nop
.dbline 124
; _nop_();
nop
.dbline 125
; _nop_();
nop
.dbline 126
; _nop_();
nop
.dbline 127
; _nop_();
nop
.dbline 128
; _nop_();
nop
.dbline 129
L12:
.dbline 129
; } while (--timeout);
movw R24,R16
sbiw R24,1
movw R16,R24
cpi R16,0
cpc R16,R17
brne L11
X0:
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbsym r timeout 16 i
.dbend
.dbfunc e UartInit _UartInit fV
.even
_UartInit::
.dbline -1
.dbline 139
; }
;
; /*****************************************************************************************
; //函数名:UartInit()
; //输入:无
; //输出:无
; //功能描述:串口初始化程序
; /*****************************************************************************************/
; void UartInit(void) //用232串口发数据到PC,收集数据
; {
.dbline 140
; UCSRB=(1<<RXEN)|(1<<TXEN);//允许发送和接收
ldi R24,24
out 0xa,R24
.dbline 141
; UBRRL= (F_osc/9600/16-1)%256;
ldi R24,47
out 0x9,R24
.dbline 142
; UBRRH= (F_osc/9600/16-1)/256;
clr R2
out 0x20,R2
.dbline 143
; UCSRC=(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);//8位数据+1位STOP位
ldi R24,134
out 0x20,R24
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SpiInit _SpiInit fV
.even
_SpiInit::
.dbline -1
.dbline 148
; }
;
;
; void SpiInit(void)
; {
.dbline 149
; DDRB|=(1<<SPI_DO);
sbi 0x17,3
.dbline 150
; DDRB|=(1<<SPI_Clock);
sbi 0x17,5
.dbline 151
; DDRB|=(1<<Chip_Select);
sbi 0x17,2
.dbline 153
;
; PORTB|=(1<<SPI_DI);
sbi 0x18,4
.dbline 156
;
;
; CSN_0;
cbi 0x18,2
.dbline 156
.dbline 157
; SCK_0;
cbi 0x18,5
.dbline 157
.dbline 158
; CSN_1;
sbi 0x18,2
.dbline 158
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e CpuInit _CpuInit fV
.even
_CpuInit::
.dbline -1
.dbline 168
; }
;
; /*****************************************************************************************
; //函数名:CpuInit()
; //输入:无
; //输出:无
; //功能描述:SPI初始化程序
; /*****************************************************************************************/
; void CpuInit(void)
; {
.dbline 169
; UartInit();
rcall _UartInit
.dbline 171
;
; SpiInit();
rcall _SpiInit
.dbline 172
; delay(5000);
ldi R16,5000
ldi R17,19
rcall _delay
.dbline -2
L16:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SpiTxRxByte _SpiTxRxByte fc
; temp -> R20
; i -> R22
; dat -> R16
.even
_SpiTxRxByte::
rcall push_gset2
.dbline -1
.dbline 182
; }
;
; //*****************************************************************************************
; //函数名:SpisendByte(INT8U dat)
; //输入:发送的数据
; //输出:无
; //功能描述:SPI发送一个字节
; //*****************************************************************************************
; INT8U SpiTxRxByte(INT8U dat)
; {
.dbline 184
; INT8U i,temp;
; temp = 0;
clr R20
.dbline 186
;
; SCK_0;
cbi 0x18,5
.dbline 186
.dbline 187
; for(i=0; i<8; i++)
clr R22
rjmp L21
L18:
.dbline 188
; {
.dbline 189
; if(dat & 0x80)
sbrs R16,7
rjmp L22
.dbline 190
; {
.dbline 191
; MOSI_1;
sbi 0x18,3
.dbline 191
.dbline 192
; }
rjmp L23
L22:
.dbline 193
cbi 0x18,3
L23:
.dbline 193
; else MOSI_0;
.dbline 194
; dat <<= 1;
lsl R16
.dbline 196
;
; SCK_1;
sbi 0x18,5
.dbline 196
.dbline 197
; _nop_();
nop
.dbline 198
; _nop_();
nop
.dbline 200
;
; temp <<= 1;
lsl R20
.dbline 201
; if(MISO)temp++;
sbis 0x16,4
rjmp L24
.dbline 201
inc R20
L24:
.dbline 202
cbi 0x18,5
.dbline 202
.dbline 203
nop
.dbline 204
nop
.dbline 205
L19:
.dbline 187
inc R22
L21:
.dbline 187
cpi R22,8
brlo L18
.dbline 206
; SCK_0;
; _nop_();
; _nop_();
; }
; return temp;
mov R16,R20
.dbline -2
L17:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r i 22 c
.dbsym r dat 16 c
.dbend
.dbfunc e RESET_CC1100 _RESET_CC1100 fV
.even
_RESET_CC1100::
.dbline -1
.dbline 216
; }
;
; //*****************************************************************************************
; //函数名:void RESET_CC1100(void)
; //输入:无
; //输出:无
; //功能描述:复位CC1100
; //*****************************************************************************************
; void RESET_CC1100(void)
; {
.dbline 217
; CSN_0;
cbi 0x18,2
.dbline 217
L27:
.dbline 218
L28:
.dbline 218
; while (GDO0);
sbic 0x10,2
rjmp L27
.dbline 219
; SpiTxRxByte(CCxxx0_SRES); //写入复位命令
ldi R16,48
rcall _SpiTxRxByte
L30:
.dbline 220
L31:
.dbline 220
; while (GDO0);
sbic 0x10,2
rjmp L30
.dbline 221
; CSN_1;
sbi 0x18,2
.dbline 221
.dbline -2
L26:
.dbline 0 ; func end
ret
.dbend
.dbfunc e POWER_UP_RESET_CC1100 _POWER_UP_RESET_CC1100 fV
.even
_POWER_UP_RESET_CC1100::
.dbline -1
.dbline 231
; }
;
; //*****************************************************************************************
; //函数名:void POWER_UP_RESET_CC1100(void)
; //输入:无
; //输出:无
; //功能描述:上电复位CC1100
; //*****************************************************************************************
; void POWER_UP_RESET_CC1100(void)
; {
.dbline 232
; CSN_1;
sbi 0x18,2
.dbline 232
.dbline 233
; halWait(1);
ldi R16,1
ldi R17,0
rcall _halWait
.dbline 234
; CSN_0;
cbi 0x18,2
.dbline 234
.dbline 235
; halWait(1);
ldi R16,1
ldi R17,0
rcall _halWait
.dbline 236
; CSN_1;
sbi 0x18,2
.dbline 236
.dbline 237
; halWait(41);
ldi R16,41
ldi R17,0
rcall _halWait
.dbline 238
; RESET_CC1100(); //复位CC1100
rcall _RESET_CC1100
.dbline -2
L33:
.dbline 0 ; func end
ret
.dbend
.dbfunc e halSpiWriteReg _halSpiWriteReg fV
; value -> R20
; addr -> R22
.even
_halSpiWriteReg::
rcall push_gset2
mov R20,R18
mov R22,R16
.dbline -1
.dbline 248
; }
;
; //*****************************************************************************************
; //函数名:void halSpiWriteReg(INT8U addr, INT8U value)
; //输入:地址和配置字
; //输出:无
; //功能描述:SPI写寄存器
; //*****************************************************************************************
; void halSpiWriteReg(INT8U addr, INT8U value)
; {
.dbline 249
; CSN_0;
cbi 0x18,2
.dbline 249
L35:
.dbline 250
L36:
.dbline 250
; while (GDO0);
sbic 0x10,2
rjmp L35
.dbline 251
; SpiTxRxByte(addr); //写地址
mov R16,R22
rcall _SpiTxRxByte
.dbline 252
; SpiTxRxByte(value); //写入配置
mov R16,R20
rcall _SpiTxRxByte
.dbline 253
; CSN_1;
sbi 0x18,2
.dbline 253
.dbline -2
L34:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r value 20 c
.dbsym r addr 22 c
.dbend
.dbfunc e halSpiWriteBurstReg _halSpiWriteBurstReg fV
; temp -> R20
; i -> R22
; count -> R10
; buffer -> R12,R13
; addr -> R20
.even
_halSpiWriteBurstReg::
rcall push_gset4
movw R12,R18
mov R20,R16
ldd R10,y+8
.dbline -1
.dbline 263
; }
;
; //*****************************************************************************************
; //函数名:void halSpiWriteBurstReg(INT8U addr, INT8U *buffer, INT8U count)
; //输入:地址,写入缓冲区,写入个数
; //输出:无
; //功能描述:SPI连续写配置寄存器
; //*****************************************************************************************
; void halSpiWriteBurstReg(INT8U addr, INT8U *buffer, INT8U count)
; {
.dbline 265
; INT8U i, temp;
; temp = addr | WRITE_BURST;
ori R20,64
.dbline 266
; CSN_0;
cbi 0x18,2
.dbline 266
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -