一種基于51單片機的獨立式鍵盤應用,通過一個共陽led顯示屏和8個led燈顯示
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機源程序如下:
- #include<reg51.h>
- #define uchar unsigned char;
- #define uint unsigned int;
- uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80};
- uchar code ledtable[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- uchar i,j,z,temp,num;
-
- void delay(z)
- {
- for(j=z;j>0;j--)
- for(i=110;i>0;i--);
- }
-
- void main()
- {
- P0=0x00;
- P1=0xff;
-
- while(1)
- {
- temp=P1;
- temp=temp&0xff;
- while(temp!=0xff)
- {
- delay(5);
- temp=P1;
- temp=temp&0xff;
- while(temp!=0xff)
- {
- temp=P1;
- switch(temp)
- {
- case 0xfe:num=0;break;
- case 0xfd:num=1;break;
- case 0xfb:num=2;break;
- case 0xf7:num=3;break;
- case 0xef:num=4;break;
- case 0xdf:num=5;break;
- case 0xbf:num=6;break;
- case 0x7f:num=7;break;
- default:break;
- }
- while(temp!=0xff)
- {
- temp=P1;
- temp=temp&0xff;
-
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
獨立式按鍵led顯示.zip
(218.2 KB, 下載次數: 21)
2018-4-20 15:49 上傳
點擊文件名下載附件
|