如题~PD5输入,读不到~使用库函数GPIO_ReadInputPin(GPIOD, GPIO_PIN_5);
头次使用STM8很多不知道的地方 ,还请大侠们多指点`~
unsigned char PWR_STA;
void PWR_CHECK(void)
{
static unsigned char i;
static unsigned char count;
unsigned char pwr_sta[SAMP_IO_COUNT];
unsigned char sum;
if(GPIO_ReadInputPin(GPIOD, GPIO_PIN_5) != RESET)
pwr_sta[count] = 1;
else
pwr_sta[count] = 0;
//pwr_sta[count]=GPIO_ReadInputData(GPIOD);
if (++count >= SAMP_IO_COUNT)
{
count = 0;
sum = 0;
for (i = 0; i < SAMP_IO_COUNT; i++)
{
sum += pwr_sta[i];
}
//10次中5次以上为高电平即为有闭门器电源
if(sum>=5)
PWR_STA = 1;
else
PWR_STA = 0;
}
}
初始化对应ADC通道后,然后调用函数ADC1_GetConversionValue()当去当前通道转换结果,这个结果寄存器是公用的,你初始化开启哪个通道,结果寄存器填写的就是哪个通道的转换值,没有一个通道对应一个结果寄存器,和STM32不一样的地方
明白否?
u16 Get_ADVAL(u8 tongdao)
{
u8 i=0;
u16 sum,V;
sum=0;
V=0;
for(i=0;i<10;i++)
{
ADC1_Init(ADC1_CONVERSIONMODE_SINGLE, tongdao, ADC1_PRESSEL_FCPU_D18, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, tongdao, DISABLE);
//while (!ADC1_GetFlagStatus(ADC1_FLAG_EOC));
delay_ms(2);
ADC1_ClearFlag(ADC1_FLAG_EOC);
V=ADC1_GetConversionValue();
sum+=V;
delay_ms(2);
}
sum=(u16)(sum/10.0);
return sum;
}
让大侠们见效了~
一周热门 更多>