LM3S9b92里面ADC的初学例程,帮看下哪不对呢
[复制链接]
#include "inc/hw_types.h" #include "inc/hw_memmap.h" #include "driverlib/adc.h" #include "driverlib/gpio.h" #include "driverlib/sysctl.h" int main(void) { unsigned long ulValue=1000; SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);//设置时钟频率为16M SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //使能PF口 SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); //使能ADC GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_2); // 设置PF2口为输出模式
ADCSequenceConfigure(ADC_BASE,0,ADC_TRIGGER_PROCESSOR,0);//配置ADC,基准源是处理器发生 ADCSequenceStepConfigure(ADC_BASE,0,0,ADC_CTL_IE|ADC_CTL_END|ADC_CTL_CH5);//配置ADC,通道5采样 ADCSequenceEnable(ADC_BASE,0); //使能采样 while(1) { ADCProcessorTrigger(ADC_BASE,0);//开始采样 while(!ADCIntStatus(ADC_BASE,0,false));//等待采样状态为结束。 ADCSequenceDataGet(ADC_BASE,0,&ulValue) ; //获取采样值 if(ulValue<500) //判断采样值,控制led等亮灭 {GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0x04); } else {GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,0); }
} }
[ 本帖最后由 慢慢来 于 2011-2-15 11:44 编辑 ]
|