找回密码
 注册

QQ登录

只需一步,快速开始

搜索

proteus仿真STM32 GPIOC口分别接有一个开关K1和两个指示灯 两个灯一亮一灭

[复制链接]
路漫漫 发表于 2020-6-10 23:30:01 | 显示全部楼层 |阅读模式
proteus仿真STM32 GPIOC口分别接有一个开关K1和两个指示灯 两个灯一亮一灭
c语言程序和仿真文件.7z (60.48 KB, 售价: 1 E币)
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
1.png
本程序以stm32f10x为核心
部分源码:
  1. #include"stm32f10x.h"
  2. voidGPIO_Config(void);
  3. intmain(void)
  4. {   
  5.    
  6.     int i;
  7.     GPIO_Config();
  8.     GPIO_SetBits(GPIOC, GPIO_Pin_5);  
  9.      GPIO_ResetBits(GPIOC, GPIO_Pin_6);
  10.     while(1)
  11.     {
  12.             if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_10)==0)
  13.             {
  14.                 for(i=0;i<500;i++){}
  15.                    if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_10)==0)
  16.                    {
  17.                        GPIO_WriteBit( GPIOC,GPIO_Pin_5, (BitAction)(1 - GPIO_ReadOutputDataBit( GPIOC, GPIO_Pin_5 )));
  18.                        GPIO_WriteBit( GPIOC,GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit( GPIOC, GPIO_Pin_6 )));
  19.                        while(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_10)==0);
  20.                    }
  21.          
  22.          }
  23.      }
  24.      
  25. }
  26. voidGPIO_Config(void)
  27. {
  28.    
  29.   GPIO_InitTypeDef GPIO_InitStructure;
  30.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE) ;
  31.     GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  32.     GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  33.     GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_5;
  34.     GPIO_Init(GPIOC,&GPIO_InitStructure);
  35.     GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
  36.     GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
  37.     GPIO_Init(GPIOC,&GPIO_InitStructure);
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-4-26 15:43

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表