独立键盘
#include <reg52.h>
sbit LED = P0^0;
sbit KEY = P1^0;
void main()
{
while(1)
{
if(0 == KEY)
{
LED = 0;
}
else
{
LED = 1;
}
}
}
矩阵键盘
#include <reg52.h>
#include "delay.h"
#define SEGPORT P0
#define KEYPORT P3
sbit wei_select = P1^0;
sbit duan_select = P1^1;
unsigned char segport[2] = {0xfe,0xfd};
unsigned char segdata[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char TempData[2];
void display_seg()
{
static unsigned char i = 0;
SEGPORT = 0xff;
wei_select = 1;
wei_select = 0;
SEGPORT = 0x0;
duan_select = 1;
duan_select = 0;
SEGPORT = segport[i];
wei_select = 1;
wei_select = 0;
SEGPORT = TempData[i];
duan_select = 1;
duan_select = 0;
i++;
if(2 == i)

本文介绍了如何使用单片机进行独立键盘和矩阵键盘的编程,包括显示部分的实现和按键扫描算法,同时展示了针对LCD显示屏的初始化及字符显示操作。
最低0.47元/天 解锁文章
741

被折叠的 条评论
为什么被折叠?



