STM32实现流水灯

led.c

#include"led.h"

void Led_Init(void)
{
	GPIO_InitTypeDef GPIO_VALUE; //???
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//???
	GPIO_VALUE.GPIO_Mode=GPIO_Mode_Out_PP;//???? ????
	GPIO_VALUE.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;//????
	GPIO_VALUE.GPIO_Speed=GPIO_Speed_50MHz;//????
	GPIO_Init(GPIOC,&GPIO_VALUE);//???	
}
void Led_On(int nu)
{
	switch(nu)
	{
		case 0:GPIO_SetBits(GPIOC,GPIO_Pin_1);break;
		case 1:GPIO_SetBits(GPIOC,GPIO_Pin_2);break;
		case 2:GPIO_SetBits(GPIOC,GPIO_Pin_3);break;
	}
		
}
void Led_Off(int nu)
{
	switch(nu)
	{
		case 0:GPIO_ResetBits(GPIOC,GPIO_Pin_1);break;
		case 1:GPIO_ResetBits(GPIOC,GPIO_Pin_2);break;
		case 2:GPIO_ResetBits(GPIOC,GPIO_Pin_3);break;
	}	
}

led.h

#ifndef __LED_H
#define __LED_H
#include "stm32f10x_conf.h"

extern void Led_Init(void);
extern void Led_On(int opt);
extern void Led_Off(int opt);
#endif 

main.c

#include "led.h"

int main(void)
{
	int i,j;
	Led_Init();
	while(1){
		Led_On(0);
	for(i=0;i<1000;i++)
	  for(j=0;j<1000;j++);
	Led_Off(0);
	
		Led_On(1);
	for(i=0;i<1000;i++)
	  for(j=0;j<1000;j++);
	Led_Off(1);
	
		Led_On(2);
	for(i=0;i<1000;i++)
	  for(j=0;j<1000;j++);
	Led_Off(2);
	}
	return 0;
}






相关推荐

  1. STM32——点

    2023-12-25 06:02:01       32 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-25 06:02:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-25 06:02:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-25 06:02:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-25 06:02:01       18 阅读

热门阅读

  1. 【PostgreSQL表增加/删除字段是否会重写表】

    2023-12-25 06:02:01       34 阅读
  2. C#编程简单应用程序批量修改文件名2.0

    2023-12-25 06:02:01       42 阅读
  3. Node.js教程-mysql模块

    2023-12-25 06:02:01       36 阅读
  4. SQL面试题挑战06:互相关注的人

    2023-12-25 06:02:01       32 阅读
  5. 客户需求分析常用的ChatGPT通用提示词模板

    2023-12-25 06:02:01       38 阅读
  6. C++多线程学习笔记004简单的Producer和Consumer模型

    2023-12-25 06:02:01       39 阅读
  7. Ubuntu18.04安装GTSAM库(亲测可用)

    2023-12-25 06:02:01       41 阅读
  8. OV5640:寄存器 自用

    2023-12-25 06:02:01       39 阅读
  9. KPM算法快速检索文本

    2023-12-25 06:02:01       35 阅读
  10. LeetCode day30

    2023-12-25 06:02:01       44 阅读
  11. 常用算法-桶排序

    2023-12-25 06:02:01       32 阅读