|
|
這是我先前編寫的:獨(dú)立按鍵K3,K4,K5:按下K3按鍵LED燈由LED1到LED8流水,按下K4按鍵LED燈由LED8到LED1流水,按下K5按鍵流水停止;
電路原理圖如下:
單片機(jī)源程序如下:
- #include<reg51.h>
- #include<intrins.h>
- typedef unsigned int uint;
- typedef unsigned char uchar;
- sbit k3=P3^5;
- sbit k4=P3^4;
- sbit k5=P3^3;
- uchar count;
- void delays(uint x)
- {
- uint i,j;
- for(i=x;i>0;i--)
- for(j=120;j>0;j--);
- }
- void keypros()
- {
- if(k3==0)
- {
- delays(10);
- if(k3==0)
- {
- while(!k3);
- for(count=0;count<10000;count++)
- {
- P1=_crol_(P1,1);
- delays(200);
- if(k4==0)break;
- if(k5==0)break;
-
- }
- }
- }
- if(k4==0)
- {
- delays(10);
- if(k4==0)
- {
- while(!k4);
- for(count=0;count<10000;count++)
- {
- P1=_cror_(P1,1);
- delays(200);
- if(k3==0)break;
- if(k5==0)break;
-
- }
- }
- }
- }
- void main()
- {
- P1=0xfe;
- while(1)
- {
- keypros();
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
實(shí)驗(yàn)二.zip
(7.04 KB, 下載次數(shù): 22)
2018-6-9 19:22 上傳
點(diǎn)擊文件名下載附件
實(shí)驗(yàn)程序
|
評(píng)分
-
查看全部評(píng)分
|