新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 基于單片機的頻率計的C語言源代碼

        基于單片機的頻率計的C語言源代碼

        作者: 時間:2012-08-21 來源:網絡 收藏

        RCAP2L=(65536-47850)%256;
        ET2=1; //開定時器2中斷
        EA=1; //開總中斷
        TR2=1;
        }
        void display()
        {
        uchar i;
        fre=(T1count*65536+TH1*256+TL1); //計算
        temp[0]=fre/10000000;
        temp[1]=fre%10000000/1000000;
        temp[2]=fre%10000000%1000000%1000000/100000;
        temp[3]=fre%10000000%1000000%1000000%100000/10000;
        temp[4]=fre%10000000%1000000%1000000%100000%10000/1000;
        temp[5]=fre%10000000%1000000%1000000%100000%10000%1000/100;
        temp[6]=fre%10000000%1000000%1000000%100000%10000%1000%100/10;
        temp[7]=fre%10000000%1000000%1000000%100000%10000%1000%100%10;
        if(fre=999)
        {
        write_com(0x80+4);
        for(i=0;i8;i++)
        {
        write_dat(0x30+temp[i]); //保存要顯示的數到顯示緩沖區
        }
        write_dat('H');
        write_dat('z');
        write_dat(' ');
        write_dat(' ');
        }
        else if(fre>=1000)
        {
        write_com(0x80+4);
        for(i=0;i8;i++)
        {
        write_dat(0x30+temp[i]); //保存要顯示的數到顯示緩沖區
        if(i==4)
        {
        write_dat('.');
        }
        }
        write_dat('K');
        write_dat('H');
        write_dat('z');
        }
        T1count=0;
        timecount=0;
        TH1=0;
        TL1=0;
        TH0=0;
        TL0=0; //定時器0重新裝值,保證精確(不加的話只是最多差0.001s,0.1%)
        }

        void display1()
        {
        uchar j;
        float zhou;
        zhou=((T1count1*65536+TH0*256+TL0)*1.0549);
        frx=(long)((zhou)*256);
        temp1[0]=frx/10000000;
        temp1[1]=frx%10000000/1000000;
        temp1[2]=frx%10000000%1000000%1000000/100000;
        temp1[3]=frx%10000000%1000000%1000000%100000/10000;
        temp1[4]=frx%10000000%1000000%1000000%100000%10000/1000;
        temp1[5]=frx%10000000%1000000%1000000%100000%10000%1000/100;
        temp1[6]=frx%10000000%1000000%1000000%100000%10000%1000%100/10;
        temp1[7]=frx%10000000%1000000%1000000%100000%10000%1000%100%10;
        if(frx=999)
        {
        write_com(0x80+0x40+4);
        for(j=0;j8;j++)
        {
        write_dat(0x30+temp1[j]); //保存要顯示的數到顯示緩沖區
        }
        write_dat('H');
        write_dat('z');
        write_dat(' ');
        write_dat(' ');
        }
        else if(frx>=1000)
        { // frx=frx/1000;
        write_com(0x80+0x40+4);
        for(j=0;j8;j++)
        {
        write_dat(0x30+temp1[j]); //保存要顯示的數到顯示緩沖區
        if(j==4)
        {
        write_dat('.');
        }
        }
        write_dat('K');
        write_dat('H');
        write_dat('z');
        }
        }


        void main(void)
        {
        init();
        init1();
        while(1)
        {
        rd=0;
        ird=1;
        if(flag==1) //標志位為1,表示進行完了一次1S記數
        {
        flag=0;
        kb=0;
        kx=1;
        clr=0;
        ird=0;
        id=0;
        display1();
        display();
        }
        else
        {
        kb=1;
        kx=0;
        }


        }
        }
        void t1(void) interrupt 3 // 記數器中斷,加1
        {
        T1count++;
        }

        void t0(void) interrupt 1 // 記數器中斷,加1
        {
        T1count1++;
        }
        void Timer2() interrupt 5 //調用定時器2,自動重裝載模式
        {
        uchar i=0; //定義靜態變量i
        TF2=0; //定時器2的中斷標志要軟件清0
        timecount++; //計數標志自加1
        if(timecount==20) //判斷是否到1s
        {
        timecount=0; //將靜態變量清0
        flag=1;
        }
        }

        本文引用地址:http://www.104case.com/article/171002.htm

        上一頁 1 2 下一頁

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 龙胜| 苏尼特右旗| 通道| 青河县| 阿城市| 台湾省| 孙吴县| 徐闻县| 潜山县| 高要市| 汉寿县| 和静县| 潍坊市| 鹿泉市| 扎鲁特旗| 奈曼旗| 南涧| 和田县| 曲靖市| 龙南县| 尼勒克县| 菏泽市| 灵寿县| 五指山市| 珠海市| 房山区| 云安县| 峨山| 甘南县| 弥勒县| 高碑店市| 康保县| 芜湖县| 始兴县| 安宁市| 陇南市| 合作市| 剑川县| 色达县| 林周县| 保康县|