蓝桥杯单片机第八届
Posted 一心向月
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了蓝桥杯单片机第八届相关的知识,希望对你有一定的参考价值。
全部文件:提取码:azxy
#include "STC15F2K60S2.h"
#include "ds1302.h"
#include "onewire.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit S4=P3^3;
sbit S5=P3^2;
sbit S6=P3^1;
sbit S7=P3^0;
extern unsigned char Time[3];
// 0 1 2 3 4 5 6 7 8 9 熄灭 — //
u8 code duan[12]=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf;
u8 sz[3];
u8 Time1[3]=0x00,0x00,0x00;
u8 nz[3];
u8 time_t=0;
u8 clock=0;
u16 temp=0;
u8 clock_flag=0;
u8 count=0;
u8 count1=0;
void delay(u16 i)
while(i--);
void Chan_hc573(chose);
void Timer0Init(void) //5ms 12.000MHz
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xA0;
TH0 = 0x15;
TF0 = 0;
ET0=1;
void Service_T0() interrupt 1
count++;
if(count==40)
count1++;
count=0;
if(count1%2==1)
clock_flag=1;
else
clock_flag=0;
//===========================选择锁存器=======================//
void Chan_hc573(chose)
switch(chose)
case 4:
P2 = (P2 & 0x1f) | 0x80; break;
case 5:
P2 = (P2 & 0x1f) | 0xa0; break;
case 6:
P2 = (P2 & 0x1f) | 0xc0; break;
case 7:
P2 = (P2 & 0x1f) | 0xe0; break;
case 0:
P2 = (P2 & 0x1f) | 0x00; break;
void Init_system()
Chan_hc573(5);
P0=0x00;
Chan_hc573(4);
P0=0xff;
//==========================数码管设置======================//
void Smg_display(u8 com,u8 dat)
Chan_hc573(7);
P0=0xff;
Chan_hc573(6);
P0=0x01<<com;
Chan_hc573(7);
P0=dat;
void Close_smg()
Chan_hc573(6);
P0=0x00;
Chan_hc573(7);
P0=0xff;
//==========================数码管显示界面======================//
void Time_display()
if(time_t==0&&clock==0&&S4==1)
Smg_display(0,duan[Time[0]/16]); delay(1000);
Smg_display(1,duan[Time[0]%16]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[Time[1]/16]); delay(1000);
Smg_display(4,duan[Time[1]%16]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[Time[2]/16]); delay(1000);
Smg_display(7,duan[Time[2]%16]); delay(1000);
Close_smg();
else if(time_t==1&&clock==0)
if(Time[2]%16%2==1)
Smg_display(0,duan[sz[0]/10]); delay(1000);
Smg_display(1,duan[sz[0]%10]); delay(1000);
else
Smg_display(0,duan[10]); delay(1000);
Smg_display(1,duan[10]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[sz[1]/10]); delay(1000);
Smg_display(4,duan[sz[1]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[sz[2]/10]); delay(1000);
Smg_display(7,duan[sz[2]%10]); delay(1000);
Close_smg();
else if(time_t==2&&clock==0)
if(Time[2]%16%2==1)
Smg_display(3,duan[sz[1]/10]); delay(1000);
Smg_display(4,duan[sz[1]%10]); delay(1000);
else
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(0,duan[sz[0]/10]); delay(1000);
Smg_display(1,duan[sz[0]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[sz[2]/10]); delay(1000);
Smg_display(7,duan[sz[2]%10]); delay(1000);
Close_smg();
else if(time_t==3&&clock==0)
if(Time[2]%16%2==1)
Smg_display(6,duan[sz[2]/10]); delay(1000);
Smg_display(7,duan[sz[2]%10]); delay(1000);
else
Smg_display(6,duan[10]); delay(1000);
Smg_display(7,duan[10]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[sz[1]/10]); delay(1000);
Smg_display(4,duan[sz[1]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(0,duan[sz[0]/10]); delay(1000);
Smg_display(1,duan[sz[0]%10]); delay(1000);
Close_smg();
else if(time_t==0&&clock==1)
if(Time[2]%16%2==1)
Smg_display(0,duan[nz[0]/10]); delay(1000);
Smg_display(1,duan[nz[0]%10]); delay(1000);
else
Smg_display(0,duan[10]); delay(1000);
Smg_display(1,duan[10]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[nz[1]/10]); delay(1000);
Smg_display(4,duan[nz[1]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[nz[2]/10]); delay(1000);
Smg_display(7,duan[nz[2]%10]); delay(1000);
Close_smg();
else if(time_t==0&&clock==2)
if(Time[2]%16%2==1)
Smg_display(3,duan[nz[1]/10]); delay(1000);
Smg_display(4,duan[nz[1]%10]); delay(1000);
else
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(0,duan[nz[0]/10]); delay(1000);
Smg_display(1,duan[nz[0]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[nz[2]/10]); delay(1000);
Smg_display(7,duan[nz[2]%10]); delay(1000);
Close_smg();
else if(time_t==0&&clock==3)
if(Time[2]%16%2==1)
Smg_display(6,duan[nz[2]/10]); delay(1000);
Smg_display(7,duan[nz[2]%10]); delay(1000);
else
Smg_display(6,duan[10]); delay(1000);
Smg_display(7,duan[10]); delay(1000);以上是关于蓝桥杯单片机第八届的主要内容,如果未能解决你的问题,请参考以下文章
《蓝桥杯真题》:2017年单片机省赛(第八届)(内附两种代码实现风格)