待选题目如下:
1、数字钟要求:24小时制时间显示,可随时进行时间校对调整,整点报时及闹钟功能。
单片机源程序如下:
#include
#include
//****************************宏定义********************************
typedef unsigned char uchar;
typedef unsigned int uint;
//****************************位声明********************************
sbit key1=P1^0;
sbit key2=P1^1;
sbit key3=P1^2;
sbit key4=P1^3;
sbit beep=P3^0;
//************************数码管显示的数值**************************
uchar code table[]= {
0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x40,0x00
};
//****************************函数声明******************************
void jia();
void jian();
//********************数组定义,数组内含有8个数值******************
uchar table1[8],table2[8],table3[8],table4[8];
//**************************时间显示初始值**************************
uchar shi=12,fen=0,miao=0;
//**************************定义全局变量****************************
uchar shi1,fen1,miao1,shi2,fen2,miao2,shi3,fen3,miao3;
uchar shi4,fen4,miao4;
uchar flag, flag1, wss, cnt, cnt1, alm1, alm2, alm3;
// 1秒 等时 位闪 次数 校时 闹1 闹2 闹3
uint flag2;
// 蜂鸣
//*********************延时函数,用于动态扫描数码管*****************
void delay(uchar i)
{
uchar x,y;
for(x=i;x>0;x--)
for(y=120;y>0;y--);
}
//*******************************初始化函数*************************
void init()
{
TMOD=0x01; //工作方式1
TH0=0x3c; //定时时间为:50ms (65536-50000)/256
TL0=0x0b0; //(65536-50000)%256
EA=1; //开总中断
ET0=1; //打开定时器
TR0=1; //启动定时器
beep=0;
}
//********************显示子函数,用于显示时间数值*****************
void display()
{
uchar i,j;
if(cnt!=10||wss==0)
{
table1[0]=miao%10; //分离秒的个位与十位
table1[1]=miao/10;
}
else
table1[0]=table1[1]=11;
if(cnt!=11||wss==0)
{
table1[3]=fen%10; //分离分的个位与十位
table1[4]=fen/10;
}
else
table1[3]=table1[4]=11;
if(cnt!=12||wss==0)
{
table1[6]=shi%10; //分离时的个位与十位
table1[7]=shi/10;
}
else
table1[6]=table1[7]=11;
table1[2]=table1[5]=10;
j=0xfb;
for(i=0;i<=7;i++) //从秒到时的扫描
{
P2=j;
P0=table[table1[i]]; //显示数值
delay(10);
j=_cror_(j,1); //循环右移
}
}
//*******************显示子函数,用于显示定时1时间*****************
void display1()
{
uchar i,j;
if(alm1==0)
{
if(cnt!=1||wss==0)
{
table2[0]=miao1%10; //以下含义同上
table2[1]=miao1/10;
}
else
table2[0]=table2[1]=11;
if(cnt!=2||wss==0)
{
table2[3]=fen1%10;
table2[4]=fen1/10;
}
else
table2[3]=table2[4]=11;
if(cnt!=3||wss==0)
{
table2[6]=shi1%10;
table2[7]=shi1/10;
}
else
table2[6]=table2[7]=11;
}
else
table2[0]=table2[1]=table2[3]=table2[4]=table2[6]=table2[7]=10;
table2[2]=table2[5]=10;
j=0xfb;
for(i=0;i<=7;i++)
{
P2=j;
P0=table[table2[i]];
delay(10);
j=_cror_(j,1);
}
}
//********************显示子函数,用于显示定时2时间******************
void display2()
{
uchar i,j;
if(alm2==0)
{
if(cnt!=4||wss==0)
{
table3[0]=miao2%10; //以下含义同上
table3[1]=miao2/10;
}
else
table3[0]=table3[1]=11;
if(cnt!=5||wss==0)
{
table3[3]=fen2%10;
table3[4]=fen2/10;
}
else
table3[3]=table3[4]=11;
if(cnt!=6||wss==0)
{
table3[6]=shi2%10;
table3[7]=shi2/10;
}
else
table3[6]=table3[7]=11;
}
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』