这是一个朋友做的,你可以参考一下:
#include <reg52.h>
#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;
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;
}
}
void year_display()
{
int year_qian,year_bai,year_shi,year_ge;
year_qian=year/1000;
year_bai=year%1000/100;
year_shi=year%1000%100/10;
year_ge=year%10;
if(flag==6&&p!=1)
p++;
else
{
p=0;
dula=1;
P0=~table[year_ge];
dula=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x08;
wela1=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
dula=1;
P0=~table[year_shi];
dula=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x04;
wela1=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
dula=1;
P0=~table[year_bai];
dula=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x02;
wela1=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
dula=1;
P0=~table[2];
dula=0;
wela2=1;
P1=0x00;
wela2=0;
wela1=1;
P1=0x01;
wela1=0;
delay(1);
dula=1;
P0=0xff;
dula=0;
wela1=0;
}
}
void control()
{
if(!key_ch)
{
delay(5);
if(!key_ch)
{
flag++;
if(flag==7)
flag=0;
}
}
while(!key_ch);
if(flag==1&&key_add==0)
{
while(!key_add);
sec++;
if(sec==60)
sec=0;
}
if(flag==1&&key_minus==0)
{
while(!key_minus);
sec--;
if(sec==-1)
sec=59;
}
if(flag==2&&key_add==0)
{
while(!key_add);
min++;
if(min==60)
min=0;
}
if(flag==2&&key_minus==0)
{
while(!key_minus);
min--;
if(min==-1)
min=59;
}
if(flag==3&&key_add==0)
{
while(!key_add);
h++;
if(h==24)
h=0;
}
if(flag==3&&key_minus==0)
{
while(!key_minus);
h--;
if(h==-1)
h=23;
}
if(flag==4&&key_add==0)
{
while(!key_add);
date++;
if(date==29)
if((year%4!=0)&&(month==2))
date=1;
if(date==30)
if((year%4==0)&&(month==2))
date=1;
if(date==31)
if((month==4)||(month==6)||(month==9)||(month==11))
date=1;
if(date==32)
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
date=1;
}
if(flag==5&&key_add==0)
{
while(!key_add);
month++;
if(month==13)
month=1;
}
if(flag==5&&key_minus==0)
{
while(!key_minus);
month--;
if(month==0)
month=12;
}
if(flag==6&&key_add==0)
{
while(!key_add);
year++;
if(year==99)
year=1;
}
if(flag==6&&key_minus==0)
{
while(!key_minus);
year--;
if(year==0)
year=99;
}
}
void T0_rpt() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
i++;
time();
}
void time()
{
if(i==20)
{
i=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
h++;
if(h==24)
{
h=0;
min=0;
sec=0;
date++;
if(date==29)
if((year%4!=0)&&(month==2))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==30)
if((year%4==0)&&(month==2))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==31)
if((month==4)||(month==6)||(month==9)||(month==11))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
if(date==32)
if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
{
date=1;
month++;
if(month==13)
{
month=1;
year++;
}
}
}
}
}
}
}
at89c51单片机实现电子时钟,不带闹铃。显示时分秒。求图求程序
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x80};\/*0~9和无显示、的数码管段码*\/ uint dd=0,sec=0,min=0,hour=12; \/\/时间初始值12:00:00 uchar sec1=0,min1=0,hour1=0,set=0,sw=0;\/\/闹钟设定初始值0:00:00 uchar x[7],y[...
AT89C51,编写C语言程序,实现LED灯间隔1s亮一次 ,显示器开始计时从00~20...
0x99,0x92,0x82,0xf8,0x80,0x90};\/\/ 数码管段选 unsigned char aa,second;sbit LED=P1^0;\/\/ 小灯 void init(); \/\/初始化 void keypress(); \/\/按键识别 void delay(unsigned int z);\/\/延时 void main(){ init();LED = 1;while(1){ if(aa==20){ aa=0;second++;LED=...
...以AT89C51单片机为核心的时钟,在LED显示器上显示当前的时间。_百度...
0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x76,0x79,0x38,0x3f,0x40,0x00};void init();void jianpan();void display(uchar,uchar,uchar,uchar,uchar,uchar,uchar);uchar a,b,c,d,e,f,miao,fen,shi,i,j,k;void delay(uint z) \/\/延时函数 { uint...
求:用AT89C51单片机实现直流电机PWM调速原理图,protues仿真、程序
uchar code smg[12]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x73,0x71};\/\/程序存储区定义字型码表 char data led[4]={0x08,0x04,0x02,0x01}; \/\/位码 uint x; \/\/数码管显示的数值 display(); \/\/数码管显示 delays(); \/\/延时函数 key();displays...
AT89C51数码管动态显示
AT89C51数码管动态显示,用8位一体共阳数码管。仿真图和效果如下 程序如下 include<reg51.h> define uint unsigned int define uchar unsigned char uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,\/\/0~9的段码值 0xf1,0xbf};\/\/J,-的段码 uchar ledram[]=...
AT89c51单片机程序控制两个数码管显示00-59秒表的程序要怎么编啊...
display(second)子函数与两个数码管的连接方式有关 void main(void )\/\/主程序 { TMOD=0x01;\/\/ 定时器1工作方式一 ET0=1;EA=1;TH0=(65536-10000)\/256;\/\/定时10ms TL0=(65536-10000)%256;TR0=0;\/\/上电先不启动 while(1){ if(key1==0)\/\/判断按键是否按下 { Delay1ms(10);\/\/延时...
用单片机AT89C51 加数码管共阴极的来动态显示学号,比如1234,求用keil...
include<reg51.h>#define uchar unsigned charuchar tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00}; \/\/0到9uchar num;uchar led[]={1,2,3,4};void t0isr() interrupt 1{TH0=(65536-5000)\/256;TL0=(65536-5000)%256;switch(num){case 0:P2=0x01;break...
求程序用AT89C51单片机...用六位数码管实现数字时钟,显示时分秒,用两个...
uchar code table[]={ \/\/数码管编码表 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};void display(uchar miao,uchar fen,uchar shi);void delay(uint z);void init();void main(){ init();\/\/初始化子程序 miao=0;shi=0;fen=0;while(1){ display(miao,fen,shi);} }...
单片机 at89c51 6位数码管24小时倒计时程序
include<reg51.h> define uchar unsigned char define uint unsigned int uchar hour,min,sec;uint count;uchar code tab[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};uchar code add[6]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb};\/***延时一毫秒***\/ void delay1ms(void...
急求基于单片机AT89C51的多功能数字电子钟的汇编程序,高手进!~_百度知...
用89C51控制3个HC595,前两个595接8段数码显示管,显示“0”~“9”每秒跳动一次.第3个HC595接8个LED灯,每隔1秒闪烁1次.include<at89x52.h> include<intrins.h> define uchar unsigned char define uint unsigned int uchar table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90...