📄 ads834x.c
字号:
U0BR1 = 0x00; //
U0MCTL = 0x00; // Modulation control - not used. Ensure
// all these bits are reset
}
/************************************************************/
/* Prototype - init_adc */
/* */
/* !NA init_adc */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV * */
/* Description */
/* This prototype sets-up the ADS8344 ADC */
/************************************************************/
void init_adc (void)
{
// Do one dummy cycle at startup to ensure proper clock mode operation
P3OUT &= ~(ADC_CS) ; // Assert ADC_CS LOW
JUNK = U0RXBUF; // Trash.
U0TXBUF = (ADC_INIT); // See ADS8344.h for details
while ((IFG1 & URXIFG0) == 0);
JUNK = U0RXBUF; // Trash.
U0TXBUF = (0x00); // Send clocks to the ADC
while ((IFG1 & URXIFG0) == 0);
P3OUT |= ADC_CS ; // Assert ADC_CS HIGH
JUNK = U0RXBUF; // Clear the recieve buffer to ensure porper sample alignment.
}
/************************************************************/
/* 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 - displayTest */
/* */
/* Display the sampled channel and conversion results */
/************************************************************/
void displayTest(int type)
{
switch (type)
{
case 0:
displayMinor(5,UD_P1_C);
displayMinor(4,UD_P2_H);
displayMinor(3,UR_ZERO);
displayMinor(2,UR_ZERO);
sortMajor(adc_Data[i]);
break;
case 1:
displayMinor(5,UD_P1_C);
displayMinor(4,UD_P2_H);
displayMinor(3,UR_ZERO);
displayMinor(2,UR_TWO);
sortMajor(adc_Data[i]);
break;
case 2:
displayMinor(5,UD_P1_C);
displayMinor(4,UD_P2_H);
displayMinor(3,UR_ZERO);
displayMinor(2,UR_FOUR);
sortMajor(adc_Data[i]);
break;
case 3:
displayMinor(5,UD_P1_C);
displayMinor(4,UD_P2_H);
displayMinor(3,UR_ZERO);
displayMinor(2,UR_SIX);
sortMajor(adc_Data[i]);
break;
case 4:
displayMinor(5,UD_P1_C);
displayMinor(4,UD_P2_H);
displayMinor(3,UR_ZERO);
displayMinor(2,UR_ONE);
sortMajor(adc_Data[i]);
break;
case 5:
displayMinor(5,UD_P1_C);
displayMinor(4,UD_P2_H);
displayMinor(3,UR_ZERO);
displayMinor(2,UR_THREE);
sortMajor(adc_Data[i]);
break;
case 6:
displayMinor(5,UD_P1_C);
displayMinor(4,UD_P2_H);
displayMinor(3,UR_ZERO);
displayMinor(2,UR_FIVE);
sortMajor(adc_Data[i]);
break;
case 7:
displayMinor(5,UD_P1_C);
displayMinor(4,UD_P2_H);
displayMinor(3,UR_ZERO);
displayMinor(2,UR_SEVEN);
sortMajor(adc_Data[i]);
break;
}
}
/************************************************************/
/* Prototype - convert */
/* */
/* !NA convert */
/* !LA ANSI C */
/* !PI * */
/* !PO * */
/* !LV * */
/* Description */
/* This prototype does the adc conversion */
/************************************************************/
void adc_convert (int cnt)
{
int channel = 0;
switch (DispType)
{
case 0:
channel = (0x87);
break;
case 1:
channel = (0x97);
break;
case 2:
channel = (0xA7);
break;
case 3:
channel = (0xB7);
break;
case 4:
channel = (0xC7);
break;
case 5:
channel = (0xD7);
break;
case 6:
channel = (0xE7);
break;
case 7:
channel = (0xF7);
break;
}
P3OUT &= ~ADC_CS ; // Assert ADC_CS LOW
U0TXBUF = (channel); // See above switch routine for details
while ((IFG1 & URXIFG0) == 0);
JUNK = U0RXBUF; // First byte is garbage
delay(20); // delay a little to complete conversion
U0TXBUF = (0x00); // Send clocks to the ADC
while ((IFG1 & URXIFG0) == 0);
FRST7 = U0RXBUF; // Store this data in the FRST7 variable
U0TXBUF = (0x00); // Send clocks to the ADC
while ((IFG1 & URXIFG0) == 0);
NEXT8 = U0RXBUF; // Store this data in the NEXT8 variable.
U0TXBUF = (0x00); // Send clocks to the ADC
while ((IFG1 & URXIFG0) == 0);
LAST1 = U0RXBUF; // Store this data in the LAST1 variable.
P3OUT |= ADC_CS; // Assert ADC_CS HIGH
// Format and concatinate recieved data bytes
adc_Data[cnt] = ((FRST7<<9) + ((NEXT8<<1) + (LAST1>>7)));
}
#pragma vector=PORT1_VECTOR
__interrupt void CH_switch (void)
// interruptactivated by PB Switch labeled SW2
{
P1IFG &= ~BIT6;
DispType = DispType + 1;
delay(5);
if (DispType >= 8) DispType = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -