给你修改好了,你试试。
频率表+仿真.zip
(60.32 KB, 下载次数: 6)
- #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();
- }
复制代码
|