| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1206 人关注过本帖
标题:自己做小流水灯 按一个按钮 就能重复6次怎么做
只看楼主 加入收藏
led5457
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-8-13
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
自己做小流水灯 按一个按钮 就能重复6次怎么做
int main(void)
{      //u8 i=0;
     u8 res;
    u8  mes=9;
    u8 mesbin=0xff;
    u8  i,aa=0x01;

   
   
    GPIO_InitTypeDef  GPIO_InitStructure;
    Debug_USART_Config();  //串口初始化
    SysTick_Init();        //系统滴答时钟初始化
    KEY_Init();               //IO初始化
    BEEP_Init();
        
    //LED_Init();          //初始化
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);//使能GPIOF时钟
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE);//使能GPIOF时钟
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOF时钟
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//使能GPIOF时钟
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);//使能GPIOF时钟
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);//使能GPIOF时钟
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//使能GPIOF时钟
   
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_13;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;         //普通输出模式
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;        //推挽输出
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;    //100MHz
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;          //上拉   
    GPIO_Init(GPIOD, &GPIO_InitStructure);                //初始化
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11;
    GPIO_Init(GPIOI, &GPIO_InitStructure);                 //初始化
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_2| GPIO_Pin_7| GPIO_Pin_0;
    GPIO_Init(GPIOA, &GPIO_InitStructure);                 //初始化
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_8;
    GPIO_Init(GPIOF, &GPIO_InitStructure);                 //初始化
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2| GPIO_Pin_5 | GPIO_Pin_8 ;
    GPIO_Init(GPIOC, &GPIO_InitStructure);                 //初始化
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ;
    GPIO_Init(GPIOH, &GPIO_InitStructure);                 //初始化
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
    GPIO_Init(GPIOD, &GPIO_InitStructure);                 //初始化
            
    while (1)
    {     Show_bin(mesbin);
       res=KEY_Scan(0);                     
       if(res)                                            //如果有按下
         {  Beep(1);                                       //蜂鸣器
            // i=res;
   
     switch(res)
     {
        case KEY1_ON:
                      aa=0x01;
                      for(i=0;i<7;i++    )     
                      { Show_bin(aa);  
                       aa=aa<<1;
                       Sleep_ms(1000);           
                }     
     }
搜索更多相关主题的帖子: 流水灯 重复 res 初始化 时钟 
2017-08-13 15:01
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:20 
外层循环6次:  
for(j=0;j<6;j++    )     
                       {
aa=0x01;
                       for(i=0;i<7;i++    )     
                       { Show_bin(aa);  
                        aa=aa<<1;
                        Sleep_ms(1000);           
                 }
}     
2017-08-14 09:31
快速回复:自己做小流水灯 按一个按钮 就能重复6次怎么做
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021046 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved