欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3125|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

STM32無法循環(huán)點亮,求個大神幫幫忙

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:783526 發(fā)表于 2020-6-21 11:22 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
#include "stm32f10x.h"
uint16_t temp,i;
void Delay(unsigned int count)
{
        unsigned int i;
        for(;count!=0;count--)
        {
                i=5000;
                while(i--);
        }
}
void main(void)
{
        
        GPIO_InitTypeDef GPIO_InitStructure;
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOB,&GPIO_InitStructure);
        
        while(1)
        {
               
                if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==0)
                {
                        Delay(500);
                        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==0)
                        {
                                temp=0x0100;
                    for(i=0;i<8;i++)
                    {
                                 
                            GPIO_Write(GPIOB,~temp);
                             Delay(100);
                            temp=temp<<1;
                                        while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1);
                    }
                        }
           }else if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1){
                        
                         temp=0x8000;
                         for(i=7;i>=0;i--)
                    {
                                 
                            GPIO_Write(GPIOB,~temp);
                             Delay(100);
                            temp=temp>>1;
                                        while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1);
                    }
                 }

                        
         }
        
}

1.PNG (41.31 KB, 下載次數(shù): 72)

1.PNG
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:277948 發(fā)表于 2020-6-21 18:19 | 只看該作者
我把程序改為 按鍵按下燈取反四次

#include "stm32f10x.h"
#include "sys.h"
//#include "intrins.h"
#define LED1 PDout(2)        // PD2       
uint16_t temp,i;
void Delay(unsigned int count)
{
        unsigned int i;
        for(;count!=0;count--)
        {
                i=5000;
                while(i--);
        }
}
int main(void)
{

        GPIO_InitTypeDef GPIO_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;//注意GPIO_Mode_IPD不是GPIO_Mode_IPU
        GPIO_Init(GPIOA, &GPIO_InitStructure);

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOD,&GPIO_InitStructure);
                                temp=0x0001;//注要放在循環(huán)前邊
while(1)
{
        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1)     //沒按下按鍵為0 按下按鍵為1
        {
                Delay(200);
                if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1)
                {
                        for(i=0;i<8;i++)
                        {
//                                GPIO_Write(GPIOD,temp);
                                LED1=!LED1;
                                Delay(1000);
                        }
                }
   }while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==0); //按鍵釋放應(yīng)該放在按鍵判斷之外
}        
}

回復(fù)

使用道具 舉報

板凳
ID:355173 發(fā)表于 2020-6-22 14:47 | 只看該作者
是IPU(上拉輸入),而IPD是(下拉),很明顯PA0接了個電阻到VDD,而當(dāng)有按鍵按下時,電路接通到地,所以PA0處讀到的電壓是0,當(dāng)釋放時,與VDD想接,是高電平為1
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表