📄 ads7871a.c
字号:
void TX_complete(void)
{
#if (SITE1)
do
{
IFG1 &=~ UTXIFG0;
}
while (UTXIFG0 & IFG1);
delay(10);
#else
do
{
IFG2 &=~ UTXIFG1;
}
while (UTXIFG1 & IFG2);
#endif
}
/************************************************************/
/* Prototype - convert */
/* */
/* !NA convert */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV * */
/* Description */
/* This prototype does the adc conversion */
/************************************************************/
void timer(void)
{
TACTL = TASSEL1 + TACLR; // SMCLK, Clear Tar
CCR0 = 4-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = 2; // CCR1 PWM duty cycle
TACTL |= MC0; // Start Timer_A in up mode
}
/************************************************************/
/* Prototype - delay */
/* */
/* !NA delay */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV i */
/* Description */
/* This prototype gives a delay of around 1 second */
/************************************************************/
void delay(int time)
{
unsigned int i;
for (i = 0; i > time; i--);
}
/************************************************************/
/* Prototype - RESET_ADC */
/* */
/* !NA delay */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV i */
/* Description */
/* This prototype resets the ADS787x Device */
/************************************************************/
void RESET_ADC(void)
{
#if HDW_RST
P3OUT &= ~ADC_RST ;
P3OUT |= ADC_RST ;
#else
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = REG0; // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been received.
P3OUT |= ADC_CS ; // Assert ADC_CS HIGH
#endif
}
/************************************************************/
/* Prototype - SET_R3 */
/* */
/* !NA delay */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV i */
/* Description */
/* This prototype resets the ADS787x Device */
/************************************************************/
void SET_R3(int value)
{
//while(1){
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = REG3; // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (value); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
P3OUT |= ADC_CS ; // Assert ADC_CS LOW
//}
}
/************************************************************/
/* Prototype - SET_R3 */
/* */
/* !NA delay */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV i */
/* Description */
/* This prototype resets the ADS787x Device */
/************************************************************/
void SET_R6(int value)
{
//while(1){
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = REG6; // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (value); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
P3OUT |= ADC_CS ; // Assert ADC_CS LOW
//}
}
/************************************************************/
/* Prototype - SET_R7 */
/* */
/* !NA delay */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV i */
/* Description */
/* This prototype resets the ADS787x Device */
/************************************************************/
void SET_R7(int value)
{
#if EXT_CLK
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = (WRITE + REG7); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (value); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
P3OUT |= ADC_CS ; // Assert ADC_CS HIGH
#else
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = (WRITE + REG7); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (OSCR+OSCE+value); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
P3OUT |= ADC_CS ; // Assert ADC_CS HIGH
#endif
delay(10);
}
/************************************************************/
/* Prototype - SET_R24 */
/* */
/* !NA delay */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV i */
/* Description */
/* This prototype resets the ADS787x Device */
/************************************************************/
void SET_R24(int value)
{
//while(1){
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = REG24; // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (value); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
P3OUT |= ADC_CS ; // Assert ADC_CS LOW
//}
}
/************************************************************/
/* Prototype - Read_REG */
/* */
/* !NA delay */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV i */
/* Description */
/* This prototype resets the ADS787x Device */
/************************************************************/
void Read_REG(int REG)
{
int value;
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = (READ + REG); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (0x00); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
value = U0RXBUF;
P3OUT |= ADC_CS ; // Assert ADC_CS HIGH
delay(10);
}
/************************************************************/
/* Prototype - flash */
/* */
/* !NA flash */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV i */
/* Description */
/* This prototype indicates the program is complete */
/************************************************************/
void display(void)
{
while(1)
{
P1OUT |= BIT0; // Set P1.0
delay(100);
P1OUT &= ~BIT0; // Clear P1.0
delay(100);
}
}
/************************************************************/
/* Prototype - convert */
/* */
/* !NA convert */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV * */
/* Description */
/* This prototype does the adc conversion */
/************************************************************/
void adc_convert (void)
{
//while(1){
#if DIRECTMODE
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = (DIRECT+GAIN01+SING0); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
P3OUT |= ADC_CS; // De-assert ADC_CS HIGH
#else
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
//P3OUT |= CONVERT;
//P3OUT &= ~CONVERT;
U0TXBUF = (REGISTER+WORD+WRITE+REG4);// Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (CNV_BSY+GAIN01+SING0); // Send clocks to the ADC, this shifts
// in the second 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (0x0F & i); // Toggle GPIO's
// in the second 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
P3OUT |= ADC_CS; // De-assert ADC_CS HIGH
#endif
//}
}
/************************************************************/
/* Prototype - convert */
/* */
/* !NA convert */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV * */
/* Description */
/* This prototype does the adc conversion */
/************************************************************/
void adc_read (int cnt)
{
unsigned int trash;
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = (READ+WORD+REG1); // Send clocks to the ADC, this shifts
// in the first 8 bits of data.
TX_complete(); // Wait until all 8 bits have been transmitted.
U0TXBUF = (0x00); // Send clocks to the ADC, this shifts
// in the second 8 bits of data.
TX_complete(); // Wait until all 8 bits have been received.
hi_byte = U0RXBUF; // Store this data in the hi-byte variable.
U0TXBUF = (0x00); // Send clocks to the ADC, this shifts
// in the second 8 bits of data.
TX_complete(); // Wait until all 8 bits have been received.
lo_byte = U0RXBUF; // Store this data in the lo-byte variable.
//Read_REG(3);
P3OUT |= ADC_CS; // De-assert ADC_CS HIGH
trash = U0RXBUF; // Clear the receiver
adc_hi = hi_byte << 8; // Left-shift the hi-byte 8-bits, to prepare
if (ADS7871){ // for the second byte.
adc_data[cnt] = (adc_hi + lo_byte)>>1; // Join the hi-byte and the lo-byte together.
}
if (ADS7870){
adc_data[cnt] = (adc_hi + lo_byte)>>3; // Join the hi-byte and the lo-byte together.
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -