欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
藍橋杯單片機組 第八屆省賽-基于單片機的電子鐘程序設計
[打印本頁]
作者:
Donsuke
時間:
2019-3-25 15:44
標題:
藍橋杯單片機組 第八屆省賽-基于單片機的電子鐘程序設計
沒有使用DS1302模塊,用定時器完全實現了題目要求,發出來讓沒有思路的同學們參考一下。
本人水平有限,如果有不足之處多多指正。
單片機源程序如下:
#include "intrins.h"
#include "STC15F2K60S2.h"
#include "key.h"
#include "onewire.h"
sbit S7 = P3^0;
sbit S6 = P3^1;
sbit S5 = P3^2;
sbit S4 = P3^3;
unsigned char table[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,0xbf};
unsigned char distime = 0;
unsigned char num0[] = {0,0,17,0,0,17,0,0}; //顯示時鐘
unsigned char num1[] = {0,0,17,0,0,17,0,0}; //顯示鬧鐘設置時間
unsigned char num2[] = {16,16,16,16,16,0,0,12}; //顯示溫度
int shizhong = 0; //用于時鐘的正確運行
unsigned char time_shi = 0 , time_fen = 0 , time_miao = 0; //時鐘參數
unsigned char time_set_mode = 0; //時鐘設置模式,0為不設置,1為設置時,2為設置分,3為設置秒
unsigned char alarm_shi = 0 , alarm_fen = 0 , alarm_miao = 0; //鬧鐘參數
unsigned char alarm_set_mode = 0; //鬧鐘設置模式,對應同上
int alarm_count = 0 ;
bit alarm_start = 0 , alarm_enough = 0;
unsigned char temper = 0;
unsigned char DS_mode = 0; //數碼管顯示模式,0為時鐘,1為鬧鐘,2為溫度
bit flash_start = 0 ;
bit flash0 = 1 , flash1 = 1;
bit LED_mode = 0;
unsigned int LED_count = 0;
void LED_flash()
{
if(LED_mode)
{
P2 = (P2 & 0x1f) | 0x80;
P0 = 0xfe;
P2 &= 0x1f;
P0 = 0xff;
}
else
{
P2 = (P2 & 0x1f) | 0x80;
P0 = 0xff;
P2 &= 0x1f;
P0 = 0xff;
}
if(++LED_count==1000)
LED_mode = ~(LED_mode);
}
void display()
{
P2 |= 0xc0;
P0 = 1<<distime;
P2 &= ~(0xc0);
P0 = 0xff;
switch(DS_mode)
{
case 0:
if(flash0)
{
P2 |= 0xe0;
P0 = table[num0[distime]];
P2 &= ~(0xe0);
P0 = 0x00;
}
else
{
if((distime==(3*(time_set_mode-1)))||(distime==(3*(time_set_mode-1)+1)))
{
P2 |= 0xe0;
P0 = 0xff;
P2 &= ~(0xe0);
P0 = 0x00;
}
else
{
P2 |= 0xe0;
P0 = table[num0[distime]];
P2 &= ~(0xe0);
P0 = 0x00;
}
}
break;
case 1:
if(flash1)
{
P2 |= 0xe0;
P0 = table[num1[distime]];
P2 &= ~(0xe0);
P0 = 0x00;
}
else
{
if((distime==(3*(alarm_set_mode-1)))||(distime==(3*(alarm_set_mode-1)+1)))
{
P2 |= 0xe0;
P0 = 0xff;
P2 &= ~(0xe0);
P0 = 0x00;
}
else
{
P2 |= 0xe0;
P0 = table[num1[distime]];
P2 &= ~(0xe0);
P0 = 0x00;
}
}
break;
case 2:
P2 |= 0xe0;
P0 = table[num2[distime]];
P2 &= ~(0xe0);
P0 = 0x00;
break;
}
if(++distime==8) distime = 0;
}
void Timer0Init() //2ms
{
AUXR |= 0x80; //?????1T??
TMOD &= 0xF0; //???????
TL0 = 0x40; //??????
TH0 = 0xA2; //??????
TF0 = 0; //??TF0??
TR0 = 1; //???0????
EA = 1;
ET0 = 1;
}
void timer0() interrupt 1
{
//====================================================================================
if(alarm_start) //L1閃爍(鬧鐘)控制
{
if(++alarm_count==2500) //5s
{
alarm_count = 0;
alarm_start = 0;
alarm_enough = 1;
}
}
//====================================================================================
if(++shizhong==500) //時鐘正常計時控制,1s
{
if(time_miao==59)
{
time_miao = 0;
if(time_fen==59)
{
time_fen = 0;
if(time_shi==23)
{
time_shi = 0;
}
else
time_shi++;
}
else
time_fen++;
}
else
time_miao++;
shizhong = 0;
if(flash_start)
{
if(DS_mode==0)
flash0 = ~(flash0);
else
flash0 = 1;
if(DS_mode==1)
flash1 = ~(flash1);
else
flash1 = 1;
}
}
//====================================================================================
display();
}
void main()
{
P2 = (P2 & 0x1f) | 0xa0;
P0 = 0;
P2 &= 0x1f;
P0 = 0xff;
P2 = (P2 & 0x1f) | 0x80;
P0 = 0xff;
P2 &= 0x1f;
P0 = 0x00;
time_shi = 23;
time_fen = 59;
time_miao = 50;
alarm_shi = 0;
alarm_fen = 0;
alarm_miao = 0;
Timer0Init();
//////////////////////初始化
//=========================================================================================
while(1)
{
num0[0] = time_shi/10;
num0[1] = time_shi%10;
num0[3] = time_fen/10;
num0[4] = time_fen%10;
num0[6] = time_miao/10;
num0[7] = time_miao%10;
num1[0] = alarm_shi/10;
num1[1] = alarm_shi%10;
num1[3] = alarm_fen/10;
num1[4] = alarm_fen%10;
num1[6] = alarm_miao/10;
num1[7] = alarm_miao%10;
//=========================================================================================
if(S7==0) //時鐘設定
{
Delay10ms();
if(S7==0)
{
DS_mode = 0;
alarm_set_mode = 0;
switch(time_set_mode)
{
case 0:
time_set_mode = 1;
break;
case 1:
time_set_mode = 2;
break;
case 2:
time_set_mode = 3;
break;
case 3:
time_set_mode = 0;
break;
default:
break;
}
while(S7==0);
}
}
//=========================================================================================
if(S6==0) //鬧鐘設定
{
Delay10ms();
if(S6==0)
{
DS_mode = 1;
time_set_mode = 0;
switch(alarm_set_mode)
{
case 0:
alarm_set_mode = 1;
break;
case 1:
alarm_set_mode = 2;
break;
case 2:
alarm_set_mode = 3;
break;
case 3:
alarm_set_mode = 0;
DS_mode = 0;
break;
default:
break;
}
while(S6==0);
}
}
//=========================================================================================
if(S5==0) //加
{
Delay10ms();
if(S5==0)
{
if(time_set_mode!=0&&alarm_set_mode==0)
{
switch(time_set_mode)
{
case 1:
if(time_shi==23)
time_shi = 0;
else
time_shi++;
break;
case 2:
if(time_fen==59)
time_fen = 0;
else
time_fen++;
break;
case 3:
if(time_miao==59)
time_miao = 0;
else
time_miao++;
break;
default:
break;
}
}
if(time_set_mode==0&&alarm_set_mode!=0)
{
switch(alarm_set_mode)
{
case 1:
if(alarm_shi==23)
alarm_shi = 0;
else
alarm_shi++;
break;
case 2:
if(alarm_fen==59)
alarm_fen = 0;
else
alarm_fen++;
break;
case 3:
if(alarm_miao==59)
alarm_miao = 0;
else
alarm_miao++;
break;
default:
break;
}
}
while(S5==0);
}
}
//=========================================================================================
if(S4==0) //減;顯示溫度
{
Delay10ms();
if(S4==0)
{
if(time_set_mode!=0&&alarm_set_mode==0)
{
switch(time_set_mode)
{
case 1:
if(time_shi==0)
time_shi = 23;
else
time_shi--;
break;
case 2:
if(time_fen==0)
time_fen = 59;
else
time_fen--;
break;
case 3:
if(time_miao==0)
time_miao = 59;
else
time_miao--;
break;
default:
break;
}
}
if(time_set_mode==0&&alarm_set_mode!=0)
{
switch(alarm_set_mode)
{
case 1:
if(alarm_shi==0)
alarm_shi = 23;
else
alarm_shi--;
break;
case 2:
if(alarm_fen==0)
alarm_fen = 59;
else
alarm_fen--;
break;
case 3:
if(alarm_miao==0)
alarm_miao = 59;
else
alarm_miao--;
break;
default:
break;
}
}
if(time_set_mode==0&&alarm_set_mode==0)
{
temper = temper_read();
num2[5] = temper/10;
num2[6] = temper%10;
DS_mode = 2;
}
while(S4==0);
DS_mode = 0;
}
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
電子鐘(自)2018.zip
(53.58 KB, 下載次數: 30)
2019-3-25 15:43 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1