|
是用51hei單片機開發板 電路圖詳見:http://www.zg4o1577.cn/f/51hei-5.pdf 的數碼管部分, 用2個74hc573 鎖存,p0口作為數據口 ,注意圖中要改一下p3.6和p3.7分別是段和位的鎖存端口.P2口上面是按鍵- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- //======================
- uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar code ACT[4]={0xfe,0xfd,0xfb,0xf7};
- sbit D=P3^6;
- sbit V=P3^7;
- uint counter;
- //===========
- void initial(void)
- {
- TMOD=0x50;
- TH1=0x00;
- TL1=0x00;
- IE=0x00;
- TR1=1;
- }
- //===============
- void delay(uint k)
- {
- uint data i,j;
- for(i=0;i<k;i++){
- for(j=0;j<121;j++)
- {;}}
- }
- //=================
- void display(void)
- {
- D=1;P0=SEG7[counter/1000];D=0;P0=0xff;V=1;P0=ACT[0];V=0;delay(2);
- D=1;P0=SEG7[(counter/100)%10];D=0;P0=0xff;V=1;P0=ACT[1];V=0;delay(2);
- D=1;P0=SEG7[(counter%100)/10];D=0;P0=0xff;V=1;P0=ACT[2];V=0;delay(2);
- D=1;P0=SEG7[counter%10];D=0;P0=0xff;V=1;P0=ACT[3];V=0;delay(2);
- }
- //===============
- void main(void)
- {uint temp1,temp2;
- initial();
- for(;;)
- {
- display();
- temp1=TL1;temp2=TH1;
- counter=(temp2<<8)+temp1;
- }
- }
復制代碼
|
|