給你修改好了,你試試。
無標題.jpg (168.34 KB, 下載次數: 35)
下載附件
2019-4-17 15:29 上傳
頻率表+仿真.zip
(60.32 KB, 下載次數: 6)
2019-4-17 15:32 上傳
點擊文件名下載附件
- #include<reg51.h>
- #include<intrins.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- uchar code DSY_CODE[]={//共陽數碼管段碼"0~f-."
- 0xc0,0xf9,0xa4,0xb0,
- 0x99,0x92,0x82,0xf8,
- 0x80,0x90,0x88,0x83,
- 0xc6,0xa1,0x86,0x8e,0xbf,0x7f};
- uchar code wei[]={0x01,0x02,0x04,0x08};
- uchar buf[4];//緩存
- uint bb=0;
- uint count=0;
- bit sign=0;
- void xianshi()
- {
- static uchar i=0,j=0; //計數變量
- if(++j>=8)
- {
- j=0;
- P0=0xff; //消隱
- switch(i)
- {
- case 0: P2=wei[i];P0=DSY_CODE[buf[3]];i++;break;
- case 1: P2=wei[i];P0=DSY_CODE[buf[2]];i++;break;
- case 2: P2=wei[i];P0=DSY_CODE[buf[1]];i++;break;
- case 3: P2=wei[i];P0=DSY_CODE[buf[0]];i=0;break;
- }
- }
- }
- void main()
- {
- uchar j;
- TMOD= 0x52; //設置定時器模式
- TL0 = 0x06; //設置定時初值,晶振12MHz
- TH0 = 0x06; //設置定時重載值
- TH1=0x00;
- TL1=0x00;
- TR0=1;
- TR1=1;
- EA=1;
- ET0=1;
- while(1)
- {
- if(sign==1)
- {
- sign=0;
- for(j=0;j<4;j++)//分解數據
- {
- buf[j]=count%10;//按位保存
- count/=10;
- }
- }
- }
- }
- void zhongduan1() interrupt 1
- {
- bb++;
- if(bb==4000)
- {
- bb=0;
- sign=1;
- count=TH1;
- count=(count<<8)+TL1;
- TH1=0;
- TL1=0;
- }
- xianshi();
- }
復制代碼
|