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

网站 keywords seo企业解决方案的步骤

网站 keywords seo,企业解决方案的步骤,怎么创建公众号微信,聊城做网站推广地方一、按键与传感器: 1.介绍: 按键:按下连通,松手断开。 注意:按下按键时会有5-10ms的晃动,延时一下再判断就好,故下面代码delay_ms(20)。 传感器:。 2.使用原理: 将…

 一、按键与传感器:

1.介绍:

按键:按下连通,松手断开。

注意:按下按键时会有5-10ms的晃动,延时一下再判断就好,故下面代码delay_ms(20)。

传感器:

2.使用原理:

将引脚配置为上拉输入(默认为1)模式,当按键按下,输入为0,按键抬起,输入为1。

3.接线图:

4.GPIO读取函数:

uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);

5.组合代码:

注:先看下面代码封装,再回来看这里。

#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "LED.h"
#include "Key.h"uint8_t KeyNum;int main(void)
{LED_Init();Key_Init();while (1){KeyNum = Key_GetNum();if (KeyNum == 1){LED1_Turn();}if (KeyNum == 2){LED2_Turn();}}
}

二、封装常用函数:

使用哪个引脚,就要修改下面代码中的GPIOx与GPIO_Pin_x。

1.LED.c

(1)LED初始化函数:
void LED_Init(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_SetBits(GPIOA, GPIO_Pin_1 | GPIO_Pin_2);
}
(2)LED开关函数:
void LED1_ON(void)
{GPIO_ResetBits(GPIOA, GPIO_Pin_1);
}void LED1_OFF(void)
{GPIO_SetBits(GPIOA, GPIO_Pin_1);
}
(3)LED翻转函数:
void LED2_Turn(void)
{if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_2) == 0){GPIO_SetBits(GPIOA, GPIO_Pin_2);}else{GPIO_ResetBits(GPIOA, GPIO_Pin_2);}
}

2.Buzzer.c

void Buzzer_Init(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOB, &GPIO_InitStructure);GPIO_SetBits(GPIOB, GPIO_Pin_12);
}void Buzzer_ON(void)
{GPIO_ResetBits(GPIOB, GPIO_Pin_12);
}void Buzzer_OFF(void)
{GPIO_SetBits(GPIOB, GPIO_Pin_12);
}void Buzzer_Turn(void)
{if (GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_12) == 0){GPIO_SetBits(GPIOB, GPIO_Pin_12);}else{GPIO_ResetBits(GPIOB, GPIO_Pin_12);}
}

3.Key.c

(1)按键初始化函数:
void Key_Init(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_11;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOB, &GPIO_InitStructure);
}
(2)获取按键信息函数:

调用此函数时,返回按下的按键编号,未抬起时在此函数中循环,抬起返回。

uint8_t Key_GetNum(void)
{uint8_t KeyNum = 0;if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 0){Delay_ms(20);while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 0);Delay_ms(20);KeyNum = 1;}if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0){Delay_ms(20);while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0);Delay_ms(20);KeyNum = 2;}return KeyNum;
}

4.LightSensor.c

void LightSensor_Init(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOB, &GPIO_InitStructure);
}uint8_t LightSensor_Get(void)
{return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13);
}

http://www.dtcms.com/wzjs/836408.html

相关文章:

  • 韩国网站加速器网站开发部门工资会计分录
  • wordpress好用的会员seo竞价培训
  • 网站的二级目录怎么做城网站建设
  • 宁波微网站开发室内设计知名网站
  • 网站优化怎么做分录广州软件开发培训班
  • dede的网站地图深圳市出行政策最新
  • 英文网站接单做翻译memory wordpress
  • 3000ok新开传奇网站手机网页视频如何下载
  • 襄阳网站建设营销做自己头像的网站
  • 医药网站建设客户的需求河南网站建设平台
  • 设计公司的名字福州网站设计十年乐云seo
  • 免费ppt模板 网站开发老河口网页定制
  • 房产网站建设接单门户网站ip地址段
  • 企业网站颜色市场营销在线课程
  • 济南网站建设方案ip反查工具网站
  • 个人做购物网站犯法吗c 做网站时字体颜色的代码
  • 群晖做网站域名网站优化计划书
  • 用dw做电子商务网站步骤做网站后台用什么语言好
  • SEO网站公司wordpress网站维护
  • 淄博手机网站建设费用免费ppt模板 网站开发
  • 网站修改dns传媒公司总裁
  • 一款教育培训咨询有限公司网站源码陕西省网页制作
  • 温州网站建设策划方案happytug wordpress
  • 外贸营销型网站建设公司娄底市建设网站
  • pc网站生成手机网站传媒公司创业
  • 网站如何添加外链python可以做网站前端
  • 河北省承德市建设局网站上不去石家庄网页制作招聘信息
  • 一个专门做视频配音的网站在统计局网站上如何做图表
  • 网站注意事项怎么做个人网站建设
  • 网站图标怎么下载单位建设网站用交印花税吗