《单片机编程45.doc》由会员分享,可在线阅读,更多相关《单片机编程45.doc(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、#include#define uchar unsigned char#define uint unsigned intuchar count,dunum,wenum;sbit dula=P26;sbit wela=P27;uchar code tabledu=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;uchar code tablewe=0xfe,0xfd,0xfb,0xf7,0xef,0xdf;display();void main()EA=1;ET1=1;TMOD=0x1
2、0;TH1=(65536-500)/256;TL1=(65536-500)%256;TR1=1;while(1)if(count=2) count=0; if(dunum=6) dunum=0; /清零 if(wenum=6) wenum=0; display(); dunum+; wenum+; void tim1() interrupt 3TH1=(65536-500)/256;TL1=(65536-500)%256;count+;display()P0=0xff; /消除余辉wela=1;wela=0;P0=tabledudunum+1;dula=1;dula=0;P0=tablewew
3、enum;wela=1;wela=0;#include#define uchar unsigned char#define uint unsigned intuchar count;uint disnum;sbit dula=P26;sbit wela=P27;uchar code tabledu=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;display(uchar,uchar,uchar);delay(uchar);void main()EA=1;ET1=1;TMOD=0x1
4、0;TH1=(65536-50000)/256;TL1=(65536-50000)%256;TR1=1;while(1)if(count=20) count=0; / if(disnum=1000)/disnum=0; disnum+; display(disnum/100,disnum%100/10,disnum%100%10);void tim1() interrupt 3 using 3TH1=(65536-50000)/256;TL1=(65536-50000)%256;count+;display(uchar bai,uchar shi,uchar ge)P0=tabledubai;
5、dula=1;dula=0;P0=0xfe;wela=1;wela=0;delay(1);P0=tabledushi;dula=1;dula=0;P0=0xfd;wela=1;wela=0;delay(1);P0=tableduge;dula=1;dula=0;P0=0xfb;wela=1;wela=0;delay(1);delay(uchar x)uchar a,b;for(a=x;a0;a-)for(b=255;b0;b-);#include #include #define uchar unsigned char#define uint unsigned intsbit dula=P26
6、;sbit wela=P27;uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x76,0x79,0x38,0x3f,0;uchar temp,t0,t1,bai,shi,ge,flag,flag1;uint shu;void init();void display(uchar,uchar,uchar,uchar,uchar,uchar);void delay(uint z)uint t1,y;for(t1=z;t10;t1-)for(y=110;y
7、0;y-);void main()init();while(1)if(flag1!=1)display(7,6,5,bai,shi,ge);elsedisplay(16,17,18,18,19,20);void init()shu=432;temp=0xfe;P1=temp;TMOD=0x11;TH0=(65536-50000)/256;TL0=(65536-50000)%256;TH1=(65536-50000)/256;TL1=(65536-50000)%256;EA=1;ET0=1;ET1=1;TR0=1;TR1=1;void timer0() interrupt 1TH0=(65536
8、-50000)/256;TL0=(65536-50000)%256;t0+;if(flag!=1)if(t0=10)t0=1;temp=_crol_(temp,1);P1=temp;elseif(t0%4=0)P1=P1;if(t0=60)TR0=0;P1=0xff;flag1=1;void timer1() interrupt 3TH1=(65536-50000)/256;TL1=(65536-50000)%256;t1+;if(t1=2)t1=0;shu-;bai=shu/100;shi=shu%100/10;ge=shu%10;if(shu=398)TR0=0;TH0=(65536-50
9、000)/256;TL0=(65536-50000)%256;TR0=1;flag=1;t0=0;P1=0xff;TR1=0;void display(uchar aa,uchar bb,uchar cc,uchar ba,uchar sh,uchar g) dula=1;P0=tableaa;dula=0;P0=0xff;wela=1;P0=0xfe;wela=0;delay(1); dula=1;P0=tablebb;dula=0;P0=0xff;wela=1;P0=0xfd;wela=0;delay(1); dula=1;P0=tablecc;dula=0;P0=0xff;wela=1;P0=0xfb;wela=0;delay(1); dula=1;P0=tableba;dula=0;P0=0xff;wela=1;P0=0xf7;wela=0;delay(1);dula=1;P0=tablesh;dula=0;P0=0xff;wela=1;P0=0xef;wela=0;delay(1);dula=1;P0=tableg;dula=0;P0=0xff;wela=1;P0=0xdf;wela=0;delay(1);