標(biāo)題: 單片機(jī)按鍵顯示流水燈源碼與實(shí)驗(yàn)報(bào)告 [打印本頁(yè)]
作者: 焦凱 時(shí)間: 2018-4-11 20:05
標(biāo)題: 單片機(jī)按鍵顯示流水燈源碼與實(shí)驗(yàn)報(bào)告
流水燈仿真圖:
實(shí)驗(yàn)感悟:
- 用proteus仿真時(shí)候,發(fā)現(xiàn)錯(cuò)誤:
error variable not found parsing property resistance of RN1-Rnvalue expected for RN1-R(n=1~8)而且led燈亮度十分微弱。可能是接入的電阻太大了。
檢查電路圖發(fā)現(xiàn)排阻的值為RX8,修改為220(自己選擇)后。錯(cuò)誤便沒有了,同時(shí),led燈的亮度也增強(qiáng)了。
延時(shí)的時(shí)間計(jì)算不太明白。
3、P0=0xfe;是對(duì)單片機(jī)P0口的8個(gè)I/O口同時(shí)進(jìn)行操作,0x后的數(shù)使用十六進(jìn)制表示,fe轉(zhuǎn)換為二進(jìn)制是1111 1110,則P0.0為低電平,對(duì)應(yīng)的led燈亮,其他7個(gè)led燈滅。
單片機(jī)流水燈源程序如下:
- 源程序:
- #include<reg52.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit key1=P3^7;
- sbit key2=P3^6;
- sbit key3=P3^5;
- unsigned int time=2000,count1=0;
- unsigned int led=0xfe,count2=0;
- void key();
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void dump()
- {
- if(count1==0)
- {
- P1=led;
- led=_crol_(led,1);
-
- }
- if(count1==1)
- {
- led=_cror_(led,1);
- P1=led;
- }
- }
- void main()
- {
- while(1)
- {
- key();
- delay(time/5);
- key();
- delay(time/5);
- key();
- delay(time/5);
- dump();
- key();
- delay(time/5);
- key();
- delay(time/5);
- }
- }
- void key()
- {
- if(key1==0)
- {
- delay(5);
- if(key1==0)
- {
- count2++;
- if(count2%2==1)
- {
- count1=1;
- }
- if(count2%2==0)
- {
- count1=0;
- }
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(5);
- if(key2==0)
- {
- if(time==4000);
- else
- {
- time+=500;
- }
- while(!key2);
- }
- }
- if(key3==0)
- {
- delay(5);
- if(key3==0);
- {
- if(time==500);
- else
- {
- time-=500;
- }
- while(!key3);
- }
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
第一次試驗(yàn)報(bào)告B16040415焦凱.docx
(171.99 KB, 下載次數(shù): 15)
2018-4-11 20:01 上傳
點(diǎn)擊文件名下載附件
按鍵顯示
下載積分: 黑幣 -5
| 歡迎光臨 (http://m.raoushi.com/bbs/) |
Powered by Discuz! X3.1 |