📄 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
_SET_CLOCK::
; /*
; 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;
;
; void SET_CLOCK() { PORTG |=0x1; }
lds R24,101
ori R24,1
sts 101,R24
L1:
.dbline 0 ; func end
ret
.even
_CLEAR_CLOCK::
; void CLEAR_CLOCK() { PORTG &=~(0x1); }
lds R24,101
andi R24,254
sts 101,R24
L2:
.dbline 0 ; func end
ret
.even
_SET_IN::
; void SET_IN() { PORTG |=0x2; }
lds R24,101
ori R24,2
sts 101,R24
L3:
.dbline 0 ; func end
ret
.even
_CLEAR_IN::
; void CLEAR_IN() { PORTG &=~(0x2); }
lds R24,101
andi R24,253
sts 101,R24
L4:
.dbline 0 ; func end
ret
.even
_SET_CSN::
; void SET_CSN() { PORTC |=0x4; }
sbi 0x15,2
L5:
.dbline 0 ; func end
ret
.even
_CLEAR_CSN::
; void CLEAR_CSN() { PORTC &=~(0x4); }
cbi 0x15,2
L6:
.dbline 0 ; func end
ret
.even
_GET_OUT::
; //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 L8
ldi R16,1
ldi R17,0
xjmp L9
L8:
clr R16
clr R17
L9:
L7:
.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
L11:
; else
; ;
L10:
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 L17
L14:
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
L15:
inc R16
L17:
cpi R16,10
brlo L14
L13:
.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 L20
L19:
; unsigned int i,j;
; while(l--)
; for(i=0;i<54;i++)
clr R20
clr R21
xjmp L25
L22:
clr R22
clr R23
xjmp L29
L26:
L27:
subi R22,255 ; offset = 1
sbci R23,255
L29:
cpi R22,100
ldi R30,0
cpc R23,R30
brlo L26
L23:
subi R20,255 ; offset = 1
sbci R21,255
L25:
cpi R20,54
ldi R30,0
cpc R21,R30
brlo L22
L20:
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L19
tst R3
brne L19
X0:
L18:
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 L34
L31:
; {
; if((value&0x80)==0x80)
mov R24,R20
andi R24,128
cpi R24,128
brne L35
; {
; Dly10us();
xcall _Dly10us
; SET_IN(); // SI=1
xcall _SET_IN
; }
xjmp L36
L35:
; else
; {
; CLEAR_IN(); // SI=0
xcall _CLEAR_IN
; Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
; }
L36:
; Dly10us();Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
; SET_CLOCK(); //SCLK=1;
xcall _SET_CLOCK
; 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 L37
; spi_status=spi_status|0x01;
mov R24,R10
ori R24,1
mov R10,R24
xjmp L38
L37:
; else
; spi_status=spi_status&0xfe;
mov R24,R10
andi R24,254
mov R10,R24
L38:
xcall _CLEAR_CLOCK
xcall _Dly10us
xcall _Dly10us
L32:
inc R22
L34:
cpi R22,8
brlo L31
; CLEAR_CLOCK();
; Dly10us();Dly10us();
; }
; return(spi_status);
mov R16,R10
L30:
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 L43
L40:
; {
; SET_CLOCK(); //P_SCLK=1;
xcall _SET_CLOCK
; 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 L44
mov R24,R10
ori R24,1
mov R10,R24
xjmp L45
L44:
; else value&=0xfe;
mov R24,R10
andi R24,254
mov R10,R24
L45:
xcall _Dly10us
xcall _Dly10us
xcall _CLEAR_CLOCK
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
L41:
inc R20
L43:
cpi R20,8
brlo L40
; Dly10us();Dly10us();
; CLEAR_CLOCK(); //SCLK=0 //P_SCLK=0;
; Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
; }
; return value;
mov R16,R10
L39:
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
xcall _CLEAR_CSN
L47:
L48:
; while(GET_OUT());
xcall _GET_OUT
cpi R16,0
cpc R16,R17
brne L47
X1:
; CLEAR_CLOCK();
xcall _CLEAR_CLOCK
; RxTxstatus=SPI_write(CCxxx0_SNOP);
ldi R16,61
xcall _SPI_write
mov R20,R16
; CLEAR_CLOCK(); //SCLK=0
xcall _CLEAR_CLOCK
; CLEAR_IN(); // SI=0
xcall _CLEAR_IN
; SET_CSN(); //CSn=1
xcall _SET_CSN
; return(RxTxstatus);
mov R16,R20
L46:
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();
xcall _CLEAR_CSN
L51:
L52:
; while(GET_OUT());
xcall _GET_OUT
cpi R16,0
cpc R16,R17
brne L51
X2:
; CLEAR_CLOCK();
xcall _CLEAR_CLOCK
; 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();
xcall _CLEAR_CLOCK
; CLEAR_IN();
xcall _CLEAR_IN
; SET_CSN();
xcall _SET_CSN
L50:
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
xcall _CLEAR_CSN
; CLEAR_CLOCK();
xcall _CLEAR_CLOCK
L55:
L56:
; while(GET_OUT());
xcall _GET_OUT
cpi R16,0
cpc R16,R17
brne L55
X3:
; SPI_write(strobe);
mov R16,R20
xcall _SPI_write
; CLEAR_CLOCK();
xcall _CLEAR_CLOCK
; CLEAR_IN();
xcall _CLEAR_IN
; SET_CSN();
xcall _SET_CSN
L54:
xcall pop_gset1
.dbline 0 ; func end
ret
; value -> R12
; j -> R20
; i -> R14
; count -> R22
; buffer -> R10,R11
; addr -> R20
.even
_halSpiWriteBurstReg::
xcall push_gset5
movw R10,R18
mov R20,R16
ldd R22,y+10
; }
; /*******************************************/
; void halSpiWriteBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)
; {
; unsigned char i,j,value;
; CLEAR_CLOCK();
xcall _CLEAR_CLOCK
; Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
; CLEAR_CSN(); // CSn=0
xcall _CLEAR_CSN
; addr|=WRITE_BURST;
ori R20,64
; SPI_write(addr);
mov R16,R20
xcall _SPI_write
; CLEAR_IN();
xcall _CLEAR_IN
; for(j=0;j<count;j++)
clr R20
xjmp L62
L59:
; {
; value=buffer[j];
mov R30,R20
clr R31
add R30,R10
adc R31,R11
ldd R12,z+0
; SPI_write(value);
mov R16,R12
xcall _SPI_write
; CLEAR_IN();
xcall _CLEAR_IN
clr R14
xjmp L66
L63:
L64:
inc R14
L66:
mov R24,R14
cpi R24,100
brlo L63
L60:
inc R20
L62:
cp R20,R22
brlo L59
; for(i=0;i<100;i++);
; }
; SET_CSN();
xcall _SET_CSN
L58:
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();
xcall _SET_CSN
clr R20
clr R21
xjmp L71
L68:
L69:
subi R20,255 ; offset = 1
sbci R21,255
L71:
; for(i=0;i<100;i++);
cpi R20,100
ldi R30,0
cpc R21,R30
brlo L68
; CLEAR_CSN();
xcall _CLEAR_CSN
clr R20
clr R21
xjmp L75
L72:
L73:
subi R20,255 ; offset = 1
sbci R21,255
L75:
; for(i=0;i<100;i++);
cpi R20,100
ldi R30,0
cpc R21,R30
brlo L72
; SET_CSN();
xcall _SET_CSN
clr R20
clr R21
xjmp L79
L76:
L77:
subi R20,255 ; offset = 1
sbci R21,255
L79:
; for(i=0;i<2000;i++);
cpi R20,208
ldi R30,7
cpc R21,R30
brlo L76
; CLEAR_CSN();
xcall _CLEAR_CSN
L80:
L81:
; while(GET_OUT());
xcall _GET_OUT
cpi R16,0
cpc R16,R17
brne L80
X4:
; halSpiStrobe(CCxxx0_SRES);
ldi R16,48
xcall _halSpiStrobe
; CLEAR_CLOCK();
xcall _CLEAR_CLOCK
; CLEAR_IN();
xcall _CLEAR_IN
; SET_CSN();
xcall _SET_CSN
L67:
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 L85
L84:
ldi R16,1
ldi R17,0
xcall _Dly1mS
L85:
; while(spiGetRxTxStatus()&0x70)
xcall _spiGetRxTxStatus
mov R24,R16
andi R24,112
brne L84
; {
; Dly1mS(1);
; //Dly1mS(2);
; }
; SEND_DONE=0x01;
ldi R24,1
sts _SEND_DONE,R24
; return 0;
clr R16
L83:
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);
; halRfSendPacket(txBuffer_CCxx00, sizeof(txBuffer_CCxx00));
; Dly1mS(100);
; }
; */
; /*********************************************************/
; unsigned char halSpiReadReg(unsigned char addr)
; {
; unsigned char value;
; CLEAR_CLOCK();
xcall _CLEAR_CLOCK
; Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
; CLEAR_CSN(); // CSn=0
xcall _CLEAR_CSN
; addr|=READ_SINGLE;
ori R20,128
; SPI_write(addr);
mov R16,R20
xcall _SPI_write
; CLEAR_IN();
xcall _CLEAR_IN
; Dly10us();Dly10us();Dly10us();Dly10us();Dly10us();
xcall _Dly10us
xcall _Dly10us
xcall _Dly10us
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -