历史上的今天
今天是:2024年10月21日(星期一)
2019年10月21日 | STM32流水灯的几种实现方法
2019-10-21 来源:eefocus
#include “stm32f10x.h”
void RCC_Configuration(void);//2
void GPIO_Configuration(void);//GPIO
void Delay(u32 count)
{
u32 i=0;
for(;i int main(void) { RCC_Configuration();//3 LED_Init(); while(1) { GPIO_SetBits(GPIOA,GPIO_Pin_0);//第一灯亮 Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_0); //第一灯灭 Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_1); //第二灯亮 Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_1); //第二灯灭 Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_2); //第三灯亮 Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_2); //第三灯灭 Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_3); //第四灯亮 Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_3); //第四灯灭 Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_4);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_4); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_5);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_5); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_6);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_6); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_7);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_7); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_8);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_8); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_9);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_9); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_10);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_10); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_11);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_11); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_12);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_12); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_13);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_13); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_14);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_14); // Delay(800000); //延时 GPIO_SetBits(GPIOA,GPIO_Pin_15);// Delay(800000); //延时 GPIO_ResetBits(GPIOA,GPIO_Pin_15); // Delay(800000); //延时 } } void LED_Init(void)//GPIO { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; //结构体 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); } void RCC_Configuration(void) //1 { ErrorStatus HSEStartUpStatus; RCC_DeInit(); RCC_HSEConfig(RCC_HSE_ON); HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { RCC_HCLKConfig(RCC_SYSCLK_Div1); RCC_PCLK2Config(RCC_HCLK_Div1); RCC_PCLK1Config(RCC_HCLK_Div2); FLASH_SetLatency(FLASH_Latency_2); FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); RCC_PLLCmd(ENABLE); while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); while(RCC_GetSYSCLKSource() != 0x08); } } 流水灯还有几中实现方法如 用函数GPIO_Write 位置1 再左移 实现流水灯
史海拾趣
|
请进我的博客日志看:https://home.eeworld.com.cn/index.php?uid-77246-action-viewspace-itemid-13210… 查看全部问答> |
|
ASSERT()是一个调试程序时经常使用的宏,在程序运行时它计算括号内的表达式,如果表达式为FALSE (0), 程序将报告错误,并终止执行。如果表达式不为0,则继续执行后面的语句。这个宏通常原来判断程序中是否出现了明显非法的数据,如果出现了终止程序 ...… 查看全部问答> |
|
2012年中国国际社会公共安全产品博览会 展会场馆:北京顺义天竺裕祥路88号中国国际展览中心(新馆)举办时间:2012年12月3日~2012年12月6日 2012国际车联网大会展会场馆:北京国家会议中心举办时间:2012年12月12日~12月16日 2012 安捷 ...… 查看全部问答> |
|
位移傳感器又稱爲線性傳感器,它分爲電感式位移傳感器,電容式位移傳感器,光電式位移傳感器,超聲波式位移傳感器,霍爾式位移傳感器。 電感式位移傳感器是一種屬于金屬感應的線性器件,接通電源後,在開關的感應面将産生一個交變磁場,當金屬物體 ...… 查看全部问答> |




