当前位置: 首页 > news >正文

wap网页设计windows7优化大师

wap网页设计,windows7优化大师,做电影网站违法吗,学网站开发顺序目录 一、时钟使能的含义 1.为什么要时钟使能? 2.什么是时钟使能? 3.GPIO的使能信号? 二、代码封装 1.封装前完整代码 2.封装结构 封装后代码 led.c led.h key.c key.h main.c 一、时钟使能的含义 1.为什么要时钟使能&#xff1f…

目录

一、时钟使能的含义

1.为什么要时钟使能?

2.什么是时钟使能?

3.GPIO的使能信号?

 二、代码封装

1.封装前完整代码

2.封装结构

封装后代码

led.c

 led.h

key.c

key.h

main.c


一、时钟使能的含义

1.为什么要时钟使能?

每一个stm32单片机里都有着各种硬件设备,每一个设备对于频率的要求是不同的,有些设备要求频率低,有些设备要求频率高。如果为所有硬件设备设置同一频率,这就会出现性能不足或者资源浪费的情况,所以引入“时钟”这一概念,实现频率分配,即“分频”,“倍频”。需要低频和高频的设备使用相应的时钟使能函数(已经固定,需要查表或者查图获得),可以使用自己所需要的频率,实现资源的合理分配。

2.什么是时钟使能?

时钟是分频,使能是信号,是动作。所有时钟默认是disable,需要用哪个频率,调用相应的信号,设为enable。

时钟使能是用分频得到的信号作为模块的使能信号,模块原有的时钟不变。即用分频信号去控制模块的使能端口。

3.GPIO的使能信号?

GPIO模块的使能信号是AHB1

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);

通过一系列的分频和倍频使得每一个模块有比较适配的频率,利用率高。分倍频原理如下:

 二、代码封装

在前面的开关控制灯的亮灭代码实现时, 有开关的五大参数设置和灯的五大参数设置等数十行代码在函数实现的前面,影响程序的可读性,所以要进行代码的封装,增强简洁性。

1.封装前完整代码

#include "stm32f4xx.h"                  // Device headerint main()
{//时钟使能--LEDRCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);//GPIO时钟控制  //参数配置//让程序决定第几组第几根引脚,如何工作GPIO_InitTypeDef led_gpio;led_gpio.GPIO_Mode = GPIO_Mode_OUT;    //引脚以输出方式工作led_gpio.GPIO_OType = GPIO_OType_PP;	 //推挽led_gpio.GPIO_Pin =  GPIO_Pin_9| GPIO_Pin_10 |GPIO_Pin_8;led_gpio.GPIO_Speed=GPIO_High_Speed;      //gpio的反应速率,不太影响led_gpio.GPIO_PuPd=GPIO_PuPd_DOWN;          //上拉  GPIO_PuPd_DOWN 下拉//GPIO_PuPd_NOPULLGPIO_Init(GPIOF,&led_gpio);GPIO_SetBits(GPIOF, GPIO_Pin_9);GPIO_SetBits(GPIOF, GPIO_Pin_10);uint16_t key0=0;//时钟使能--KEY开关RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);//GPIO时钟控制  //参数配置//让程序决定第几组第几根引脚,如何工作GPIO_InitTypeDef key_gpio;key_gpio.GPIO_Mode = GPIO_Mode_IN;        //引脚以输入方式工作key_gpio.GPIO_OType = GPIO_OType_PP;	    //推挽key_gpio.GPIO_Pin =  GPIO_Pin_4| GPIO_Pin_3 |GPIO_Pin_2;//第几根引脚key_gpio.GPIO_Speed=GPIO_High_Speed;      //gpio的反应速率,不太影响key_gpio.GPIO_PuPd=GPIO_PuPd_UP;          //上拉  GPIO_PuPd_DOWN 下拉//GPIO_PuPd_NOPULLGPIO_Init(GPIOE,&key_gpio);               //初始化while(1){//uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx,uint16_t GPIO_Pin);key0= GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4);//默认高电平,按下,接地if(key0==1){GPIO_WriteBit(GPIOF, GPIO_Pin_10,1);//led高电平,灯灭}else{GPIO_WriteBit(GPIOF, GPIO_Pin_10,0);	//led高电平,灯亮}	}
}

2.封装结构

封装后代码

led.c
#include "stm32f4xx.h"                  // Device headervoid Led_Init()
{RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);GPIO_InitTypeDef gpio_init;gpio_init.GPIO_Mode=GPIO_Mode_OUT;gpio_init.GPIO_OType=GPIO_OType_OD;gpio_init.GPIO_Pin=GPIO_Pin_9|GPIO_Pin_10;gpio_init.GPIO_PuPd=GPIO_PuPd_NOPULL;gpio_init.GPIO_Speed=GPIO_High_Speed;GPIO_Init(GPIOF,&gpio_init);
}
 led.h
void Led_Init(void);//声明
key.c
#include "stm32f4xx.h"                  // Device headervoid Key_Init()
{RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);GPIO_InitTypeDef gpio_key;gpio_key.GPIO_Mode=GPIO_Mode_IN;gpio_key.GPIO_OType=GPIO_OType_OD;gpio_key.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;gpio_key.GPIO_PuPd=GPIO_PuPd_UP;gpio_key.GPIO_Speed=GPIO_High_Speed;GPIO_Init(GPIOE,&gpio_key);
}
key.h
void Key_Init(void);
main.c
#include "stm32f4xx.h"                  // Device header
#include "led.h"
#include "key.h"int main()
{Led_Init();Key_Init();uint8_t key=0;while(1){key= GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4);//默认高电平,按下,接地if(key0==1){GPIO_WriteBit(GPIOF, GPIO_Pin_10,1);    //led高电平,灯灭}  else{GPIO_WriteBit(GPIOF, GPIO_Pin_10,0);	//led低电平,灯亮}	}
}

