⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 +

📁 STM32的恒温消毒柜设计
💻
字号:
#include "keyboard.h"
#include "stm32f10x.h"
#include "SysTick.h"
void keyboard_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);   //  打开C端口时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);	 //	 打开E端口时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);	   //  打开A端口时钟
//GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;           // PC2和PC3对应独立按键      
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;	 // 上拉输入
 //GPIO_Init(GPIOC, &GPIO_InitStructure);

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;           // PA3对应独立按键      
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;	 // 上拉输入
 GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6;
GPIO_Init(GPIOE,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStructure);
GPIO_SetBits(GPIOE,GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4); 
}

uint8_t key_scan(void)
{
uint16_t temp=0;
uint8_t key=0;
GPIO_ResetBits(GPIOE,GPIO_Pin_2);
temp=(((GPIO_ReadInputData(GPIOE)&0xffef)>>4)|(GPIO_ReadInputData(GPIOC)&0x01))&0x07;
if(temp!=0x07)
{
Delay(10000);
//Delay_us(400);  //延时4ms
temp=(((GPIO_ReadInputData(GPIOE)&0xffef)>>4)|(GPIO_ReadInputData(GPIOC)&0x01))&0x07;
if(temp!=0x07)
{
switch(temp)
{
case 0x05:key=0x01;break;
case 0x03:key=0x02;break;
case 0x06:key=0x03;break;
}
}
}
GPIO_SetBits(GPIOE,GPIO_Pin_2);
GPIO_ResetBits(GPIOE,GPIO_Pin_3);
temp=(((GPIO_ReadInputData(GPIOE)&0xffef)>>4)|(GPIO_ReadInputData(GPIOC)&0x01))&0x07;
if(temp!=0x07)
{
Delay(10000);
//Delay_us(400);  //延时4ms
temp=(((GPIO_ReadInputData(GPIOE)&0xffef)>>4)|(GPIO_ReadInputData(GPIOC)&0x01))&0x07;
if(temp!=0x07)
{
switch(temp)
{
case 0x05:key=0x04;break;
case 0x03:key=0x05;break;
case 0x06:key=0x06;break;
}
}
}
GPIO_SetBits(GPIOE,GPIO_Pin_3);
GPIO_ResetBits(GPIOE,GPIO_Pin_4);
temp=(((GPIO_ReadInputData(GPIOE)&0xffef)>>4)|(GPIO_ReadInputData(GPIOC)&0x01))&0x07;
if(temp!=0x07)
{
Delay(10000);
//Delay_us(400);  //延时4ms
temp=(((GPIO_ReadInputData(GPIOE)&0xffef)>>4)|(GPIO_ReadInputData(GPIOC)&0x01))&0x07;
if(temp!=0x07)
{
switch(temp)
{
case 0x05:key=0x07;break;
case 0x03:key=0x08;break;
case 0x06:key=0x09;break;
}
}
}
GPIO_SetBits(GPIOE,GPIO_Pin_4);
return key;
}
void Delay(__IO u32 nCount)	 //简单的延时函数
{
	for(; nCount != 0; nCount--);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -