c语言 提示时间 程序(带声音提示时间、就是闹铃)要在DOS在运行的。做好了加50分
发布网友
发布时间:2023-04-28 15:44
我来回答
共1个回答
热心网友
时间:2023-10-29 02:37
#include <at89x52.h>
#include <DS1302.h>
//定义共阳极字型码0123456789-
unsigned char code dispcode[]=;
unsigned char time[]=;//用来储存时间
unsigned char date[]=;//用来储存日期
unsigned char year[]=;//用来储存年份
unsigned char week[]=;//用来储存星期
SYSTEMTIME time1; //在ds1302.h文件中已经定义了一个名字为SYSTEMTIME的结构体,在这里我们定义一个变量名
//为time的SYSTEMTIME结构体
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); //等待按键释放
}
}
if(P1_5==0)
{
delay(50);
if(P1_5==0)
{
if(n==0)
n=y;
else
n--;
while(P1_5==0);
}
}
return n;
}
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);
}
}
if(P1_5==0)
{
delay(50);
if(P1_5==0)
{
if(n==1)
n=y;
else
n--;
while(P1_5==0);
}
}
return n;
}
unsigned char button_year(n,x,y) //年份调整子程序
unsigned char n,x,y;
{
if(P1_7==0)
{
delay(50);
if(P1_7==0)
{
n++;
if(n==x)
n=2;
while(P1_7==0);
}
}
if(P1_5==0)
{
delay(50);
if(P1_5==0)
{
if(n==2)
n=y;
else
n--;
while(P1_5==0);
}
}
return n;
}
void display(minute10,minute1,hour10,hour1) //显示子程序
unsigned char minute10,minute1,hour10,hour1;
{
P2=0xfe;
P0=dispcode[minute10];//显示分的十位
delay(1);
P2=0xfd;
P0=dispcode[minute1]; //显示分的个位
delay(1);
P2=0xfb;
P0=dispcode[hour10]; //显示时的十位
delay(1);
P2=0xf7;
P0=dispcode[hour1]; //显示时的个位
delay(1);
}
void display1(week1)
unsigned char week1;
{
P2=0xef;
P0=dispcode[week1];
delay(1);
}
void main()
{
unsigned char flag,aa=2,bb=0;
Initial_DS1302(); //初始化DS1302这个时钟芯片,
while(1)
{
DS1302_GetTime(&time1); //读取时间参数
time[3]=(time1.Minute)%10; //把分的个位数据存入time[3]
time[2]=(time1.Minute)/10; //把分的十位数据存入time[2]
time[1]=(time1.Hour)%10; //把时的个位数据存入time[1]
time[0]=(time1.Hour)/10; //把时的十位数据存入time[0]
date[3]=(time1.Day)%10;
date[2]=(time1.Day)/10;
date[1]=(time1.Month)%10;
date[0]=(time1.Month)/10;
year[1]=(time1.Year)%10;
year[0]=(time1.Year)/10;
week[0]=(time1.Week);
display1(week[0]); //显示星期
if(P1_4==0) //如果按下Time Start键一下,时钟开始正常显示时间,再按一下,显示日期,再按一下,显示年份
{
delay(50);
if(P1_4==0)
{
flag++;
if(flag>2)
{
flag=0;
}
}
while(P1_4==0);
}
if(P1_6==0) //如果按下Time Set键一下,开始显示日期,再按一下开始显示年份,再按一下,进入年份,日期,星期和时间的调节模式
{
delay(50);
if(P1_6==0)
{
flag++;
if(flag>8)
{
flag=0;
}
}
while(P1_6==0);
}
switch(flag)
{
case 0:display(time[0],time[1],time[2],time[3]); //调用子函数display,把存入数组time的数据给显示出来
break;
case 1:display(date[0],date[1],date[2],date[3]); //调用子函数display,把存入数组date的数据给显示出来
break;
case 2:display(aa,bb,year[0],year[1]); //调用子函数display,把存入数组year的数据给显示出来
break;
case 3:time1.Year=button_year(time1.Year,2099,2098); //调整年
DS1302_SetTime(0x8c,time1.Year);
display(aa,bb,year[0],year[1]);
break;
case 4:time1.Month=button_date(time1.Month,13,12); //调整月
DS1302_SetTime(0x88,time1.Month);
display(date[0],date[1],10,10);
break;
case 5:time1.Day=button_date(time1.Day,32,31); //调整日
DS1302_SetTime(0x86,time1.Day);
display(10,10,date[2],date[3]);
break;
case 6:time1.Week=button_date(time1.Week,8,7); //调整星期
DS1302_SetTime(0x8a,time1.Week);
display1(week[0]);
break;
case 7:time1.Hour=button_time(time1.Hour,24,23); //调整时
DS1302_SetTime(0x84,time1.Hour);
display(time[0],time[1],10,10);
break;
case 8:time1.Minute=button_time(time1.Minute,60,59); //调整分
DS1302_SetTime(0x82,time1.Minute);
display(10,10,time[2],time[3]);
break;
}
}
}
追问#include
#include
#define uint unsigned int
#define uchar unsigned char
uchar temp;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
P1=0xfe;
temp=P1;
while(1)
{
temp=_crol_(temp,1);
P1=temp;
delay(50);
}
}中的delay是库函数吗?还是随意写个词都行?