项目用到一个64路的压力传感器,打算用两个8路的模拟开关进行采集,使用一个ADC接口采集数据,自定义了帧头EEEE帧尾FFFF,一帧数据共68位。可是收到的一帧数据中却是重复两次的前32路数据检测,请问下问题出现在那里?谢谢!
#include "adc.h"
#include "delay.h"
#include "usart.h"
#include "LCD.h"
#include "high.h"
//u8 FSR_BUF[68];
void control()
{
vcc_en=0;
gnd_en=0;
}
int channel[16][4]=
{
{0,0,0,0},//channel 0
{1,0,0,0},//channel 1
{0,1,0,0},//channel 2
{1,1,0,0},//channel 3
{0,0,1,0},//channel 4
{1,0,1,0},//channel 5
{0,1,1,0},//channel 6
{1,1,1,0},//channel 7
{0,0,0,1},//channel 8
{1,0,0,1},//channel 9
{0,1,0,1},//channel 10
{1,1,0,1},//channel 11
{0,0,1,1},//channel 12
{1,0,1,1},//channel 13
{0,1,1,1},//channel 14
{1,1,1,1} //channel 15
};
void getadc()
{
int k=2;
int i,j,a,p,m;
float temp;
u8 FSR_BUF[68];
FSR_BUF[0]=238;
FSR_BUF[1]=238;
FSR_BUF[66]=255;
FSR_BUF[67]=255;
//printf("
");
for(i=0;i<8;i++)
{
vcc_s0=channel[0];
vcc_s1=channel[1];
vcc_s2=channel[2];
vcc_s3=channel[3];
delay_ms(10);
for(j=0;j<8;j++)
{
gnd_s0=channel[j][0];
gnd_s1=channel[j][1];
gnd_s2=channel[j][2];
gnd_s3=channel[j][3];
delay_ms(10);
a=Get_Adc(ADC_Channel_1);
temp=(float)a*(3.3/4096);
p=temp*10;
if (p>200||p<=0)
{
p=0;
}
FSR_BUF[k]=p;
k++;
}
}
for(m=0;m<68;m++)
{
USART_SendData(USART1,FSR_BUF[m]);
while(RESET==USART_GetFlagStatus(USART1,USART_FLAG_TC));
}
}
int main(void)
{
delay_init();
delay_ms(1); //延时函数初始化
uart_init(9600); //串口初始化为9600
adc_init(); //ADC初始化
HIGH_Init();
control();
while(1)
{
getadc();
delay_ms(5);
}
}
一周热门 更多>