?? spidac.c
字號:
#include "Headfiles.h"
void SPI_Data_Output(unsigned char send_data)
{
unsigned char tmp;
tmp = SPI1BUF; //No meaning, avoid receive overflow
while (SPI1STATbits.SPITBF); //Wait for idle of SPI
SPI1BUF = send_data; //Write data to SPI write_register
//while (!SPI1STATbits.SPIRBF); //Wait for send over of SPI
// SPI1STATbits.SPIROV = 0;
// tmp = SPI1BUF;
}
///***********************************************************************
//Func. Name: DAC data processing(DP)
//Input variables: None
//Output variables: None
//Use sub-func.list: None
//Used by list: ADCDAC.c -- DAC
//Description: Process the digtal data for DAC output
//************************************************************************
void DAC_Datatreat(void)
{
unsigned char i;
int temp_output[2];
temp_output[0] = PID[0] + System_Zero_Point[0];
//conrol_parameter_6 is zero-point of 1-channel
temp_output[1] = PID[1] + System_Zero_Point[1];
//conrol_parameter_13 is zero-point of 2-channel
//-------------------------Output data restriction & zero-point motion
for (i = 0; i < 2; i++)
{
if (temp_output[i] >= 32767)
{
temp_output[i] = 32767;
}
else if (temp_output[i] <= -32768)
{
temp_output[i] = -32768;
}
Output[i] = temp_output[i] + 32768;
//Make sure the data must be 0~65535(0x0000~0xffff)
}
}
///************************************************************************
//Func. Name: DAC (Digtal to analog convert)
//Input variables: None
//Output variables: None
//Use sub-func.list: ADCDAC.c -- DAC_Datatreat
//Used by list: MainFunc.c -- TIMER_A (ISR)
//Description: Output the control signal for controlling servo-valve
// ------------------------
// | MSP430 |
// | F167 P6.6/A6/DAC0 |5pin--> Servo valve 1
// | P6.7/A7/DAC1 |6pin--> Servo valve 2
// | |
//************************************************************************
void SPI_SendData_to_DAC(unsigned char command, unsigned int data_16bits)
{
unsigned char low_8bits, high_8bits;
low_8bits = (data_16bits & 0x00FF);
high_8bits = ((data_16bits >> 8) & 0x00FF);
_DACSYNC_ENABLE(); //Enable peripheral DAC moduel
_SPION(); //Enable SPI
SPI_Data_Output(command); //Send command(8bits)
SPI_Data_Output(high_8bits); //Send high 8bits
SPI_Data_Output(low_8bits); //Send low 8bits
_SPIOFF(); //Disable SPI
_DACSYNC_DISABLE(); //Disable peripheral DAC moduel
}
void DAC(void)
{
DAC_Datatreat(); // DAC data processing
SPI_SendData_to_DAC(0x10, Output[0]); //Send the data to DAC_A
// SPI_SendData_to_DAC(0x20, Output[1]);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -