📄 cc1100.s
字号:
.module cc1100.c
.area data(ram, con, rel)
_paTable::
.blkb 2
.area idata
.byte 192,192
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 192,192
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 192,192
.area data(ram, con, rel)
.blkb 2
.area idata
.byte 192,192
.area data(ram, con, rel)
_SEND_DONE::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.area text(rom, con, rel)
.even
_GET_OUT::
; /*
; v2.5 halSpiWriteReg(CCxxx0_MCSM2, 0x08);
; halSpiWriteReg(CCxxx0_PKTLEN, 0x1F);
; v2.6 测试发送:Dly1mS(100); 删去
; */
; #include <iom128v.h>
; #include "cc1100_reg.h"
; typedef unsigned char uint8_t;
; typedef unsigned int uint16_t;
; unsigned char paTable[8] = {0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0};
; unsigned char rxBuffer[32]; //接收缓冲区的大小
;
; unsigned char rd_reg;
;
; //unsigned char INTERRUPT_STATE=0x00;
; unsigned char SEND_DONE=0x00;
;
; #define SET_CLOCK() { PORTG |=0x1; }
; #define CLEAR_CLOCK() { PORTG &=~(0x1); }
; #define SET_IN() { PORTG |=0x2; }
; #define CLEAR_IN() { PORTG &=~(0x2); }
; #define SET_CSN() { PORTC |=0x4; }
; #define CLEAR_CSN() { PORTC &=~(0x4); }
; //char GET_OUT() { return (PINC & 0x2)!=0;}
; //char GET_GDO0() { return (PIND & 0x2)!=0;}
; int GET_OUT() { return (* (volatile unsigned char *)(unsigned int )& * (volatile unsigned char *)(0x13 + 0x20) & (1 << 1)) != 0;}
sbis 0x13,1
rjmp L2
ldi R16,1
ldi R17,0
xjmp L3
L2:
clr R16
clr R17
L3:
L1:
.dbline 0 ; func end
ret
; size -> R22
; txPtr -> R20,R21
.even
_CC1100_send::
xcall push_gset2
mov R22,R18
movw R20,R16
;
;
;
;
;
; extern uint8_t CC1100_sendDone();
; extern uint8_t *CC1100_receive(uint8_t *msg);
;
; unsigned char CC1100_send(uint8_t *txPtr,uint8_t size)
; {
; if (1)
; return CC1100_sendRFburst(txPtr,size);
mov R18,R22
clr R19
movw R16,R20
xcall _CC1100_sendRFburst
L5:
; else
; ;
L4:
xcall pop_gset2
.dbline 0 ; func end
ret
; i -> R16
.even
_Dly10us::
; }
;
; /******************************************/
;
; //延时函数 10us
; void Dly10us()
; {
; unsigned char i;
; for(i=0;i<10;i++)
clr R16
xjmp L11
L8:
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
L9:
inc R16
L11:
cpi R16,10
brlo L8
L7:
.dbline 0 ; func end
ret
; i -> R20,R21
; j -> R22,R23
; l -> R16,R17
.even
_Dly1mS::
xcall push_gset2
; {
; asm("nop");
; asm("nop");
; asm("nop");
; asm("nop");
; asm("nop");
; asm("nop");
; asm("nop");
; asm("nop");
; asm("nop");
; asm("nop");
; }
; }
; //延时函数 1ms
; void Dly1mS(unsigned int l)
; {
xjmp L14
L13:
; unsigned int i,j;
; while(l--)
; for(i=0;i<54;i++)
clr R20
clr R21
xjmp L19
L16:
clr R22
clr R23
xjmp L23
L20:
L21:
subi R22,255 ; offset = 1
sbci R23,255
L23:
cpi R22,100
ldi R30,0
cpc R23,R30
brlo L20
L17:
subi R20,255 ; offset = 1
sbci R21,255
L19:
cpi R20,54
ldi R30,0
cpc R21,R30
brlo L16
L14:
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L13
tst R3
brne L13
X0:
L12:
xcall pop_gset2
.dbline 0 ; func end
ret
; rd_pin -> R12
; i -> R22
; spi_status -> R10
; value -> R20
.even
_SPI_write::
xcall push_gset4
mov R20,R16
; for(j=0;j<100;j++);
; }
;
; /******************************************/
;
; unsigned char SPI_write(unsigned char value)
; {
; unsigned char i,spi_status,rd_pin;
; for(i=0;i<8;i++)
clr R22
xjmp L28
L25:
; {
; if((value&0x80)==0x80)
mov R24,R20
andi R24,128
cpi R24,128
brne L29
; {
; Dly10us();
xcall _Dly10us
; SET_IN(); // SI=1
lds R24,101
ori R24,2
sts 101,R24
; }
xjmp L30
L29:
; else
; {
; CLEAR_IN(); // SI=0
lds R24,101
andi R24,253
sts 101,R24
; Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
; }
L30:
; Dly10us();Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
; SET_CLOCK(); //SCLK=1;
lds R24,101
ori R24,1
sts 101,R24
; Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
; value <<=1;
lsl R20
; spi_status<<=1;
lsl R10
; rd_pin=GET_OUT();
xcall _GET_OUT
mov R12,R16
; if((rd_pin&0x01)==0x01)
mov R24,R12
andi R24,1
cpi R24,1
brne L31
; spi_status=spi_status|0x01;
mov R24,R10
ori R24,1
mov R10,R24
xjmp L32
L31:
; else
; spi_status=spi_status&0xfe;
mov R24,R10
andi R24,254
mov R10,R24
L32:
lds R24,101
andi R24,254
sts 101,R24
xcall _Dly10us
xcall _Dly10us
L26:
inc R22
L28:
cpi R22,8
brsh X1
xjmp L25
X1:
; CLEAR_CLOCK();
; Dly10us();Dly10us();
; }
; return(spi_status);
mov R16,R10
L24:
xcall pop_gset4
.dbline 0 ; func end
ret
; rd_pin -> R22
; value -> R10
; i -> R20
.even
_SPI_read::
xcall push_gset3
; }
; unsigned char SPI_read()
; {
; unsigned char i,value,rd_pin;
; for(i=0;i<8;i++)
clr R20
xjmp L37
L34:
; {
; SET_CLOCK(); //P_SCLK=1;
lds R24,101
ori R24,1
sts 101,R24
; value <<=1;Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
lsl R10
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
; rd_pin=GET_OUT();
xcall _GET_OUT
mov R22,R16
; if((rd_pin&0x01)==0x01) value|=0x01;
mov R24,R22
andi R24,1
cpi R24,1
brne L38
mov R24,R10
ori R24,1
mov R10,R24
xjmp L39
L38:
; else value&=0xfe;
mov R24,R10
andi R24,254
mov R10,R24
L39:
xcall _Dly10us
xcall _Dly10us
lds R24,101
andi R24,254
sts 101,R24
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
L35:
inc R20
L37:
cpi R20,8
brlo L34
; Dly10us();Dly10us();
; CLEAR_CLOCK(); //SCLK=0 //P_SCLK=0;
; Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
; }
; return value;
mov R16,R10
L33:
xcall pop_gset3
.dbline 0 ; func end
ret
; RxTxstatus -> R20
.even
_spiGetRxTxStatus::
xcall push_gset1
; }
; /******************************************/
; unsigned char spiGetRxTxStatus()
; {
; unsigned char RxTxstatus;
; CLEAR_CSN(); // CSn=0
cbi 0x15,2
L41:
L42:
; while(GET_OUT());
xcall _GET_OUT
cpi R16,0
cpc R16,R17
brne L41
X2:
; CLEAR_CLOCK();
lds R24,101
andi R24,254
sts 101,R24
; RxTxstatus=SPI_write(CCxxx0_SNOP);
ldi R16,61
xcall _SPI_write
mov R20,R16
; CLEAR_CLOCK(); //SCLK=0
lds R24,101
andi R24,254
sts 101,R24
; CLEAR_IN(); // SI=0
lds R24,101
andi R24,253
sts 101,R24
; SET_CSN(); //CSn=1
sbi 0x15,2
; return(RxTxstatus);
L40:
xcall pop_gset1
.dbline 0 ; func end
ret
; value -> R20
; addr -> R22
.even
_halSpiWriteReg::
xcall push_gset2
mov R20,R18
mov R22,R16
; }
; /******************************************/
; void halSpiWriteReg(unsigned char addr, unsigned char value)
; {
; CLEAR_CSN();
cbi 0x15,2
L45:
L46:
; while(GET_OUT());
xcall _GET_OUT
cpi R16,0
cpc R16,R17
brne L45
X3:
; CLEAR_CLOCK();
lds R24,101
andi R24,254
sts 101,R24
; addr&=0x7F;
andi R22,127
; SPI_write(addr);
mov R16,R22
xcall _SPI_write
; SPI_write(value);
mov R16,R20
xcall _SPI_write
; CLEAR_CLOCK();
lds R24,101
andi R24,254
sts 101,R24
; CLEAR_IN();
lds R24,101
andi R24,253
sts 101,R24
; SET_CSN();
sbi 0x15,2
L44:
xcall pop_gset2
.dbline 0 ; func end
ret
; strobe -> R20
.even
_halSpiStrobe::
xcall push_gset1
mov R20,R16
; }
; /******************************************/
; void halSpiStrobe(unsigned char strobe)
; {
; CLEAR_CSN(); // CSn=0
cbi 0x15,2
; CLEAR_CLOCK();
lds R24,101
andi R24,254
sts 101,R24
L49:
L50:
; while(GET_OUT());
xcall _GET_OUT
cpi R16,0
cpc R16,R17
brne L49
X4:
; SPI_write(strobe);
mov R16,R20
xcall _SPI_write
; CLEAR_CLOCK();
lds R24,101
andi R24,254
sts 101,R24
; CLEAR_IN();
lds R24,101
andi R24,253
sts 101,R24
; SET_CSN();
sbi 0x15,2
L48:
xcall pop_gset1
.dbline 0 ; func end
ret
; value -> R20
; j -> R22
; i -> R14
; count -> R10
; buffer -> R12,R13
; addr -> R20
.even
_halSpiWriteBurstReg::
xcall push_gset5
movw R12,R18
mov R20,R16
ldd R10,y+10
; }
; /*******************************************/
; void halSpiWriteBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
; {
; unsigned char i,j,value;
; CLEAR_CLOCK();
lds R24,101
andi R24,254
sts 101,R24
; Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
; CLEAR_CSN(); // CSn=0
cbi 0x15,2
; addr|=WRITE_BURST;
ori R20,64
; SPI_write(addr);
mov R16,R20
xcall _SPI_write
; CLEAR_IN();
lds R24,101
andi R24,253
sts 101,R24
; for(j=0;j<count;j++)
clr R22
xjmp L56
L53:
; {
; value=buffer[j];
mov R30,R22
clr R31
add R30,R12
adc R31,R13
ldd R20,z+0
; SPI_write(value);
mov R16,R20
xcall _SPI_write
; CLEAR_IN();
lds R24,101
andi R24,253
sts 101,R24
clr R14
xjmp L60
L57:
L58:
inc R14
L60:
mov R24,R14
cpi R24,100
brlo L57
L54:
inc R22
L56:
cp R22,R10
brlo L53
; for(i=0;i<100;i++);
; }
; SET_CSN();
sbi 0x15,2
L52:
xcall pop_gset5
.dbline 0 ; func end
ret
; i -> R20,R21
.even
_CC1100_POR::
xcall push_gset1
; }
; /******************************/
; void CC1100_POR()
; {
; unsigned int i;
; halSpiStrobe(CCxxx0_SIDLE);
ldi R16,54
xcall _halSpiStrobe
; SET_CSN();
sbi 0x15,2
clr R20
clr R21
xjmp L65
L62:
L63:
subi R20,255 ; offset = 1
sbci R21,255
L65:
; for(i=0;i<100;i++);
cpi R20,100
ldi R30,0
cpc R21,R30
brlo L62
; CLEAR_CSN();
cbi 0x15,2
clr R20
clr R21
xjmp L69
L66:
L67:
subi R20,255 ; offset = 1
sbci R21,255
L69:
; for(i=0;i<100;i++);
cpi R20,100
ldi R30,0
cpc R21,R30
brlo L66
; SET_CSN();
sbi 0x15,2
clr R20
clr R21
xjmp L73
L70:
L71:
subi R20,255 ; offset = 1
sbci R21,255
L73:
; for(i=0;i<2000;i++);
cpi R20,208
ldi R30,7
cpc R21,R30
brlo L70
; CLEAR_CSN();
cbi 0x15,2
L74:
L75:
; while(GET_OUT());
xcall _GET_OUT
cpi R16,0
cpc R16,R17
brne L74
X5:
; halSpiStrobe(CCxxx0_SRES);
ldi R16,48
xcall _halSpiStrobe
; CLEAR_CLOCK();
lds R24,101
andi R24,254
sts 101,R24
; CLEAR_IN();
lds R24,101
andi R24,253
sts 101,R24
; SET_CSN();
sbi 0x15,2
L61:
xcall pop_gset1
.dbline 0 ; func end
ret
; size -> R22
; txBuffer -> R20,R21
.even
_halRfSendPacket::
xcall push_gset2
mov R22,R18
movw R20,R16
sbiw R28,1
; }
; /*******************************************/
; unsigned char halRfSendPacket(unsigned char *txBuffer, unsigned char size)
; {
; halSpiStrobe(CCxxx0_SFTX);
ldi R16,59
xcall _halSpiStrobe
; Dly1mS(15);
ldi R16,15
ldi R17,0
xcall _Dly1mS
; //Dly1mS(25);
; halSpiWriteBurstReg(CCxxx0_TXFIFO, txBuffer, size);
std y+0,R22
movw R18,R20
ldi R16,127
xcall _halSpiWriteBurstReg
; Dly1mS(15);
ldi R16,15
ldi R17,0
xcall _Dly1mS
; //Dly1mS(25);
; halSpiStrobe(CCxxx0_STX);
ldi R16,53
xcall _halSpiStrobe
xjmp L79
L78:
ldi R16,1
ldi R17,0
xcall _Dly1mS
L79:
; while(spiGetRxTxStatus()&0x70)
xcall _spiGetRxTxStatus
mov R24,R16
andi R24,112
brne L78
; {
; Dly1mS(1);
; //Dly1mS(2);
; }
; SEND_DONE=0x01;
ldi R24,1
sts _SEND_DONE,R24
; return 0;
clr R16
L77:
adiw R28,1
xcall pop_gset2
.dbline 0 ; func end
ret
; value -> R20
; addr -> R20
.even
_halSpiReadReg::
xcall push_gset1
mov R20,R16
; }// halRfSendPacket
; /*******************************************/
; /*
; void TxCCxx00()
; {
; unsigned char i;
; halSpiWriteReg(CCxxx0_FREND0, 0x10); //CC1100:POWER=10DBM;CC2500:1DBM
; Dly1mS(25);;
; for(i=0;i<4;i++) //发四次
; {
; halRfSendPacket(txBuffer_CCxx00, sizeof(txBuffer_CCxx00));
; Dly1mS(50);
; }
; halSpiWriteReg(CCxxx0_FREND0, 0x15); //CC1100太近会收不到,将发射功率降低到-10DBM //#define CCxxx0_FREND0 0x22
; Dly1mS(50);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -