lx911gt 发表于 2013-7-6 11:21 
麻烦能给个程序么?参考一下 - #include<STC12C2052AD.h>
- #include<intrins.h>
- #include<string.h>
- #include<math.h>
- #include<stdio.h>
- #include<stdlib.h>
- #include<absacc.h>
- #define uchar unsigned char
- #define ulong unsigned long
- #define uint unsigned int
- #define _Nop() _nop_() /*定义空指令*/
- void sendbyte(uchar byte);
- void Disp();
- //显示部分
- sbit CLK=P1^0; //定义A串行数据输入端
- sbit DAT=P3^7; //定义A控制端
-
- sbit vol=P1^1; //
- sbit crt=P1^2;
- uchar i=0;
- bit flag=0;
- uchar count; //计数
- ulong pinlv=0,pin=0; //频率——频率缓存
- uchar temp[4]=0; //数据缓存
- uchar DispBuf[4]=0; //4位数据显示
- uchar dis_code[10]={
- 0x03, //"0"
- 0x9F, //"1"
- 0x25, //"2"
- 0x0D, //"3"
- 0x99, //"4"
- 0x49, //"5"
- 0x41, //"6"
- 0x1F, //"7"
- 0x01, //"8"
- 0x09 //"9"
- };
- //延时
- void delay_50ms(unsigned int t)
- {
- unsigned int j;
- for(;t>0;t--)
- for(j=6245;j>0;j--)
- {;}
- }
- void sendbyte(uchar byte)
- {
- uchar num,c;
- num=dis_code[byte];
- for(c=0;c<8;c++)
- {
- CLK=0;
- DAT=num&0x01;
- CLK=1;
- num>>=1;
- }
- }
-
- void time0(void) interrupt 1 //定时器0溢出中断模式2可重装载
- {
- TR0=0; //定时器0暂停
- count++;
- TL0 = 0xB0; //设置定时初值
- TH0 = 0x3C; //设置定时初值
- if(count==1)
- {
- Disp();// LED2=!LED2;
- if(vol==0)
- {
- delay_50ms(10);
- if(vol==0)
- {
- crt=0;
- }
- }
- else crt=1;
- }
- if(count==20)
- {
- TR1=0; //T1计数停止
- count=0;
- TR1=0; //定时器1停止计数
- pinlv=TH1*256+TL1; //计算频率值
- pin=pinlv;
- TH1=0; //计数清零
- TL1=0;
- TR1=1; //开始计数
- }
- TR0=1;
- }
- void Disp()
- {
- pin=pin*0.06;// (pin/1000)*60 1000线
- temp[3]=pin/1000%10; //千位
- temp[2]=pin/100%10; //百位
- temp[1]=pin%100/10; //十位
- temp[0]=pin%10; //个位
- // if(temp[4]>=1)
- // {
- // sendbyte(temp[1]);
- // sendbyte(temp[2]);
- // sendbyte(temp[3]);
- // sendbyte(temp[4]);
- // }
- // else
- sendbyte(temp[0]);
- sendbyte(temp[1]);
- sendbyte(temp[2]);
- sendbyte(temp[3]);
- }
- void init() //定时器0,1初始化
- {
-
- EA=0; //关主中断
- TMOD=0x51; //方式寄存器,T0定时,T1计数功能
- TH0=0x3c; //0x3c 定时50ms
- TL0=0xb0; //0xb0
- TH1=0;
- TL1=0;
- ET0=ET1=1; //T0允许中?
- EA=1; //开主中断
- TR1=1; //T1计数
- TR0=1; //T0定
- }
- int main()
- {
- init();
- while(1);
- }
|