《单片机简易6位数码管频率计c语言程序.doc》由会员分享,可在线阅读,更多相关《单片机简易6位数码管频率计c语言程序.doc(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、#include #define uchar unsigned char#define uint unsigned int#define ulong unsigned longunsigned char code duan = 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f; /段码控制unsigned char code wei=0xfe,0xfd,0xfb,0xf7,0xef,0xdF; /位选控制 查表的方法控制/0xfe,0xfd,0xfb,0xf7,0xef,0xdFvoid display(uchar,uchar,uchar,uc
2、har,uchar,uchar);void delay(uint);uchar flag,n,a,b,c,d,e,f;ulong m;uint num;void main()TMOD=0x25; /设置定时器t1方式2,计数器t0方式0TH0=0;TL0=0;TH1=6;TL1=6;EA=1;ET0=1;ET1=1;TR0=1;TR1=1;while(1)if(flag)m=n*65536+256*TH0+TL0;m=256*TH0+TL0;a=m/100000;b=m%100000/10000;c=m%100000%10000/1000;d=m%100000%10000%1000/100;e
3、=m%100000%10000%1000%100/10;f=m%100000%10000%1000%100%10;display(a,b,c,d,e,f);void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f) /数码管显示子程序P0=wei0;P2=duana;delay(1);P0=wei1;P2=duanb;delay(1);P0=wei2;P2=duanc;delay(1);P0=wei3;P2=duand;delay(1);P0=wei4;P2=duane;delay(1);P0=wei5;P2=duanf;delay(1);void delay(uint xms) /延时子程序uint i,j;for(i=xms;i0;i-) for(j=110;j0;j-);void t0() interrupt 1 /计数器t0服务子程序n+;void T1_time()interrupt 3 /定时器t1服务子程序num+;if(num=4000)TR0=0;TR1=0;flag=1;