所有资料51hei提供下载:
频率计.zip
(51.2 KB, 下载次数: 12)
单片机源程序如下:
- #include <STC15F2K60S2.H>
- #include <intrins.h>
- #include "anjian.h"
- sbit a=P2^5;
- sbit b=P2^6;
- sbit c=P2^7;
- sbit beep=P0^6;
- sbit pk=P3^4;
- unsigned char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x90,0xbf,0xff};
- unsigned int disp[8]={10,10,10,10,10,10,10,10};
- unsigned char key_scan();
- extern unsigned char key_value;
- unsigned int zhuoqi=0;
- unsigned int pl1=0;
- unsigned char over_flag=0;
- unsigned int f,t;
- void Timer0init();
- void Timer1init();
- void Delay300us();
- void zhouqidisplay();
- void Pldisplay();
- void Display();
- void zongdisp();
-
- void Bee()
- {
- a=1;b=0;c=1;
- beep=0;
- }
- void main()
- {
- Bee();
- Delay300us();
- Timer0init();
- Timer1init();
- EA=1;
- TR0=1;
- TR1=1;
- while(1)
- {
- if(over_flag)
- {
- ET0=1;
- TR0=1;
- TR1=1;
- over_flag=0;
- f=pl1*10;
- pl1=0;
- }
- Pldisplay();
- Display();
- P2=(P2&0x1f)|0xe0;
- P0=0xff;
- P2=(P2&0x1f)|0xc0;
- P0=0xff;
- key_scan();
- if(key_value==2) //f
- {
- while(1)
- {
- t=1000000/f;
- zhouqidisplay();
- Display();
- P2=(P2&0x1f)|0xe0;
- P0=0xff;
- P2=(P2&0x1f)|0xc0;
- P0=0xff;
- key_scan();
- if(key_value!=0)
- break;
- }
- }
- }
- }
- void Timer0init()
- {
- AUXR = 0x80;
- TMOD=0x04;
- TL0=0xff;
- TH0=0xff;
- ET0=1;
- TR0=1;
- }
- void Timer1init()
- {
- AUXR &= 0xBF; //定时器时钟12T模式
- TMOD &= 0x0F; //设置定时器模式
- TL1 = 0x00; //设置定时初值
- TH1 = 0x4C; //设置定时初值
- TF1 = 0; //清除TF1标志
- TR1 = 0; //定时器1开始计时
- ET1 = 1;
- }
- void Timer0_init() interrupt 1
- {
-
- pl1++;
- //TF0 = 0;
- }
- bit t1=0;
- void Timer1_init() interrupt 3
- {
- if(t1==0)
- t1=1;
- else
- {
- t1=0;
- ET0=0;
- TR0=0;
- TR1=0;
- over_flag=1;
- }
- }
- void Display()
- {
- unsigned char i;
- for(i=0;i<8;i++)
- {
- P2=(P2&0x1f)|0xe0;
- P0=0xff;
- P2&=0x1f;
- _nop_();
- P2=(P2&0x1f)|0xc0;
- P0=0x01<<i;
- P2&=0x1f;
- _nop_();
- P2=(P2&0x1f)|0xe0;
- P0=disp[i];
- P2&=0x1f;
- P0=0Xff;
- Delay300us();
- }
- }
- void Delay300us()
- {
- unsigned char i,j;
- _nop_();
- _nop_();
- i=4;
- j=54;
- do
- {
- while(--j);
- } while(--i);
- }
- void Pldisplay()
- {
- disp[0]=table[12];
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
|