|
1.延時(shí)函數(shù):i==500
2.從一個(gè)LED變到另一個(gè)LED間要添加延時(shí)函數(shù)(間隔要適度),否則變化太快仿佛在抖動(dòng)。
3.key()函數(shù)中添加while(KEY==0); 檢測(cè)按鍵是否彈起,否則按鍵計(jì)數(shù)可能不對(duì)
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機(jī)源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- void delay()
- {
- uchar a,b;
- for(a=500;a;a--)
- {
- for(b=500;b;b--);
- }
- }
- void main()
- {
- unsigned char count=0;
- unsigned char num=0;
- while(1){
- while(((num%3)==0)&&(P2!=0xFE))
- {
- P0=~(0x01<<count);
- delay();
- count++;
- if(count>=8)
- count=0;
- }
- while(((num%3)==1)&&(P2!=0xFE))
- {
- P0=~(0x80>>count);
- delay();
- count++;
- if(count>=8)
- count=0;
- }
- while(((num%3)==2)&&(P2!=0xFE))
- {
- P0=~(0x01<<count);
- delay();
- count=count+2;
- if(count==8){
- count=1;
- }
- if(count==9){
- count=0;
- }
- }
- if(P2==0xFE){
- num=num+1;
- }
- while(P2==0xFE);
- }
- }
復(fù)制代碼
所有資料51hei附件下載:
實(shí)驗(yàn)三.zip
(61.61 KB, 下載次數(shù): 15)
2021-11-10 15:28 上傳
點(diǎn)擊文件名下載附件
|
評(píng)分
-
查看全部評(píng)分
|