久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
基于51單片機(藍橋杯開發(fā)板)鬧鐘開源代碼下載即可用
[打印本頁]
作者:
dreamnevergrowu
時間:
2017-11-19 20:57
標題:
基于51單片機(藍橋杯開發(fā)板)鬧鐘開源代碼下載即可用
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define CLOSE P2 &= 0x1f
#define y6 P2=P2&0x1f,P2=P2|0xc0
#define y7 P2=P2&0x1f,P2=P2|0xe0
#define y5 P2=P2&0x1f,P2=P2|0xa0
#define y4 P2=P2&0x1f,P2=P2|0x80
void nao();
sbit d=P0^6;
sbit k1=P3^0;
sbit k2=P3^1;
sbit k3=P3^2;
sbit k4=P3^3;
uint num=0,sum=0,miao=55,fen=0,shi=0,yue=11,ri=19,miao1=0,fen1=1,shi1=0,miao2=0;
unsigned char table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char colork[]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,0x80,0x90};
uchar flag=0;
void time(uint n)
{
int i,j;
for(i=n;i>0;i--)
for(j=150;j>0;j--);
}
void feng() // 關閉蜂鳴器
{
y5;
d=0;
CLOSE;
}
void xiang() // 響鈴 1
{
y5;
d=1;
CLOSE;
}
void xiang1() // 響鈴 2
{
xiang();
time(500);
feng();
}
void xiang2() // 響鈴 3
{
xiang();
time(500);
feng();
time(200);
xiang();
time(300);
feng();
time(200);
xiang();
time(100);
feng();
}
void display() // 時間顯示
{
CLOSE;
P0=0x24; //0010 0100
P2=0xc0; //y6
CLOSE;
P0=0xbf;
P2=0xe0;
time(2); //y7
CLOSE; //suozhu shuzi
CLOSE;
P0=0x80; //1000 0000
P2=0xc0; //y6
CLOSE;
P0=table[miao%10];
P2=0xe0;
time(2); //y7
CLOSE; //suozhu shuzi
CLOSE;
P0=0x40; //0100 0000
P2=0xc0; //y6
CLOSE;
P0=table[miao/10];
P2=0xe0;
time(2); //y7
CLOSE; //suozhu shuzi
CLOSE;
P0=0x10; //0001 0000
P2=0xc0; //y6
CLOSE;
P0=table[fen%10];
P2=0xe0;
time(2); //y7
CLOSE; //suozhu shuzi
CLOSE;
P0=0x08; //0000 1000
P2=0xc0; //y6
CLOSE;
P0=table[fen/10];
P2=0xe0;
time(2); //y7
CLOSE; //suozhu shuzi
CLOSE;
P0=0x02; //0000 0010
P2=0xc0; //y6
CLOSE;
P0=table[shi%10];
P2=0xe0;
time(2); //y7
CLOSE; //suozhu shuzi
CLOSE;
P0=0x01; //0000 0001
P2=0xc0; //y6
CLOSE;
P0=table[shi/10];
P2=0xe0;
time(2); //y7
CLOSE; //suozhu shuzi
nao();
}
void naozhong() // 鬧鐘顯示
{
CLOSE;
P0=0x80; //1000 0000
P2=0xc0; //y6
CLOSE; // suozhu weizhi
P0=table[miao2%10];
P2=0xe0; //y7
CLOSE; //suozhu shuzi
time(1);
CLOSE;
P0=0x40; //0100 0000
P2=0xc0; //y6
CLOSE; //suozhu weihzi
P0=table[miao2/10];
P2=0xe0; //y7
CLOSE; //suozhu shuzi
time(1);
CLOSE;
P0=0x01;
y6; // 0000 0001
CLOSE;
P0=table[shi1%10];
y7;
CLOSE;
time(4);
CLOSE;
P0=0x02;
y6; // 0000 0010
CLOSE;
P0=table[shi1/10];
y7;
CLOSE;
time(4);
CLOSE;
P0=0x04;
y6; // 0000 0100
CLOSE;
P0=0xbf; // 1011 1111
y7;
CLOSE;
time(4);
CLOSE;
P0=0x08;
y6; // 0000 1000
CLOSE;
P0=table[fen1/10];
y7;
CLOSE;
time(4);
CLOSE;
P0=0x10;
y6; // 0001 0000
CLOSE;
P0=table[fen1%10];
y7;
CLOSE;
time(4);
}
void play0()
{
uint temp;
P3=0xfe; // 檢測第一行按鍵
//將第一行線置為低電平,其余全為高電平 1111 1110
temp=P3;
temp=temp&0xf0; //0xfe & 0xf0 1111 1110 & 1111 0000 = 1111 0000
if(temp!=0xf0)
{
time(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0) //再次確認按鍵是否被按下,避免上次為抖動
{
temp=P3;
switch(temp) // 判斷按鍵
{
case 0xee: //1110 1110
feng(); //關鬧鈴
break;
}
while(temp!=0xf0) // 等待按鍵釋放
{
time(4);
feng();
temp=P3;
temp=temp&0xf0; // 將按鍵復原
}
}
}
}
void play1() // 調(diào)整時間
{
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
}
}
void play2() // 暫停時間
{
while(!0x7e);
TR0=~TR0;
}
void day() // 日期顯示
{
CLOSE;
P0=0x01;
y6; // 0000 0001
CLOSE;
P0=table[yue%10];
y7;
CLOSE;
time(4);
CLOSE;
P0=0x02;
y6; // 0000 0010
CLOSE;
P0=table[yue/10];
y7;
CLOSE;
time(4);
CLOSE;
P0=0x04;
y6; // 0000 0100
CLOSE;
P0=0xbf; // 1011 1111
y7;
CLOSE;
time(4);
CLOSE;
P0=0x08;
y6; // 0000 1000
CLOSE;
P0=table[ri/10];
y7;
CLOSE;
time(4);
CLOSE;
P0=0x10;
y6; // 0001 0000
CLOSE;
P0=table[ri%10];
y7;
CLOSE;
time(4);
}
void play4() // 鬧鐘自定義
{
fen1++;
if(fen1==60)
{
fen=0;
shi1++;
if(shi1==24)
{
shi1=0;
}
}
}
void play5() // 日期自定義
{
ri++;
if(ri==31)
{
ri=1;
yue++;
if(yue==12)
{
yue=1;
}
}
}
void play6() // 進入鬧鐘界面
{
int temp;
temp=P3;
while(temp==P3)
naozhong();
}
void play7() // 進入日期界面
{
int temp;
temp=P3;
while(temp==P3)
day();
}
void play3() // 自定義鬧鈴
{
miao2++;
if(miao2==3)
miao2=0;
}
void major() // 矩陣按鍵掃描
{
uint temp;
P3=0xfe; // 檢測第一行按鍵
//將第一行線置為低電平,其余全為高電平 1111 1110
temp=P3;
temp=temp&0xf0; //0xfe & 0xf0 1111 1110 & 1111 0000 = 1111 0000
if(temp!=0xf0)
{
time(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0) //再次確認按鍵是否被按下,避免上次為抖動
{
temp=P3;
switch(temp) // 判斷按鍵
{
case 0xee: //1110 1110
feng(); //關鬧鈴
break;
case 0xde:
play1(); // 調(diào)整時間 // 1101 1110
break;
case 0xbe:
play4(); //調(diào)整鬧鐘時間
break;
case 0x7e:
play7(); //0111 1110 進入riqi界面
break;
}
while(temp!=0xf0) // 等待按鍵釋放
{
temp=P3;
temp=temp&0xf0; // 將按鍵復原
}
}
}
P3=0xfd; // 檢測第二行按鍵 1111 1101
// 將第二行置為低電平,其余全為高電平
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
time(10);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0) // 再次確認按鍵是否被按下,避免上次為抖動
{
temp=P3;
switch(temp) // 判斷按鍵
{
case 0xed:
play2(); // 暫停時間
break;
case 0xdd:
play5(); // 日期自定義
break;
case 0xbd:
play6(); //進入鬧鐘界面
break;
case 0x7d:
play3(); // 自定義鬧鈴
break;
}
while(temp!=0xf0) //等待按鍵釋放
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
void nao() // 啟用鬧鈴
{
if(fen==fen1&&shi==shi1&&miao==flag)
{
if(miao2==0)
xiang();
else if(miao2==1)
xiang1();
else if(miao2==2)
xiang2();
}
}
void main()
{
feng();
TMOD=0x01; // 設置定時器0為工作方式1(M1M0為01)
// TMOD是定時器的工作方式寄存器,確定工作方式和功能。
TH0=(65536-50000)/256; // 裝初值11.0592M晶振定時50ms數(shù)為45872
TL0=(65536-50000)%256; //
EA=1; // 開總中斷
ET0=1; // 開定時器0中斷
TR0=1; // 啟動定時器0
while(1) // 程序停止在這里不斷掃描數(shù)碼管的同時等待中斷發(fā)生
{
display();
// play0();
major();
}
}
void TO_time() interrupt 1
{
TH0=(65536-50000)/256; //重裝初值
TL0=(65536-50000)%256;
sum++; //num每加1次判斷一次是否到20次
if(sum==20) //如果到了20次,說明1秒時間到
{
sum=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
ri++;
if(ri==31)
{
ri=0;
yue++;
{
if(yue==12)
{
yue=1;
nao();
}
}
}
}
}
}
}
}
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
欧美99
|
成人欧美一区二区三区黑人孕妇
|
国产日韩精品一区二区三区
|
日本天天操
|
99亚洲精品
|
国产视频一区在线观看
|
国产精品美女久久久免费
|
亚洲精彩免费视频
|
免费视频一区二区
|
美女天天干天天操
|
亚洲午夜精品
|
一级日批片
|
九九热精品在线
|
国产成人精品在线播放
|
欧美电影大全
|
成人免费观看视频
|
久久精品国产免费高清
|
国产91色在线 | 亚洲
|
久久久久一区二区
|
久久久免费
|
看片一区
|
欧美日韩国产一区二区三区
|
免费毛片网站在线观看
|
亚洲网站在线播放
|
久久大陆
|
欧美一级二级在线观看
|
国产一级电影网
|
日韩一区二区三区在线观看视频
|
国产日韩精品视频
|
91精品久久久
|
亚洲午夜精品一区二区三区
|
国产精品久久久久久久久久久久
|
波多野结衣精品
|
国产1区2区在线观看
|
亚洲人久久
|
操久久久
|
色婷婷影院
|
日韩电影一区二区三区
|
日韩欧美在线视频
|
精品国产鲁一鲁一区二区张丽
|
www..99re
|