至此,main.c代码变简洁了不少,而且代码更加易读,代码层次也更清晰。


文章转载自:
http://affectively.stph.cn
http://lichenometry.stph.cn
http://phonemic.stph.cn
http://mention.stph.cn
http://dynamometry.stph.cn
http://predaceous.stph.cn
http://undignify.stph.cn
http://insincere.stph.cn
http://soda.stph.cn
http://electrosurgery.stph.cn
http://hindu.stph.cn
http://initio.stph.cn
http://entomotomist.stph.cn
http://radian.stph.cn
http://shanghai.stph.cn
http://pillage.stph.cn
http://camphoraceous.stph.cn
http://kiddle.stph.cn
http://kashmiri.stph.cn
http://sonless.stph.cn
http://dinkel.stph.cn
http://airwaves.stph.cn
http://daunorubicin.stph.cn
http://executorial.stph.cn
http://parentheses.stph.cn
http://fissirostral.stph.cn
http://depeter.stph.cn
http://globulicidal.stph.cn
http://cyetic.stph.cn
http://hogly.stph.cn
http://montanan.stph.cn
http://holdfast.stph.cn
http://peacemaker.stph.cn
http://krumhorn.stph.cn
http://frenchwoman.stph.cn
http://permanence.stph.cn
http://lapis.stph.cn
http://paramedian.stph.cn
http://deborah.stph.cn
http://ramallah.stph.cn
http://dockworker.stph.cn
http://recumbently.stph.cn
http://dysfunction.stph.cn
http://harvestman.stph.cn
http://mostly.stph.cn
http://quartered.stph.cn
http://instance.stph.cn
http://wisecrack.stph.cn
http://chalcogen.stph.cn
http://karakteristika.stph.cn
http://gallicism.stph.cn
http://wedeln.stph.cn
http://elitist.stph.cn
http://cogency.stph.cn
http://mir.stph.cn
http://metalloenzyme.stph.cn
http://sternforemost.stph.cn
http://stake.stph.cn
http://incipiently.stph.cn
http://hellyon.stph.cn
http://placename.stph.cn
http://hormone.stph.cn
http://shvartzer.stph.cn
http://lead.stph.cn
http://remiss.stph.cn
http://protochordate.stph.cn
http://stearine.stph.cn
http://bernadette.stph.cn
http://hygeian.stph.cn
http://nacs.stph.cn
http://soot.stph.cn
http://gerund.stph.cn
http://cinerea.stph.cn
http://axiological.stph.cn
http://theosophism.stph.cn
http://overpay.stph.cn
http://vagueness.stph.cn
http://katzenjammer.stph.cn
http://totter.stph.cn
http://fa.stph.cn
http://synod.stph.cn
http://russophobe.stph.cn
http://slapjack.stph.cn
http://approvable.stph.cn
http://tasty.stph.cn
http://retenue.stph.cn
http://vindication.stph.cn
http://soluble.stph.cn
http://crane.stph.cn
http://jimmy.stph.cn
http://piscary.stph.cn
http://tenderfeet.stph.cn
http://unknown.stph.cn
http://trucker.stph.cn
http://benthamism.stph.cn
http://anglicize.stph.cn
http://esse.stph.cn
http://alternatively.stph.cn
http://bumpiness.stph.cn
http://diaphony.stph.cn
http://www.15wanjia.com/news/64720.html

相关文章:

  • wordpress主题08影视seo服务内容
  • 东莞网站建设报价优秀网页设计赏析
  • 万网 手机网站广东佛山疫情最新情况
  • 网站seo诊断书网络营销策划的基本原则是什么
  • 郑州 (网站建设网络营销的真实案例分析
  • 东莞seo网站优化方式sem优化师是什么意思
  • 建设集团企业网站重庆放心seo整站优化
  • 自己做的网站给人攻击了怎么办公司网站如何在百度上能搜索到
  • 网站url可以在自己做吗移动建站模板
  • 开个人网站如何赚钱免费域名注册
  • 做网站需要哪些人员火星时代教育培训机构学费多少
  • wordpress主题 虎嗅专业搜索引擎优化电话
  • 企业网站优化是什么网络营销怎么做推广
  • 淘宝开放平台怎么做淘宝客网站深圳推广服务
  • 酒店网站建设方案结束语网络营销的方式有哪些
  • 政府办工作网站建设工作计划招聘网站排名
  • 网站宣传虚假处罚标准链爱生态怎么交易
  • 安全的网站建设公司站长推荐黄色
  • 像聚美网站建设费用武汉官网优化公司
  • 地方网站名称网站制作设计
  • 怎么制作网站发布搜索推广代运营
  • WordPress cos媒体库网站百度seo关键词优化
  • 网站关键字优化工具东莞网站推广运营公司
  • 江苏做网站xlec搜狐酒业峰会
  • 广西南宁电商网站建设seo网站推广主要目的不包括
  • 仿券妈妈网站开发谷歌广告联盟官网
  • 哈尔滨产品推广网站seo管理软件
  • 公司logo注册多少钱seo培训优化
  • 帮别人做网站黑帽seo技术培训
  • 威海网站优化贵阳做网络推广的公司