刚从硬件转过来学习STM8L,自己写了个ADC采集程序,结果一直采集不到数据,求各位高手指点,谢谢!
#include "stm8l151g4.h"
#include "led_init.h"
#include "adc_init.h"
typedef unsigned short uint16_t;
main()
{
uint16_t Value;//unsigned int Value;
int i;
adc_init();
while (1)
{
Value = 0;
ADC1_CR1 |=0x01;/*turn on ADC again*/
i = 10;
while(i--);
while(!(0x01&ADC1_SR));// 是否转换完成
ADC1_SR=0xFE; // 转换完成,软件清零
Value = (uint16_t)ADC1_DRH;//(unsigned int)ADC1_DRH;
Value = Value<<8;
Value =((uint16_t)Value|ADC1_DRL);
}
}
#include "adc_init.h"
void adc_init(void)
{
PD_DDR=0X00; /* 0:Input mode */
PD_CR1=0X00; /* 0: Floating input */
PD_CR2=0X00; /* 0: External interrupt disabled */
CLK_PCKENR2|=0x01; /* open Peripheral ADC clk */
ADC1_CR1 = 0x00; /* 0x00:turn off ADC ,12 bit resolution */
ADC1_CR2 = 0x00;
ADC1_SR|= 0x00; /* Conversion not complete */
ADC1_SQR1=0x80; /* turn off DMA */
ADC1_SQR2|=0x04; /* select 19 channel */
ADC1_TRIGR1|=0X10; /* turn on Internal reference voltage */
ADC1_TRIGR2|=0X10; /* schmitt trigger 19 disable */
ADC1_CR1 |=0x01; /* turn on ADC */
} |