新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 51單片機(jī)做的數(shù)碼管電子日歷

51單片機(jī)做的數(shù)碼管電子日歷

作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏



電路圖及仿真文件下載:http://www.51hei.com/bbs/dpj-20404-1.html
下面是程序源碼:
#include
#define uchar unsigned char
#define uint unsigned int
sbit db=P2^7;
char i,sec,min,h,date,month,year,flag;
uchar j,k,m,n,o,p;
sbit dula=P2^0;
sbit wela1=P2^1;
sbit wela2=P2^2;
sbit key_ch=P3^5;
sbit key_add=P3^6;
sbit key_minus=P3^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void init();
void delay(uint);
void second_display();
void minute_display();
void hour_display();
void date_display();
void month_display();
void year_display();
void control();
void time();
void main()
{
init();
while(1)
{
second_display();
minute_display();
hour_display();
date_display();
month_display();
year_display();
control();
}
}
void init()
{
db=0;
i=0;
sec=0;
min=0;
h=0;
date=1;
month=1;
year=1;
flag=0;
wela1=0;
wela2=0;
EA=1;
ET0=1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void second_display()
{
int sec_shi,sec_ge;
sec_shi=sec/10;
sec_ge=sec%10;

本文引用地址:http://m.butianyuan.cn/article/201611/323804.htm

if(flag==1&&j!=1)
j++;
else
{
j=0;
dula=1;
P0=~table[sec_ge];
dula=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x20;
wela2=0;
delay(1);
dula=1;
P0=0xff;
dula=0;

dula=1;
P0=~table[sec_shi];
dula=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x10;
wela2=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
}
}
void minute_display()
{
int min_shi,min_ge;
min_shi=min/10;
min_ge=min%10;

if(flag==2&&k!=1)
k++;
else
{
k=0;
dula=1;
P0=~table[min_ge];
dula=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x08;
wela2=0;
delay(1);
dula=1;
P0=0xff;
dula=0;

dula=1;
P0=~table[min_shi];
dula=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x04;
wela2=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
}
}
void hour_display()
{
int h_shi,h_ge;
h_shi=h/10;
h_ge=h%10;

if(flag==3&&m!=1)
m++;
else
{
m=0;
dula=1;
P0=~table[h_ge];
dula=0;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x02;
wela2=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
delay(1);

dula=1;
P0=~table[h_shi];
dula=0;
wela1=1;
P1=0x00;
wela1=1;
P1=0x00;
wela1=0;
wela2=1;
P1=0x01;
wela2=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
wela2=0;
delay(1);
}

}
void date_display()
{
int date_shi,date_ge;
date_shi=date/10;
date_ge=date%10;

if(flag==4&&n!=1)
n++;
else
{
n=0;
dula=1;
P0=~table[date_ge];
dula=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x80;
wela1=0;
delay(1);
dula=1;
P0=0xff;
dula=0;

dula=1;
P0=~table[date_shi];
dula=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x40;
wela1=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
}
}
void month_display()
{
int month_shi,month_ge;
month_shi=month/10;
month_ge=month%10;

if(flag==5&&o!=1)
o++;
else
{
o=0;
dula=1;
P0=~table[month_ge];
dula=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x20;
wela1=0;
delay(1);
dula=1;
P0=0xff;
dula=0;

dula=1;
P0=~table[month_shi];
dula=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x10;
wela1=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
}
}


上一頁(yè) 1 2 下一頁(yè)

評(píng)論


技術(shù)專區(qū)

關(guān)閉