本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
下面是个电子钟的C语言程序,但如要在P1.5端口加一个发光二极管做秒位的闪动,要怎么改程序。
#include <at89x52.h>
#include <DS1302.h>
unsigned char code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
unsigned char time[]={0,0,0,0,0,0,0,0};
unsigned char date[]={0,0,0,0,0,0,0,0};
SYSTEMTIME time1;
void delay(unsigned char i)
{
unsigned char j;
while((i--)!=0)
{
for(j=123;j>0;j--);
}
}
unsigned char button_time(n,x,y)
unsigned char n,x,y;
{
if(P1_7==0)
{
delay(50);
if(P1_7==0)
{
n++;
if(n==x)
n=0;
while(P1_7==0);
}
}
}
unsigned char button_date(n,x,y)
unsigned char n,x,y;
{
if(P1_7==0)
{
delay(50);
if(P1_7==0)
{
n++;
if(n==x)
n=1;
while(P1_7==0);
}
}
}
void display(second10,second1,minute10,minute1,hour10,hour1)
unsigned char second10,second1,minute10,minute1,hour10,hour1;
{
P2=0xfe;
P0=dispcode[second10];
delay(1);
P2=0xfd;
P0=dispcode[second1];
delay(1);
P2=0xfb;
P0=dispcode[10];
delay(1);
P2=0xf7;
P0=dispcode[minute10];
delay(1);
P2=0xef;
P0=dispcode[minute1];
delay(1);
P2=0xdf;
P0=dispcode[10];
delay(1);
P2=0xbf;
P0=dispcode[hour10];
delay(1);
P2=0x7f;
P0=dispcode[hour1];
delay(1);
}
void main()
{
unsigned char flag;
Initial_DS1302();
while(1)
{
DS1302_GetTime(&time1);
time[5]=(time1.Second)%10;
time[4]=(time1.Second)/10;
time[3]=(time1.Minute)%10;
time[2]=(time1.Minute)/10;
time[1]=(time1.Hour)%10;
time[0]=(time1.Hour)/10;
date[5]=(time1.Day)%10;
date[4]=(time1.Day)/10;
date[3]=(time1.Month)%10;
date[2]=(time1.Month)/10;
date[1]=(time1.Year)%10;
date[0]=(time1.Year)/10;
if(P1_6==0)
{
delay(50);
if(P1_6==0)
{
flag++;
if(flag>7)
{
flag=0;
}
}
while(P1_6==0);
}
switch(flag)
{
case 0:display(time[0],time[1],time[2],time[3],time[4],time[5]);
break;
case 1:display(date[0],date[1],date[2],date[3],date[4],date[5]);
break;
case 2:time1.Year=button_date(time1.Year,100,99);
DS1302_SetTime(0x8c,time1.Year);
display(date[0],date[1],10,10,10,10);
break;
case 3:time1.Month=button_date(time1.Month,13,12);
DS1302_SetTime(0x88,time1.Month);
display(10,10,date[2],date[3],10,10);
break;
case 4:time1.Day=button_date(time1.Day,32,31);
DS1302_SetTime(0x86,time1.Day);
display(10,10,10,10,date[4],date[5]);
break;
case 5:time1.Hour=button_time(time1.Hour,24,23);
DS1302_SetTime(0x84,time1.Hour);
display(time[0],time[1],10,10,10,10);
break;
case 6:time1.Minute=button_time(time1.Minute,60,59);
DS1302_SetTime(0x82,time1.Minute);
display(10,10,time[2],time[3],10,10);
break;
case 7:time1.Second=button_time(time1.Second,60,59);
DS1302_SetTime(0x80,time1.Second);
display(10,10,10,10,time[4],time[5]);
break;
}
}
}
[ 此帖被给你一支烟在2011-08-28 23:28重新编辑 ] |