51單片機做的k1-k4按鍵控制數碼管加減演示仿真+程序
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載):
0.png (19.26 KB, 下載次數: 122)
下載附件
2017-7-13 01:32 上傳
0.png (53.61 KB, 下載次數: 125)
下載附件
2017-7-13 01:31 上傳
單片機源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code DSY_CODE[]=
- {
- 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff
- };
- uchar Num_Buffer[] = {0,0,0};
- uchar Key_Code,Key_Counts=0;
- void DelayMS(uint x)
- {
- uchar t;
- while(x--)
- {
- for(t=0;t<120;t++);
- }
- }
- void Show_Counts_ON_DSY()
- {
- uchar i,j=0x01;
- Num_Buffer[2]=Key_Counts/100;
- Num_Buffer[1]=Key_Counts/10%10;
- Num_Buffer[0]=Key_Counts%10;
- for(i=0;i<3;i++)
- {
- j = _cror_(j,1);
- P2 = j;
- P0 = DSY_CODE[Num_Buffer[i]];
- DelayMS(1);
- }
- }
- void main()
- {
- uchar i;
- P0 = 0xff;
- P1 = 0xff;
- P2 = 0x00;
- Key_Code = 0xff;
- while(1)
- {
- Show_Counts_ON_DSY();
- P1 = 0xff;
- Key_Code = P1;
- if(Key_Code != 0xff)
- {
- for(i=0;i<30;i++)
- {
- Show_Counts_ON_DSY();
- }
- }
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
K1-K4 控制數碼管加減演示.7z
(22.72 KB, 下載次數: 116)
2021-12-4 18:54 上傳
點擊文件名下載附件
仿真
|