4X4按键和数码管
文章目录
一、8位数码管从左至右显示数字1-8
实验仿真图:
控制数码管片选的是3-8译码器74HC138
该芯片数据如下
代码如下(示例):
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit L1=P1^0; //位定义 定义矩阵键盘的四条列线
sbit L2=P1^1;
sbit L3=P1^2;
sbit L4=P1^3;
uchar code dis_code[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共阴数码管0-F
//{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88};//共阳数码管0-9
void delay(uint t)
{
uchar i;
while(t--) for(i=0;i<200;i++);
}
void main()
{
uchar i,temp=0xfc,j=0x7f;//fc 1111 1100 7f 0111 1111
while(1)
{
for(i=1;i<