登錄
|
立即注冊(cè)
|
使用QQ帳號(hào)登錄
論壇
>
資料共享
發(fā)帖
|
單片機(jī)矩陣鍵盤按鍵LED數(shù)碼管顯示
看3649
|
回0
|
收藏
樓主
ID:259336
只看他
2017-12-9 11:21
代碼:
#include <reg51.h>
#define uchar unsigned char
sbit L1=P1^0; //定義鍵盤的四列線
sbit L2=P1^1;
sbit L3=P1^2;
sbit L4=P1^3;
uchar dis[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; //共陽極數(shù)碼管字符0~F對(duì)應(yīng)段碼
unsigned int time;
delay(time) //延時(shí)子程序
{unsigned int j;
for(j=0;j<time;j++)
{}
}
main()
{
uchar temp;
uchar k,i;
while(1)
{
P1=0xef;
for(i=0;i<=3;i++)
{
if (L1==0) P0=dis [i*4+0];
if (L2==0) P0=dis [i*4+1];
if (L3==0) P0=dis [i*4+2];
if (L4==0) P0=dis [i*4+3];
delay(500);
temp=P1;
temp=temp|0x0f;
temp=temp<<1;
temp=temp|0x0f;
P1=temp;
}
}
}
51黑電子論壇
Powered by
Discuz!
X3.1
首頁
|
標(biāo)準(zhǔn)版
|
觸屏版
|
電腦版