为什么长按一松开就执行if(i<20) GPIOF_ODR=0x00ff;?
时间:10-02
整理:3721RD
点击:
#include "STM32F103.h"
/*------------------------- 延时函数 -------------------------*/
void Delay(vu32 nCount)
{
u32 run;
for(run=0; run<=nCount; run++);
}
/*------------------------------------------ 主函数 ------------------------------------------*/
int main(void)
{
/*----按键码对应
key0 --- 0xfffe
key1 --- 0xfffd
key2 --- 0xfffb
key3 --- 0xfff7
key4 --- 0xffef
key5 --- 0xffdf
key6 --- 0xffbf
key7 --- 0xff7f
key8 --- 0xfeff
key9 --- 0xfdff
key10 --- 0xfbff
key11 --- 0xf7ff
key12 --- 0xefff
key13 --- 0xdfff
key14 --- 0xbfff
key15 --- 0x7fff
---------------*/
u16 keys[] = {0xfffe,0xfffd,0xfffb,0xfff7,
0xffef,0xffdf,0xffbf,0xff7f,
0xfeff,0xfdff,0xfbff,0xf7ff,
0xefff,0xdfff,0xbfff,0x7fff};
// u16 data; //定义2个新的变量
u16 LedNum=0; //定义变量
u32 i,j,p,k=30,T=0xAFFFF/40,TT=0xAFFFF/10;
u32 t=T/16,tt=TT/20;
RCC_APB2ENR |=((u32)0x00000fff); //打开GPIO组的时钟总线
GPIOG_CRL=((u32)0x88888888); //设置GPIOD组低八位为输入线
GPIOG_CRH=((u32)0x88888888); //设置GPIOD组高八位为输入线
GPIOF_CRL=((u32)0x11111111); //设置GPIOF组低八位为输出线
GPIOF_CRH=((u32)0x11111111); //设置GPIOF组低八位为输出线
/*------------------------------------------ 程序运行区 ------------------------------------------*/
GPIOF_ODR = ((u16)0xffff);
while(1)
{
u16 i;
if(GPIOG_IDR == keys[1])
{
i=0;
while(GPIOG_IDR == keys[1])
{
Delay(300000);
i++;
if(i==20) break;
}
if(i<20) GPIOF_ODR=0x00ff;
else GPIOF_ODR=0xff00;
}
}
}
/*------------------------- 延时函数 -------------------------*/
void Delay(vu32 nCount)
{
u32 run;
for(run=0; run<=nCount; run++);
}
/*------------------------------------------ 主函数 ------------------------------------------*/
int main(void)
{
/*----按键码对应
key0 --- 0xfffe
key1 --- 0xfffd
key2 --- 0xfffb
key3 --- 0xfff7
key4 --- 0xffef
key5 --- 0xffdf
key6 --- 0xffbf
key7 --- 0xff7f
key8 --- 0xfeff
key9 --- 0xfdff
key10 --- 0xfbff
key11 --- 0xf7ff
key12 --- 0xefff
key13 --- 0xdfff
key14 --- 0xbfff
key15 --- 0x7fff
---------------*/
u16 keys[] = {0xfffe,0xfffd,0xfffb,0xfff7,
0xffef,0xffdf,0xffbf,0xff7f,
0xfeff,0xfdff,0xfbff,0xf7ff,
0xefff,0xdfff,0xbfff,0x7fff};
// u16 data; //定义2个新的变量
u16 LedNum=0; //定义变量
u32 i,j,p,k=30,T=0xAFFFF/40,TT=0xAFFFF/10;
u32 t=T/16,tt=TT/20;
RCC_APB2ENR |=((u32)0x00000fff); //打开GPIO组的时钟总线
GPIOG_CRL=((u32)0x88888888); //设置GPIOD组低八位为输入线
GPIOG_CRH=((u32)0x88888888); //设置GPIOD组高八位为输入线
GPIOF_CRL=((u32)0x11111111); //设置GPIOF组低八位为输出线
GPIOF_CRH=((u32)0x11111111); //设置GPIOF组低八位为输出线
/*------------------------------------------ 程序运行区 ------------------------------------------*/
GPIOF_ODR = ((u16)0xffff);
while(1)
{
u16 i;
if(GPIOG_IDR == keys[1])
{
i=0;
while(GPIOG_IDR == keys[1])
{
Delay(300000);
i++;
if(i==20) break;
}
if(i<20) GPIOF_ODR=0x00ff;
else GPIOF_ODR=0xff00;
}
}
}