51单片机之闹钟制作
来源:互联网 发布:淘宝发安能物流好恶心 编辑:程序博客网 时间:2024/05/01 06:38
#include<reg51.h>
sbit Key0=P2^0; // 控制开关
sbit Key1=P2^1; //控制调节的变量
sbit Key2=P2^2; // 增加
sbit Key3=P2^3; // 减少
unsigned char code Dx[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code Wx[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char playdata[8]={0};
char min=0;
char ms=0;
char h=0;
void main()
{
unsigned int i;
unsigned char xuanzhe=0;
unsigned char j;
EA=1;
TMOD=0x10;
TH1=0xB8;
TL1=0x00;
ET1=1;
TR1=1;
while(1)
{
if(!Key0)
{
for(i=1000;i>0;i--);
if(!Key0)
{
EA=~EA;
while(!Key0);
}
}
if(!Key1)
{
for(i=1000;i>0;i--);
if(!Key1)
{
xuanzhe++;
while(!Key1);
}
if(xuanzhe>3)
xuanzhe=0;
}
if(!Key2)
{
for(i=1000;i>0;i--);
if(!Key2)
{
switch(xuanzhe)
{
case 1:
{
ms++;
if(ms>=60)
{
ms=0;
min++;
if(min>=60)
{
min=0;
h++;
if(h>=24)
h=0;
}
}
break;
}
case 2:
{
min++;
if(min>=60)
{
min=0;h++;
if(h>=24)
h=0;
}
break;
}
case 3:
{
h++;
if(h>=24)
h=0;
break;
}
}
while(!Key2);
}
}
if(!Key3)
{
for(i=1000;i>0;i--);
if(!Key3)
{
switch(xuanzhe)
{
case 1:
{
ms--;
if(ms<=0)
{
ms=59;
min--;
if(min<=0)
{
min=59;
h--;
if(h<=0)
{
h=23;
}
}
}
break;
}
case 2:
{
min--;
if(min<0)
{
h--;
if(h<0)
h=23;
}
break;
}
case 3:
{
h--;
if(h<0)
h=23;
break;
}
}
while(!Key3);
}
}
playdata[0]=Dx[h/10];
playdata[1]=Dx[h%10];
playdata[2]=0x80;
playdata[3]=Dx[min/10];
playdata[4]=Dx[min%10];
playdata[5]=0x80;
playdata[6]=Dx[ms/10];
playdata[7]=Dx[ms%10];
for(i=0;i<8;i++)
{
P0=0x00;
P0=playdata[i];
P1=Wx[i];
j=200;
while(j--);
}
}
}
void Timer1() interrupt 3
{
static unsigned char cnt=0;
TH1=0xB8;
TL1=0x00;
cnt++;
if(cnt>=50)
{
cnt=0;
ms++;
if(ms>=60)
{
ms=0;
min++;
if(min>=60)
{
min=0;
h++;
if(h>=24)
h=0;
}
}
}
}
sbit Key0=P2^0; // 控制开关
sbit Key1=P2^1; //控制调节的变量
sbit Key2=P2^2; // 增加
sbit Key3=P2^3; // 减少
unsigned char code Dx[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code Wx[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char playdata[8]={0};
char min=0;
char ms=0;
char h=0;
void main()
{
unsigned int i;
unsigned char xuanzhe=0;
unsigned char j;
EA=1;
TMOD=0x10;
TH1=0xB8;
TL1=0x00;
ET1=1;
TR1=1;
while(1)
{
if(!Key0)
{
for(i=1000;i>0;i--);
if(!Key0)
{
EA=~EA;
while(!Key0);
}
}
if(!Key1)
{
for(i=1000;i>0;i--);
if(!Key1)
{
xuanzhe++;
while(!Key1);
}
if(xuanzhe>3)
xuanzhe=0;
}
if(!Key2)
{
for(i=1000;i>0;i--);
if(!Key2)
{
switch(xuanzhe)
{
case 1:
{
ms++;
if(ms>=60)
{
ms=0;
min++;
if(min>=60)
{
min=0;
h++;
if(h>=24)
h=0;
}
}
break;
}
case 2:
{
min++;
if(min>=60)
{
min=0;h++;
if(h>=24)
h=0;
}
break;
}
case 3:
{
h++;
if(h>=24)
h=0;
break;
}
}
while(!Key2);
}
}
if(!Key3)
{
for(i=1000;i>0;i--);
if(!Key3)
{
switch(xuanzhe)
{
case 1:
{
ms--;
if(ms<=0)
{
ms=59;
min--;
if(min<=0)
{
min=59;
h--;
if(h<=0)
{
h=23;
}
}
}
break;
}
case 2:
{
min--;
if(min<0)
{
h--;
if(h<0)
h=23;
}
break;
}
case 3:
{
h--;
if(h<0)
h=23;
break;
}
}
while(!Key3);
}
}
playdata[0]=Dx[h/10];
playdata[1]=Dx[h%10];
playdata[2]=0x80;
playdata[3]=Dx[min/10];
playdata[4]=Dx[min%10];
playdata[5]=0x80;
playdata[6]=Dx[ms/10];
playdata[7]=Dx[ms%10];
for(i=0;i<8;i++)
{
P0=0x00;
P0=playdata[i];
P1=Wx[i];
j=200;
while(j--);
}
}
}
void Timer1() interrupt 3
{
static unsigned char cnt=0;
TH1=0xB8;
TL1=0x00;
cnt++;
if(cnt>=50)
{
cnt=0;
ms++;
if(ms>=60)
{
ms=0;
min++;
if(min>=60)
{
min=0;
h++;
if(h>=24)
h=0;
}
}
}
}
1 0
- 51单片机之闹钟制作
- 51单片机—LCD显示闹钟时间
- 闹钟制作
- 闹钟制作
- 闹钟制作
- 51单片机之音乐播放器的制作
- 运用51单片机来实现时间跟闹钟的作用
- 【51单片机】童年回忆,咬手鲨鱼改装闹钟
- 安卓制作闹钟
- android闹钟的制作
- 51单片机定时器制作日志
- 51单片机流水灯制作
- 一个闹钟的单片机程序
- 单片机时钟实现闹钟功能
- 单片机开发之数字温度计制作
- android 制作的精美闹钟
- android 制作的精美闹钟
- 学习使用Cocos制作《闹钟》
- 学习笔记:DataTables之数据读取和操作(java对象转换为json对象)
- JAVA 运算符和条件结构
- Spring MVC 实现增删改查
- 项目24.4个人所得税计算器if语句版
- iperf 2.0.5的bug
- 51单片机之闹钟制作
- 多线程系列二——java线程间的互斥与同步
- PreferenceActivity
- SSH搭建web java
- 黑马程序员——5.多线程
- Valid Parentheses
- 拓扑排序
- 51单片机之蓝牙控制风扇
- 观后感