3、时钟数码管显示--可调时
来源:互联网 发布:域名注册费用标准 编辑:程序博客网 时间:2024/04/30 03:38
#include<reg52.h>#define uchar unsigned char#define uint unsigned intuchar s1,s2,m1,m2,h1,h2,miao,fen,shi,count,flag;sbit dula=P2^6;sbit wela=P2^7;sbit tiaoshi=P3^4;sbit key_s=P3^5;sbit key_f=P3^6;sbit key_m=P3^7;uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};display(uchar,uchar,uchar,uchar,uchar,uchar);delay(uchar);void main(){ EA=1; ET1=1; TMOD=0x10; TH1=(65536-50000)/256; TL1=(65536-50000)%256; TR1=1; P3=0xff; shi=12; while(1) { while(P3!=0xff) { if(tiaoshi==0) { delay(100); if(tiaoshi==0) TR1=~TR1; while(!tiaoshi); } if(key_m==0) { delay(100); if(key_m==0) { miao++; if(miao==60) miao=0; } while(!key_m); } if(key_f==0) { delay(100); if(key_f==0) { fen++; if(fen==60) fen=0; } while(!key_f); } if(key_s==0) { delay(100); if(key_s==0) { shi++; if(shi==24) shi=0; } while(!key_s); } } display(shi/10,shi%10,fen/10,fen%10,miao/10,miao%10); }}void tim1() interrupt 3 using 3{ TH1=(65536-50000)/256; TL1=(65536-50000)%256; count++; if(count==20) { count=0; miao++; if(miao==60) { miao=0; fen++; if(fen==60) { fen=0; shi++; if(shi==24) shi=0; } } } }display(uchar h2,uchar h1,uchar m2,uchar m1,uchar s2,uchar s1){ P0=0xff; wela=1; wela=0; P0=table[h2]; dula=1; dula=0; P0=0xfe; wela=1; wela=0; delay(1); P0=0xff; wela=1; wela=0; P0=table[h1]; dula=1; dula=0; P0=0xfd; wela=1; wela=0; delay(1); P0=0xff; wela=1; wela=0; P0=table[m2]; dula=1; dula=0; P0=0xfb; wela=1; wela=0; delay(1); P0=0xff; wela=1; wela=0; P0=table[m1]; dula=1; dula=0; P0=0xf7; wela=1; wela=0; delay(1); P0=0xff; wela=1; wela=0; P0=table[s2]; dula=1; dula=0; P0=0xef; wela=1; wela=0; delay(1); P0=0xff; wela=1; wela=0; P0=table[s1]; dula=1; dula=0; P0=0xdf; wela=1; wela=0; delay(1);}delay(uchar x){ uchar a,b; for(a=x;a>0;a--) for(b=2;b>0;b--);}