四、 實驗總結:
雖然這次的上級實驗不難,但是還有點小問題,中間有一些的代碼出現了一些錯誤,還是課本上的一些沒有記清楚,導致寫的時候出現了好幾個錯誤,由此可知還是看書看的太少,以后得多看看書,然后多做一些實驗練習練習。
二、程序設計流程圖
單片機源程序如下:
- #include<reg51.H>
- sbit P3_2=P3^2;
- sbit P3_3=P3^3;
- unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共陰LED段碼表
- unsigned char count=0;
- void delay(unsigned int time){//延遲函數
- unsigned int j=0;
- for(;time>0;time--)
- for(j=0;j<125;j--);
- }
- void main(void){
- count=0;
- P1=table[count/10];
- P2=table[count%10];
- while(1){
- if(P3_2==0){
- delay(10);
- if(P3_2==0){
- count++;
- if(count==100)
- count=0;//滿一百歸零
- P1=table[count/10];
- P2=table[count%10];
- while(P3_2==0);
- }
- }
- if(P3_3==0){
- delay(10);
- if(P3_3==0){
- count--;
- if(count==-1)
- count=99;
- P1=table[count/10];
- P2=table[count%10];
- while(P3_3==0);
- }
- }
- }
- }
復制代碼
所有資料51hei提供下載:
LED數碼顯示.docx
(73.18 KB, 下載次數: 9)
2018-4-11 20:33 上傳
點擊文件名下載附件
|