本人是菜鸟,大神勿喷。
void ADC_Init(void)
{
SysCtlPeriEnable(SYSCTL_PERIPH_ADC); // 使能ADC模块
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); // 设置ADC采样率
ADCSequenceDisable(ADC_BASE , 0); // 禁止采样序列
ADCSequenceConfigure(ADC_BASE , // 采样序列配置
0 , // 采样序列编号
ADC_TRIGGER_PROCESSOR , // 由处理器触发
0); // 设置优先级
// ADCHardwareOversampleConfigure(ADC_BASE, 16); // 硬件过采样配置
ADCSequenceStepConfigure(ADC_BASE , // 采样步进设置
0 , // 采样序列编号
0 , // 设置步进
ADC_CTL_END | ADC_CTL_CH0); // 通道设置 从ADC0口读入数据
ADCSequenceEnable(ADC_BASE , 0); // 使能采样序列
}
void ADC_Getresult(void)
{
unsigned long ulVal = 0x00; //用来保存转换后的数字量
unsigned char Val,Voltage0 = 0,Voltage1 = 0, Voltage2 = 0, Voltage3 = 0, Voltage4 = 0, Voltage5 = 0;
ADCProcessorTrigger(ADC_BASE , 0); //触发样本序列
while ( HWREG(ADC_BASE+ADC_O_X_SSFSTAT) & 0x00000100 ); //等待样本序列采集完成
ADCSequenceDataGet(ADC_BASE , 0 , &ulVal); //获取采集的结果
ulVal = ulVal * (3000 / 1024);//将结果进行转换单位mV
Voltage0 = (int)(ulVal / 100000) + '0';
Voltage1 = (int)(ulVal % 100000 / 10000) + '0';
Voltage2 = (int)(ulVal % 10000 / 1000) + '0';
Voltage3 = (int)(ulVal % 1000 / 100) + '0';
Voltage4 = (int)(ulVal % 100 / 10) + '0';
Voltage5 = (int)(ulVal % 10) + '0';
showzifu(100,85,Voltage0,0,0xffff); //显示字符串
showzifu(112,85,Voltage1,0,0xffff); //显示字符串
showzifu(124,85,Voltage2,0,0xffff); //显示字符串
showzifu(136,85,Voltage3,0,0xffff); //显示字符串
showzifu(148,85,Voltage4,0,0xffff); //显示字符串
showzifu(160,85,Voltage5,0,0xffff); //显示字符串
}
此帖出自
小平头技术问答
一周热门 更多>