历史上的今天
今天是:2025年04月09日(星期三)
2019年04月09日 | STM32实战 2.矩阵键盘通过串口3输出
2019-04-09 来源:eefocus
#include "KEY44.h"
#include "sys.h"
#include "delay.h"
#include "usart.h"
u8 key_num = 0;
int main(void)
{
uart_init(115200);
delay_init();
KEY44_Init();
while(1)
{
key_num = key44_Scan();
if(key_num != 0)
{
printf("KEY is %drn",key_num);
}
}
}
#include "KEY44.h"
#include "sys.h"
#include "delay.h"
void KEY44_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1 |GPIO_Pin_2 |GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5 |GPIO_Pin_6 |GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
unsigned char key44_Scan(void)
{
H_1 = 0;
H_2 = 1;
H_3 = 1;
H_4 = 1;
if( L_1 == 0)
{
delay_ms(10);
if(L_1 == 0)
{
while(!L_1);
return 1;
}
}
if(L_2 == 0)
{
delay_ms(10);
if(L_2 == 0)
{
while(!L_2);
return 2;
}
}
if(L_3 == 0)
{
delay_ms(10);
if(L_3 == 0)
{
while(!L_3);
return 3;
}
}
if(L_4 == 0)
{
delay_ms(10);
if(L_4 == 0)
{
while(!L_4);
return 4;
}
}
H_1 = 1;
H_2 = 0;
H_3 = 1;
H_4 = 1;
if(L_1 == 0)
{
delay_ms(10);
if(L_1 == 0)
{
while(!L_1);
return 5;
}
}
if(L_2 == 0)
{
delay_ms(10);
if(L_2 == 0)
{
while(!L_2);
return 6;
}
}
if(L_3 == 0)
{
delay_ms(10);
if(L_3 == 0)
{
while(!L_3);
return 7;
}
}
if(L_4 == 0)
{
delay_ms(10);
if(L_4 == 0)
{
while(!L_4);
return 8;
}
}
H_1 = 1;
H_2 = 1;
H_3 = 0;
H_4 = 1;
if(L_1 == 0)
{
delay_ms(10);
if(L_1 == 0)
{
while(!L_1);
return 9;
}
}
if(L_2 == 0)
{
delay_ms(10);
if(L_2 == 0)
{
while(!L_2);
return 10;
}
}
if(L_3 == 0)
{
delay_ms(10);
if(L_3 == 0)
{
while(!L_3);
return 11;
}
}
if(L_4 == 0)
{
delay_ms(10);
if(L_4 == 0)
{
while(!L_4);
return 12;
}
}
H_1 = 1;
H_2 = 1;
H_3 = 1;
H_4 = 0;
if(L_1 == 0)
{
delay_ms(10);
if(L_1 == 0)
{
while(!L_1);
return 13;
}
}
if(L_2 == 0)
{
delay_ms(10);
if(L_2 == 0)
{
while(!L_2);
return 14;
}
}
if(L_3 == 0)
{
delay_ms(10);
if(L_3 == 0)
{
while(!L_3);
return 15;
}
}
if(L_4 == 0)
{
delay_ms(10);
if(L_4 == 0)
{
while(!L_4);
return 16;
}
}
return 0;
}
#ifndef __KEY44_H
#define __KEY44_H
//PA0~PA3为推挽式输出
//PA4~PA7为上拉式输入
#define H_1 PAout(0)
#define H_2 PAout(1)
#define H_3 PAout(2)
#define H_4 PAout(3)
#define L_1 PAin(4)
#define L_2 PAin(5)
#define L_3 PAin(6)
#define L_4 PAin(7)
void KEY44_Init(void);
unsigned char key44_Scan(void);
#endif
史海拾趣
|
关键字:红外防水摄像机 现在的普通红外防水摄像机,一般采用光敏元件来探测所处环境的照明强度,根据设计参数中确定的阈值,产生控制信号,实现红外灯的开启。阈值的高低,由使用的环境,用户的喜好,设计人员考虑各 ...… 查看全部问答> |
|
开发平台 :wince 开发环境 :evc++ 4.0,sp4 socket 服务器端 .net 2.0 (c#) 基于gprs 无线网络的远程文件下发和程序升级系统 有意联系 :email : acosoft@163.com… 查看全部问答> |
|
我按照WinCE4.2下通常的方法: 1.将MyApp.exe复制到E:\\PROJECTS\\MyWinCE\\RelDir\\CEPC_X86Release目录下; 2.修改MyWinCE工程的project.bib文件,在FILES Section添加&nbs ...… 查看全部问答> |
|
module test ; reg clk , rst ; reg [7:0] din ; reg en ; wire [7:0] dout ; initial begin clk=0; rst=0; en=0; din=8\'b0; #10; ...… 查看全部问答> |
|
请问一下 FTDI JTAG JLINK 这三者是什么联系啊 我用IAR的时候都是选FTDI 直接连USB就可以 这个FTDI功能是什么啊? 先谢谢好心人的解答… 查看全部问答> |
|
有谁买过淘宝上的NRF24L01+PA+LNA模块并且测试能够达到1000米的啊? 淘宝上好多NRF24L01+PA+LNA的模块号称在250Kbps的速率下,空旷地带能达到1000米的通信距离,我买了两块,卖家给的测试程序都是基于51的,但我只有2440的开发板,于是就根据他的51源程序移植到2440平台上,实际测试的时候到250米左右就丢包非常严重 ...… 查看全部问答> |




