📄 init.h
字号:
#define SWAP(x,y) {float temp=(x);(x)=(y);(y)=temp;}
#define M_PI 3.1415926
#define NNN 1024 //傅立叶变换的点数
#define fs 512 //采样频率
#define FMAX 100
#define VERSION 340 //IAR version
#define DMA_ADDRESS 0x3080
#define FLASH_B 0x1000 //存放默认的涡街内径,仪表系数,介质密度等参数
#define FLASH_A 0X1080 //存放修改的涡街内径,仪表系数,介质密度等参数
static float Coefficient[3]={50,9.123,1}; //涡街内径,涡街的仪表系数,管道介质密度
//main variable
//char fs_edit=2; //采样频率修正值
char time=0;
char caculate_flag=1;
char excaculate_flag=1;
float Diameter=0,Meter_coeffient=0,Density=0;
float f=20,Q=0,QL=0;
//main function
void CLOCK_Init(void);
void FLASH_Init(void);
void Write_unchar_FLASH(unsigned char *Flash_ptr,unsigned char Flash_value);
void Write_float_FLASH (float *Flash_ptr,float Flash_value);
void RESET_FLASH (float *Flash_ptrA,float *Flash_ptrB);
void FLASH_CLR(float *FLASH_ptr );
//////////////////////////////////////////////////////////////////////////
//ADC12 variable
__no_init float dat[NNN+1];
unsigned int AD_cnt=1;
unsigned int *DMA_ptr,*DMA_ptr1;
//FFT variable
__no_init float Power_spectrum_dat[NNN/2+1];
unsigned int i;
float f_fft_caculate;
float f_fft=0,K=0;
float tempr,tempi;
float wtemp,wr,wpr,wpi,wi,theta;
int n,mmax,m,q,istep,p;
float theta1,theta2,theta3;
//FFT caculate function
void ADC12_init(void);
void FFT_AD(void);
void FFT(float*);
float FFT_power_spectrum(void);
float FFT_caculate(void);
//////////////////////////////////////////////////////////////////////////
void CLOCK_Init(void)
{
BCSCTL1=0x00;
BCSCTL2=0x88;
do //wait in loop until crystal is stable
{
IFG1&=~OFIFG;
for (i = 0xFF; i > 0; i--); // Time for flag to set
}while(OFIFG&IFG1);
}
void UART_Init(void)
{
//------------------------------通讯口初始化------------------------------//
P3SEL |= BIT4 + BIT5;
ME1 |= URXE0 + UTXE0; // Enable USART0 RXD + TXD
UCTL0 |= CHAR + SWRST;
UBR00 = 0x06; // set the baud rate=4800
UBR10 = 0; // UBR+(m7+...m0)/8=32768/4800=6.83
UMCTL0 = 0xFB; // UBR=0xFB 利用公式得出UMCTL0的值
UTCTL0|= SSEL0; //select ACLK
URCTL0 = URXEIE; //接受出错中断允许位???
UCTL0 &= ~SWRST;
IE1 |= URXIE0; // Enable USART0 RX interrupt
}
float *ptrFCoefficient = (float *)FLASH_A; // 指向存放涡街口径和仪表修正系数的地址
unsigned char *ptrChCoefficient = (unsigned char *)FLASH_A;// 指向存放涡街口径和仪表修正系数的地址
char COEFFICIENT;
void FLASH_Init(void)
{
COEFFICIENT = 1;
if((*((char *)(ptrFCoefficient+3)))==0xAA)
{
Diameter = *ptrFCoefficient;
Meter_coeffient = *(ptrFCoefficient+1);
Density = *(ptrFCoefficient+2);
}
else
{
for(i=0;i<3;i++)
{
Write_float_FLASH ((float *)FLASH_B+i,Coefficient[i]);
Write_float_FLASH ((float *)FLASH_A+i,Coefficient[i]);
}
Write_unchar_FLASH ((unsigned char *)FLASH_B+12,0xAA);
Write_unchar_FLASH ((unsigned char *)FLASH_A+12,0xAA);
Diameter = *ptrFCoefficient;
Meter_coeffient = *(ptrFCoefficient+1);
Density = *(ptrFCoefficient+2);
}
}
void Write_unchar_FLASH(unsigned char *Flash_ptr,unsigned char Flash_value)
{
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
*Flash_ptr = Flash_value; // Write value to flash
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
void Write_float_FLASH (float *Flash_ptr,float Flash_value)
{
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
*Flash_ptr = Flash_value; // Write value to flash
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
void RESET_FLASH (float *Flash_ptrA,float *Flash_ptrB)
{
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptrA = 0; // Dummy write to erase Flash segment B
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<32; i++)
{
*Flash_ptrA++ = *Flash_ptrB++; // Copy value segment A to segment B
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
void FLASH_CLR(float *Flash_ptr )
{
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment B
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -