課程設計實驗報告 一、題目: 籃球記分器 STC89C52 12M晶振 四位一體數碼管 兩位數碼管2個 4.7K歐排阻2個 極性電容 電容22pF 電阻10K歐 開關8個 導線若干 1.12分鐘倒計時 - 分別給A、B隊加1、2、3分并顯示
- 換場A、B兩隊分數交換
- 暫停
初始化定時器T0,并開啟T0中斷,十二分鐘倒計時開始工作,每隔20uS數碼管顯示分、秒,循環檢查各開關是否按下并做相應處理。判斷是aa還是bb按下,再按one則給相應的隊加一分,按two加兩分,按three加三分;如果exchange按下,則交換AB兩隊分數;如果stop按下,則暫停工作。 六、體會 通過這次設計制作,進一步了解到單片機最小系統和工作原理,掌握了定時器和數碼管的使用。真心體會到數碼管的引腳連線是個復雜的過程,第一次連接好后由于線接的太亂,有斷開和連上的地方,沒有成功,第二次重新規整了連線,終于使單片機正常工作了。
- #include<reg51.h>
- unsigned char code seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x00,0x90 };
- int i=11,j=59,a=0,b=0,m=0,n=0,temp,s=0,r=24,k;
- sbit aa=P0^0;
- sbit bb=P0^1;
- sbit one=P0^2;
- sbit two=P0^3;
- sbit three=P0^4;
- sbit exchange=P0^5;
- sbit stop=P0^6;
- sbit led=P3^6;
- sbit tt=P3^7;
-
- void delay(int x)
- {
- int w,q;
- for(w=0;w<x;w++)
- for(q=0;q<120;q++);
- }
-
- void display(int i,int j,int a,int b)
- {
- P2 = 0x01;
- P1 = seg[i/10];
- delay(1);
- P2 = 0x00;
-
- P2 = 0x02;
- P1 = seg[i%10];
- delay(1);
- P2 = 0x00;
-
- P2 = 0x04;
- P1 = seg[j/10];
- delay(1);
- P2 = 0x00;
-
-
- P2 = 0x08;
- P1 = seg[j%10];
- delay(1);
- P2 = 0x00;
-
-
- P2= 0x10;
- P1 = seg[a/10];
- delay(1);
- P2= 0x00;
-
- P2= 0x20;
- P1 = seg[a%10];
- delay(1);
- P2 = 0x00;
-
-
- P2 = 0x40;
- P1 = seg[b/10];
- delay(1);
- P2 = 0x00;
-
-
- P2= 0x80;
- P1 = seg[b%10];
- delay(1);
- P2 = 0x00;
-
- }
-
- void time0() interrupt 1
- {
- TH0 = 0xb1;
- TL0 = 0xe0;
- m++;
- if(m==50)
- {
- m=0;
- j--;
- if(j==-1)
- j = 59;
- n++;
- if(n==60)
- {
- n=0;
- i--;
- if(i==0&&j==0){
- ET0=1;
- TR0 = 1;
- }
- }
- }
- display(i,j,a,b);
- }
-
-
- void main()
- {
- P0 = 0x00;
- display(12,0,0,0);
- TMOD = 0x01;
- TH0 = 0xb1;
- TL0 = 0xe0;
- IE = 0x82;
- TR0 = 1;
- while(1)
- {
- if(aa==1&&one==1)
- {a++;display( i, j, a, b);while(one==1);}
- else if(aa==1&&two==1)
- { a=a+2;display( i, j, a, b);while(two==1);}
- else if(aa==1&&three==1)
- {a=a+3;display( i, j, a, b);while(three==1);}
- else if(bb==1&&one==1)
- {b++;display( i, j, a, b);while(one==1);}
- else if(bb==1&&two==1)
- { b=b+2;display( i, j, a, b);while(two==1);}
- else if(bb==1&&three==1)
- { b=b+3;display( i, j, a, b);while(three==1);}
- else if(exchange==1)
- {temp = a;a = b;b = temp;delay(500);}
- else if(stop==1) {ET0=0;TR0=0;while(stop==1);while(stop==0);while(stop==1){ET0=1;TR0=1;}}
- }
- }
復制代碼
完整的Word格式文檔51黑下載地址:
|