📄 main.c
字号:
#include "MSP430x16x.h"
#include "SPI.h"
unsigned long int ShootFrequence=10000000,ShootFrequenceComByt,FMFrequence,FMFrequenceComByt; //发射频率
unsigned int ShootAmplitude=0x2f00,TimeData; //发射幅度
unsigned int SinDat[100]={
1063 , 1125 , 1187 , 1249 , 1309,
1368 , 1426 , 1482 , 1536 , 1588 , 1637,
1685 , 1729 , 1771 , 1809 , 1844 , 1876,
1905 , 1930 , 1951 , 1969 , 1982 , 1992,
1998 , 2000 , 1998 , 1992 , 1982 , 1969,
1951 , 1930 , 1905 , 1876 , 1844 , 1809,
1771 , 1729 , 1685 , 1637 , 1588 , 1536,
1482 , 1426 , 1368 , 1309 , 1249 , 1187,
1125 , 1063 , 1000 , 937 , 875 , 813,
751 , 691 , 632 , 574 , 518 , 464,
412 , 363 , 315 , 271 , 229 , 191,
156 , 124 , 95 , 70 , 49 , 31,
18 , 8 , 2 , 0 , 2 , 8,
18 , 31 , 49 , 70 , 95 , 124,
156 , 191 , 229 , 271 , 315 , 363,
412 , 464 , 518 , 574 , 632 , 691,
751 , 813 , 875 , 937 , 1000 };
const unsigned int SinDat2[128]={
0, 25, 50, 75, 100, 125, 150, 175
, 200, 224, 249, 273, 297, 321, 345, 369
, 392, 415, 438, 460, 483, 505, 526, 548
, 569, 590, 610, 630, 650, 669, 688, 706
, 724, 742, 759, 775, 792, 807, 822, 837
, 851, 865, 878, 891, 903, 915, 926, 936
, 946, 955, 964, 972, 980, 987, 993, 999
,1004,1009,1013,1016,1019,1021,1023,1024
,1024,1024,1023,1021,1019,1016,1013,1009
,1004, 999, 993, 987, 980, 972, 964, 955
, 946, 936, 926, 915, 903, 891, 878, 865
, 851, 837, 822, 807, 792, 775, 759, 742,
724, 706, 688, 669, 650, 630, 610, 590
, 569, 548, 526, 505, 483, 460, 438, 415
, 392, 369, 345, 321, 297, 273, 249, 224
, 200, 175, 150, 125, 100, 75, 50, 25};
void Init_Comclk(void)
{
unsigned int i;
BCSCTL1 &= ~(XT2OFF+XTS); //启用高频晶振,且低频引脚连接低频晶振
do
{
IFG1 &= ~OFIFG; // 清除 OSCFault 标志
for (i = 0xFF; i > 0; i--); // 延时等待
}
while ((IFG1 & OFIFG)); // OSCFault一直置位则循环继续清除
BCSCTL2 |= (SELM_2+SELS); // MCLK=SMCLK=XT2
}
void main(void)
{
unsigned int i;
unsigned int k=0;
WDTCTL=WDTPW+WDTHOLD;
for(i=0;i<10000;i++);
Init_Comclk();
// InitSPI9954();
InitSPI1305();
//_EINT();
InitSPI9954();
P2OUT&=~BIT0;
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
SPI_Write9954(0x00,0x02); //0x02 enable OSK
SPI_Write9954(0x80,0x12); //0x10:enable sinoutput 0x80: Automatic Sync Enable
SPI_WriteOne9954(0x00);
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
SPI_Write9954(0x01,0x00);
SPI_WriteOne9954(0x00);
SPI_WriteOne9954(0x88); //8倍频
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
/* */
SPI_Write9954(0x02,((ShootAmplitude&0x3f00)>>8)); //Amplitude Scale Factor
SPI_WriteOne9954(ShootAmplitude&0xff);
//SPI_Write9954(0x02,0x00); //Amplitude Scale Factor
//SPI_WriteOne9954(0x00);
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
if(ShootFrequence<3000000)
ShootFrequenceComByt=(((ShootFrequence)))-(ShootFrequence>>7)-(ShootFrequence>>6)-(ShootFrequence>>6)-(ShootFrequence>>7); //1000000时为50k
else
ShootFrequenceComByt=(((ShootFrequence)))-(ShootFrequence>>7)-(ShootFrequence>>6)-(ShootFrequence>>6)-(ShootFrequence>>7); //1000000时为50k
//ShootFrequenceComByt=((179*(ShootFrequence)))-(ShootFrequence>>3)+(ShootFrequence>>8)+(ShootFrequence>>9) ; //1000000时为50k
/*
SPI_Write9954(0x04,(ShootFrequenceComByt&0xff000000)>>24); //Frequency Tuning Word
SPI_Write9954((ShootFrequenceComByt&0x00ff0000)>>16,(ShootFrequenceComByt&0x0000ff00)>>8);
SPI_WriteOne9954((ShootFrequenceComByt&0x000000ff));
*/
SPI_Write9954(0x04,0x07); //Frequency Tuning Word
SPI_Write9954(0xff,0xff);
SPI_WriteOne9954(0xff);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
/*
while(1){
P2OUT&=~BIT0;
for(i=0;i<6000;i++);
SPI_Write9954(0x05,0x1f);
SPI_WriteOne9954(0xff);
P2OUT|=BIT0; //Updata
for(i=0;i<6000;i++);
P2OUT&=~BIT0;
for(i=0;i<6000;i++);
SPI_Write9954(0x05,0x00);
SPI_WriteOne9954(0x00);
P2OUT|=BIT0; //Updata
for(i=0;i<6000;i++);
}
*/
/********************psk*******************/
SPI_Write9954(0x00,0xc2); //0x02 enable OSK psk
SPI_Write9954(0x80,0x12); //0x10:enable sinoutput 0x80: Automatic Sync Enable
SPI_WriteOne9954(0x00);
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
SPI_Write9954(0x04,0x00); //Frequency Tuning Word
SPI_Write9954(0x0f,0x0f);
SPI_WriteOne9954(0xff);
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
SPI_Write9954(0x07,0x00);
SPI_Write9954(0x01,0x0f);
SPI_Write9954(0x00,0x80);
//SPI_Write9954(0x08,0xff);
//SPI_Write9954(0xff,0x08);
//SPI_Write9954(0x04,0x00);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
P2OUT&=~BIT3;//PS0=0
P2OUT&=~BIT4;//PS1=0
SPI_WriteOne9954(0x0B);
for(i=0;i<0x08;i++){
SPI_Write9954(0x80,0x00);
SPI_Write9954(0x00,0x00);
}
for(i=0;i<0x08;i++){
SPI_Write9954(0x00,0x00);
SPI_Write9954(0x00,0x00);
}
//P2OUT|=BIT0; //Updata
//P2OUT&=~BIT0;
//P2OUT&=~BIT3;//PS0=0
//P2OUT|=BIT4;//PS1=1
//SPI_WriteOne9954(0x0B);
P2OUT|=BIT0;
P2OUT&=~BIT0;
while(1){
//P2OUT&=~BIT4;//PS1=0
//for(i=0;i<4;i++);
//P2OUT|=BIT4;//PS1=1
//for(i=0;i<4;i++);
}
for(i=0;i<4000;i++);
/********************psk over*******************/
/******************fm***********************/
SPI_Write9954(0x00,0x82); //0x02 enable OSK fm
SPI_Write9954(0x80,0x12); //0x10:enable sinoutput 0x80: Automatic Sync Enable
SPI_WriteOne9954(0x00);
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
SPI_Write9954(0x07,0x00);
SPI_Write9954(0xff,0x7f);
SPI_Write9954(0x00,0x80);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
P2OUT&=~BIT3;//PS0=0
P2OUT&=~BIT4;//PS0=0
SPI_WriteOne9954(0x0B);
for(i=0;i<128;i++){
FMFrequence=SinDat2[i];
FMFrequenceComByt=(((FMFrequence<<8)));
FMFrequenceComByt=ShootFrequence+FMFrequenceComByt;
SPI_WriteOne9954((FMFrequenceComByt&0xff000000)>>24); //Frequency Tuning Word
SPI_Write9954((FMFrequenceComByt&0x00ff0000)>>16,(FMFrequenceComByt&0x0000ff00)>>8);
SPI_WriteOne9954((FMFrequenceComByt&0x000000ff));
}
/*
for(i=0;i<127;i++){
FMFrequence=SinDat2[i];
FMFrequenceComByt=(((FMFrequence>>5)));
FMFrequenceComByt=ShootFrequence+FMFrequenceComByt;
SPI_Write9954(0x04,(FMFrequenceComByt&0xff000000)>>24); //Frequency Tuning Word
SPI_Write9954((FMFrequenceComByt&0x00ff0000)>>16,(FMFrequenceComByt&0x0000ff00)>>8);
SPI_WriteOne9954((FMFrequenceComByt&0x000000ff));
}
for(i=0;i<127;i++){
FMFrequence=SinDat2[i];
FMFrequenceComByt=(((FMFrequence)));
FMFrequenceComByt=ShootFrequence-FMFrequenceComByt;
SPI_Write9954(0x04,(FMFrequenceComByt&0xff000000)>>24); //Frequency Tuning Word
SPI_Write9954((FMFrequenceComByt&0x00ff0000)>>16,(FMFrequenceComByt&0x0000ff00)>>8);
SPI_WriteOne9954((FMFrequenceComByt&0x000000ff));
}
*/
for(i=0;i<4000;i++);
P2OUT|=BIT0;
P2OUT&=~BIT0;
/********************fm over***********************/
/******************fsk*********************/
/*
SPI_Write9954(0x00,0x82); //0x02 enable OSK fm
SPI_Write9954(0x80,0x12); //0x10:enable sinoutput 0x80: Automatic Sync Enable
SPI_WriteOne9954(0x00);
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
SPI_Write9954(0x07,0x00);
SPI_Write9954(0x0f,0x0f);
SPI_Write9954(0x00,0x80);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
P2OUT&=~BIT3;//PS0=0
P2OUT&=~BIT4;//PS0=0
SPI_WriteOne9954(0x0B);
for(i=0;i<8;i++){
SPI_Write9954(0x00,0x00);
SPI_Write9954(0x44,0xff);
}
for(i=0;i<8;i++){
SPI_Write9954(0x00,0x00);
SPI_Write9954(0xff,0xff);
}
for(i=0;i<4000;i++);
P2OUT|=BIT0;
P2OUT&=~BIT0;
*/
/******************fsk over*********************/
/**********************Am*****************/
/*
SPI_Write9954(0x04,0x00); //Frequency Tuning Word
SPI_Write9954(0xff,0x0f);
SPI_WriteOne9954(0xff);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
while(1){
P2OUT&=~BIT0;
SPI_Write9954(0x02,0); //Amplitude Scale Factor
SPI_WriteOne9954(0);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x13); //Amplitude Scale Factor
SPI_WriteOne9954(0x50);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x24); //Amplitude Scale Factor
SPI_WriteOne9954(0xbc);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x32); //Amplitude Scale Factor
SPI_WriteOne9954(0x90);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x3b); //Amplitude Scale Factor
SPI_WriteOne9954(0x70);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x3e); //Amplitude Scale Factor
SPI_WriteOne9954(0x80);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x3b); //Amplitude Scale Factor
SPI_WriteOne9954(0x70);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x32); //Amplitude Scale Factor
SPI_WriteOne9954(0x90);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x24); //Amplitude Scale Factor
SPI_WriteOne9954(0xbc);
P2OUT|=BIT0; //Updata
P2OUT&=~BIT0;
SPI_Write9954(0x02,0x13); //Amplitude Scale Factor
SPI_WriteOne9954(0x50);
P2OUT|=BIT0; //Updata
}*/
/***********************Am Over********************/
/*
P2OUT|= BIT2; //sync
for(i=0;i<1000;i++);
P2OUT&= ~BIT2;
SPI_Write9954(0x05,0x00); //Phase Offset Word
SPI_WriteOne9954(0x00);
*/
//for(i=0;i<4000;i++);
//P2OUT|=BIT0; //Updata
//P2OUT|= BIT2; //sync
//for(i=0;i<1000;i++);
//P2OUT&= ~BIT2;
//for(i=0;i<1000;i++);
//P2OUT&=~BIT0;
//SPI_Write9954(0x02,0x00); //Amplitude Scale Factor
//SPI_WriteOne9954(0x00);
while(1){
P2OUT&=~BIT0;
SPI_WriteOne9954(0x0B);
for(i=0;i<8;i++){
SPI_Write9954(0x00,0x00);
SPI_Write9954(0x08,0xff);
}
for(i=0;i<8;i++){
SPI_Write9954(0x00,0x00);
SPI_Write9954(0x0f,0xff);
}
P2OUT|=BIT0;
};
}
#pragma vector=USART1RX_VECTOR
__interrupt void SPI1_rx (void)
{
TimeData=RXBUF1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -