4*4矩阵键盘控制四位数码管显示单片机C语言程序

4*4矩阵键盘控制四位数码管显示单片机C语言程序,第1张

#include <intrins.h>

#define uchar unsigned char

#define ROWP P3

#define LINP P2

void Delay(uchar i) {

uchar j

for(i>0i--)

for(j=0j<112j++)

_nop_()

}

uchar Keyscan(){

uchar i,j,RLP,num

for(i=0i<4i++){

LINP=(LINP|0xf0)&(~(0x10<<i))

Delay(1)

for(j=0j<团纯仿5j++){

RLP=(ROWP|0x1f)&(~(0x10>>j))

if(ROWP==RLP){

Delay(2)

if(ROWP==RLP)

num=i*5+j+1

}

}

}

return num

}

5*4的,稍裤宏微修塌纤改,就是4*4的

#include<睁族reg51.h>

#define uint unsigned int

#define uchar unsigned char

int i,j

uchar code table[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,

0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}

void keyscan()

void display(uchar num)

void delay(uchar shi)

void main()

{

while(1)

{

keyscan()

}

}

void display(uchar num)

{

P0=table[num]

}

void delay(uchar shi)

{

uint i,j

for(i=shii>棚早键10i--)

for(j=110j>0j--)

}

void keyscan()

{

uchar temp , num

P1=0xfe

temp=P1

temp=temp&0xf0链巧

if(temp!=0xf0)

{

delay(50)

if(temp!=0xf0)

{

switch(temp)

{

case 0x70: num=0

break

case 0xb0: num=1

break

case 0xd0: num=2

break

case 0xe0: num=3

break

}

}

}

P1=0xfd

temp=P1

temp=temp&0xf0

if(temp!=0xf0)

{

delay(50)

if(temp!=0xf0)

{

switch(temp)

{

case 0x70: num=4

break

case 0xb0: num=5

break

case 0xd0: num=6

break

case 0xe0: num=7

break

}

}

}

P1=0xfb

temp=P1

temp=temp&0xf0

if(temp!=0xf0)

{

delay(50)

if(temp!=0xf0)

{

switch(temp)

{

case 0x70: num=8

break

case 0xb0: num=9

break

case 0xd0: num=10

break

case 0xe0: num=11

break

}

}

}

P1=0xf7

temp=P1

temp=temp&0xf0

if(temp!=0xf0)

{

delay(50)

if(temp!=0xf0)

{

switch(temp)

{

case 0x70: num=12

break

case 0xb0: num=13

break

case 0xd0: num=14

break

case 0xe0: num=15

break

}

}

}

display(num)

}这个是1个数码管显示的,你再改改就好


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12513656.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存