单片机控制数码管显示99.99数字秒表,带记忆,倒计时,置数功能
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code dis_r[11]={~0xc0,~0xf9,~0xa4,~0xb0,
~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90, ~0xff};
{
uint i;
for(;ms>0;ms--)
for(i=0;i<115;i++){;}
}
sbitK2= P1^6;
sbit K3 = P1^5;
sbit K4 = P1^4;
sbit M=P1^3;
sfr P2M0=0x95;
sfr P2M1=0x96;
sfr P3M0=0xB1;
sfr P3M1=0xB2;
void main(void)
{
P2M0=0x00;
P2M1=0xff;
P3M0=0x00;
{
dis_buf[0] = dis_r[doc%1000%100%10];
dis_buf[1] = dis_r[doc%1000%100/10]| 0x80;
dis_buf[2] = dis_r[doc%1000/100];
dis_buf[3] = dis_r[doc/1000];
}
void delay(uint ms)
uchar code dis_b[4]={0x20,0x10,0x08,0x04};
uint dis_s[35];
uchar dis_buf[4];
uchar code dis_l[9]={0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0};
uchar dis_t;
uchar a,b,c;
}
}
if(K4!=1)
{
delay(10);
if(K4!=1)
{ while(K4!=1);break;}
}
}
}
void store()
{
b=0;c=0;
dis_s[a]=doc;
a++;
}
void read_store()
{
TR0=0;
dis_t=0;
while(dis_s[b]!='\0')
{
doc=dis_s[b];
read_store();
}
}
if(K4!=1)
{
delay(10);
if(K4!=1)
{
while(K4!=1);
key4_times++;
switch(key4_times)
{
case 1: TR1=0;doc=0;a=0;b=0;c=0;update_disbuf(); break;
case 2: doc=9999;daojshi(); key4_times=0;break;
}
}
}
}
}
void daojshi()
{
while(doc!=0)
{
update_disbuf();
doc--;
delay(50);
if(K3!=1)
{
delay(10);
if(K3!=1)
{
while(K3!=1);
TR0=0;
P2=0x00;
P3=0xff;
delay(100);
TR0=1;
store();
dis_t = 0;
key1_times = 0;
IE = 0x8a;
TR0 = 1;
TR1 = 0;
while(1)
{
if(K1!=1)
{
delay(10);
if(K1!=1)
{
while(K1!=1);
proc_key();
}
}
if(K3!=1)
{
delay(10);
if(K3!=1)
{
while(K3!=1);
P3M1=0xff;
M=0;
P2 = 0x3F;
P3 = 0xFF;
TMOD = 0x11;
TH1 = (65536-50000)/256;
TL1 = (65536-50000)%256;
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
update_disbuf();
}
}
}
void timer0() interrupt 1
{
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
P2 = dis_buf[dis_t];
P3 = dis_b[dis_t];
dis_t++;
dis_t &= 0x03;
}
void timer1() interrupt 3
update_disbuf();
b++;
P1=dis_l[c];
c++;
来自百度文库if(c==7){c=0;}
break;
}
TR0=1;
}
void proc_key()
{
if(K1==1)
{
key1_times++;
switch(key1_times)
{
case 1:TR1=1;break;
case 2:TR1=0;key1_times=0;break;
{
TH1 = (65536-50000)/256;
TL1 = (65536-50000)%256;
n++;
if(n==2)
{
doc++; n=0;
}
if(K2!=1)
{
delay(10);
if(K2!=1)
{
while(K2!=1);
store();
}
}
update_disbuf();
}
void update_disbuf()
uchar key1_times,key4_times;
uint doc,n;
void update_disbuf();
void proc_key();
void daojshi();
void store();
void read_store();
void delay(uint ms);
sbit K1 = P1^7;
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code dis_r[11]={~0xc0,~0xf9,~0xa4,~0xb0,
~0x99,~0x92,~0x82,~0xf8,~0x80,~0x90, ~0xff};
{
uint i;
for(;ms>0;ms--)
for(i=0;i<115;i++){;}
}
sbitK2= P1^6;
sbit K3 = P1^5;
sbit K4 = P1^4;
sbit M=P1^3;
sfr P2M0=0x95;
sfr P2M1=0x96;
sfr P3M0=0xB1;
sfr P3M1=0xB2;
void main(void)
{
P2M0=0x00;
P2M1=0xff;
P3M0=0x00;
{
dis_buf[0] = dis_r[doc%1000%100%10];
dis_buf[1] = dis_r[doc%1000%100/10]| 0x80;
dis_buf[2] = dis_r[doc%1000/100];
dis_buf[3] = dis_r[doc/1000];
}
void delay(uint ms)
uchar code dis_b[4]={0x20,0x10,0x08,0x04};
uint dis_s[35];
uchar dis_buf[4];
uchar code dis_l[9]={0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0};
uchar dis_t;
uchar a,b,c;
}
}
if(K4!=1)
{
delay(10);
if(K4!=1)
{ while(K4!=1);break;}
}
}
}
void store()
{
b=0;c=0;
dis_s[a]=doc;
a++;
}
void read_store()
{
TR0=0;
dis_t=0;
while(dis_s[b]!='\0')
{
doc=dis_s[b];
read_store();
}
}
if(K4!=1)
{
delay(10);
if(K4!=1)
{
while(K4!=1);
key4_times++;
switch(key4_times)
{
case 1: TR1=0;doc=0;a=0;b=0;c=0;update_disbuf(); break;
case 2: doc=9999;daojshi(); key4_times=0;break;
}
}
}
}
}
void daojshi()
{
while(doc!=0)
{
update_disbuf();
doc--;
delay(50);
if(K3!=1)
{
delay(10);
if(K3!=1)
{
while(K3!=1);
TR0=0;
P2=0x00;
P3=0xff;
delay(100);
TR0=1;
store();
dis_t = 0;
key1_times = 0;
IE = 0x8a;
TR0 = 1;
TR1 = 0;
while(1)
{
if(K1!=1)
{
delay(10);
if(K1!=1)
{
while(K1!=1);
proc_key();
}
}
if(K3!=1)
{
delay(10);
if(K3!=1)
{
while(K3!=1);
P3M1=0xff;
M=0;
P2 = 0x3F;
P3 = 0xFF;
TMOD = 0x11;
TH1 = (65536-50000)/256;
TL1 = (65536-50000)%256;
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
update_disbuf();
}
}
}
void timer0() interrupt 1
{
TH0 = (65536-1000)/256;
TL0 = (65536-1000)%256;
P2 = dis_buf[dis_t];
P3 = dis_b[dis_t];
dis_t++;
dis_t &= 0x03;
}
void timer1() interrupt 3
update_disbuf();
b++;
P1=dis_l[c];
c++;
来自百度文库if(c==7){c=0;}
break;
}
TR0=1;
}
void proc_key()
{
if(K1==1)
{
key1_times++;
switch(key1_times)
{
case 1:TR1=1;break;
case 2:TR1=0;key1_times=0;break;
{
TH1 = (65536-50000)/256;
TL1 = (65536-50000)%256;
n++;
if(n==2)
{
doc++; n=0;
}
if(K2!=1)
{
delay(10);
if(K2!=1)
{
while(K2!=1);
store();
}
}
update_disbuf();
}
void update_disbuf()
uchar key1_times,key4_times;
uint doc,n;
void update_disbuf();
void proc_key();
void daojshi();
void store();
void read_store();
void delay(uint ms);
sbit K1 = P1^7;