extern void Delay(vu32 nCount);
#define NUM_OF_RESULTS 8 // Number of temp sensor samples to take
#define ADC_CHANNEL 0 // ADC channel for conversion
#define SCALE_FACTOR 3 // For averaging converted samples
#define ADC12_RATIO 0.805664 // 3300/4096(3300mV ref & 12bit converter, straight binary o/p)
#define ADC_INPUT0 0
#define ADC_INPUT1 1
#define ADC_INPUT2 2
#define ADC_INPUT3 3
#define ADC_INPUT4 4
#define ADC_INPUT5 5
#define ADC_INPUT6 6
#define ADC_INPUT7 7
volatile unsigned char bdata;
unsigned char ADC_Input = 0x00;
unsigned char ADC_Cnt = 0x00;
unsigned short ADC_Data = 0x0000;
unsigned char ADC_Numbytes = 0x00;
unsigned char i ; void TI_ADC128S022_Init(void)
{
ADC_Numbytes = 16;
ADC_Data = 0;
AD_CS_DISABLE();
AD_SCLK_DISABLE();
Delay(1000);
AD_CS_ENABLE();
#if 0
switch(NUM_OF_RESULTS)
{
case 0:ADC_Input = ADC_INPUT0; break;
case 1:ADC_Input = ADC_INPUT1; break;
case 2:ADC_Input = ADC_INPUT2; break;
case 3:ADC_Input = ADC_INPUT3; break;
case 4:ADC_Input = ADC_INPUT4; break;
case 5:ADC_Input = ADC_INPUT5; break;
case 6:ADC_Input = ADC_INPUT6; break;
case 7:ADC_Input = ADC_INPUT7; break;
default:
break;
}
#endif
ADC_Input = 0xe1;
for(ADC_Cnt = 0; ADC_Cnt < ADC_Numbytes; ADC_Cnt++)
{
Delay(1000);
AD_SCLK_DISABLE();
if (ADC_Cnt<5)
{
if(ADC_Input&0x80)
{
ADC_DOU_ENABLE();
}
else
{
ADC_DOU_DISABLE();
}
ADC_Input <<= 1;
}
else
{
ADC_DOU_DISABLE();
}
Delay(1000);
AD_SCLK_ENABLE();
Delay(1000);
// if(ADC_Cnt >= 4 )
// {
// ADC_Data <<= 1;
//if(ADC_DIN_ENABLE)
// {
// ADC_Data |= 0x0001;
// }
// else
// {
// ADC_Data &= 0xfffe;
// }
}
// else
// {;}
//}
AD_CS_DISABLE();
//AD_SCLK_ENABLE();
// *adc_data = ADC_Data;
// return;
// printf("%d ",ADC_Data); //这儿打印出来的值是4095
}
void TI_ADC128S022_ADC_vout (void)
{
uint8_t i;
static uint16_t results[NUM_OF_RESULTS]; // To store ADC output
static uint32_t sum_adc_data = 0; // accumulate and avg adc results
volatile static float vout; // ADC vout
for(i=0; i<8;i++)
{
results = SPI_ReadWriteByte(ADC_CHANNEL); // read and store ADC Channel output
sum_adc_data += results; // accumulate result
Delay(1000); // acquisition time
}
sum_adc_data >>= SCALE_FACTOR; // Average the accumulated sum
vout = sum_adc_data * ADC12_RATIO; // ADC vout
sum_adc_data = 0; // Set Breakpoint here & see measured vout
while(1)
{
printf("%f ",vout); //这儿打印值是205.444321
Delay(5000000);
}
}
int main(void)
{
Init_Usart();
SPI_Configuration();
TI_ADC128S022_Init();
TI_ADC128S022_ADC_vout();
}
问题出在哪了,这是我的程序
|