找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3205|回复: 2
收起左侧

蓝桥杯单片机组第八届省赛源代码自己写的

[复制链接]
ID:310661 发表于 2018-4-18 10:21 来自手机 | 显示全部楼层 |阅读模式
#include<STC15F2K60S2.h>
#include "ds1302.h"
#include "ds18b20.h"
#define uchar unsigned char
#define uint unsigned int
  extern uchar shijian[];
        uchar yi,er,san,si,wu,liu,qi,ba;
        uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc6};
        uchar shijianshezhi=5;
        uchar clock[3]={0,0,0};
        uchar naozhongshezhi=0;
        uchar s4=0;
        bit wendu=0;
        uchar tt=0;
        uint miao=0;
        bit flat=0;
  uchar led=0;
       
        void display1(uchar yi,uchar er);
        void display2(uchar san,uchar si);
        void display3(uchar wu,uchar liu);
        void display4(uchar qi,uchar ba);
  void keyscan(void);
        void allinit(void);
        void delay(uint ms);
        void Timer0Init(void);
        void main(void)
        {
                allinit();
                DS_init();
                Timer0Init();
                while(1)
                {
                        DS_get();
                        if(wendu==0)
                        {
                                if(shijianshezhi==5)
                          {
                                  yi=shijian[2]/10;er=shijian[2]%10;san=10;si=shijian[1]/10;wu=shijian[1]%10;liu=10;qi=shijian[0]/10;ba=shijian[0]%10;
                          }
                          else if(shijianshezhi==1)
                          {
                                  if(shijian[0]%2==1){yi=shijian[2]/10;er=shijian[2]%10;san=10;si=shijian[1]/10;wu=shijian[1]%10;liu=10;qi=shijian[0]/10;ba=shijian[0]%10;}
                                        else{yi=11;er=11;san=10;si=shijian[1]/10;wu=shijian[1]%10;liu=10;qi=shijian[0]/10;ba=shijian[0]%10;}
                          }
                          else if(shijianshezhi==2)
                          {
                                  if(shijian[0]%2==1){yi=shijian[2]/10;er=shijian[2]%10;san=10;si=shijian[1]/10;wu=shijian[1]%10;liu=10;qi=shijian[0]/10;ba=shijian[0]%10;}
                                        else{yi=shijian[2]/10;er=shijian[2]%10;san=10;si=11;wu=11;liu=10;qi=shijian[0]/10;ba=shijian[0]%10;}
                          }
                          else if(shijianshezhi==3)
                          {
                                  if(shijian[0]%2==1){yi=shijian[2]/10;er=shijian[2]%10;san=10;si=shijian[1]/10;wu=shijian[1]%10;liu=10;qi=shijian[0]/10;ba=shijian[0]%10;}
                                        else{yi=shijian[2]/10;er=shijian[2]%10;san=10;si=shijian[1]/10;wu=shijian[1]%10;liu=10;qi=11;ba=11;}
                          }
                               
                               
                               
                            if(naozhongshezhi==5)
                          {
                                  yi=clock[2]/10;er=clock[2]%10;san=10;si=clock[1]/10;wu=clock[1]%10;liu=10;qi=clock[0]/10;ba=clock[0]%10;
                          }
                          else if(naozhongshezhi==1)
                          {
                                  if(shijian[0]%2==1){yi=clock[2]/10;er=clock[2]%10;san=10;si=clock[1]/10;wu=clock[1]%10;liu=10;qi=clock[0]/10;ba=clock[0]%10;}
                                        else{yi=11;er=11;san=10;si=clock[1]/10;wu=clock[1]%10;liu=10;qi=clock[0]/10;ba=clock[0]%10;}
                          }
                          else if(naozhongshezhi==2)
                          {
                                  if(shijian[0]%2==1){yi=clock[2]/10;er=clock[2]%10;san=10;si=clock[1]/10;wu=clock[1]%10;liu=10;qi=clock[0]/10;ba=clock[0]%10;}
                                        else{yi=clock[2]/10;er=clock[2]%10;san=10;si=11;wu=11;liu=10;qi=clock[0]/10;ba=clock[0]%10;}
                          }
                          else if(naozhongshezhi==3)
                          {
                                  if(shijian[0]%2==1){yi=clock[2]/10;er=clock[2]%10;san=10;si=clock[1]/10;wu=clock[1]%10;liu=10;qi=clock[0]/10;ba=clock[0]%10;}
                                        else{yi=clock[2]/10;er=clock[2]%10;san=10;si=clock[1]/10;wu=clock[1]%10;liu=10;qi=11;ba=11;}
                          }
                        }
                        else if(wendu==1)
                        {
                                yi=11;er=11;san=11;si=11;wu=11;liu=Tempget()/10;qi=Tempget()%10;ba=12;
                        }
                        if((shijian[2]==clock[2])&&(shijian[1]==clock[1])&&(shijian[0]==clock[0]))
                        {
                                led=1;tt=0;miao=0;
                        }
                        keyscan();
                        display1(yi,er);
                        display2(san,si);
                        display3(wu,liu);
                        display4(qi,ba);
                }
        }
        void allinit(void)
        {
                P2=0xa0;
                P0=0x00;
                P2=0x80;
                P0=0xff;
        }
        void display1(uchar yi,uchar er)
        {
                P2=0xc0;
                P0=0x01;
                P2=0xff;
                P0=tab[yi];
                delay(1);
               
                P2=0xc0;
                P0=0x02;
                P2=0xff;
                P0=tab[er];
                delay(1);
        }
        void display2(uchar san,uchar si)
        {
                P2=0xc0;
                P0=0x04;
                P2=0xff;
                P0=tab[san];
                delay(1);
               
                P2=0xc0;
                P0=0x08;
                P2=0xff;
                P0=tab[si];
                delay(1);
        }
        void display3(uchar wu,uchar liu)
        {
                P2=0xc0;
                P0=0x10;
                P2=0xff;
                P0=tab[wu];
                delay(1);
               
                P2=0xc0;
                P0=0x20;
                P2=0xff;
                P0=tab[liu];
                delay(1);
        }
        void display4(uchar qi,uchar ba)
        {
                P2=0xc0;
                P0=0x40;
                P2=0xff;
                P0=tab[qi];
                delay(1);
               
                P2=0xc0;
                P0=0x80;
                P2=0xff;
                P0=tab[ba];
                delay(1);
               
                P2=0xc0;
                P0=0xff;
                P2=0xff;
                P0=0xff;
        }
        void delay(uint ms)
        {
                uint i,j;
                for(i=ms;i>0;i--)
                for(j=845;j>0;j--);
        }
        void keyscan(void)
        {
                if(P30==0)
                {
                        delay(5);
                        if(P30==0)
                        {
                                if(led==0)
                                {
                                        if(shijianshezhi==0){shijianshezhi=5;naozhongshezhi=0;}
                                  else if(shijianshezhi==5)shijianshezhi=1;
                                  else if(shijianshezhi==1)shijianshezhi=2;
                                  else if(shijianshezhi==2)shijianshezhi=3;
                                  else if(shijianshezhi==3)shijianshezhi=5;
                                }
                                else if(led==1)
                                {
                                        led=0;P2=0x80;P0=0xff;
                                }
                        }
                        while(!P30);
                }
                if(P31==0)
                {
                        delay(5);
                        if(P31==0)
                        {
                                if(led==0)
                                {
                                        if(naozhongshezhi==0){naozhongshezhi=5;shijianshezhi=0;}
                                  else if(naozhongshezhi==5)naozhongshezhi=1;
                                  else if(naozhongshezhi==1)naozhongshezhi=2;
                                  else if(naozhongshezhi==2)naozhongshezhi=3;
                                  else if(naozhongshezhi==3)naozhongshezhi=5;
                                }
                                else if(led==1)
                                {
                                        led=0;P2=0x80;P0=0xff;
                                }
                        }
                        while(!P31);
                }
                if(P32==0)
                {
                        delay(5);
                        if(P32==0)
                        {
                                if(led==0)
                                {
                                        if(shijianshezhi==1)
                                                {
                                            if(shijian[2]==23)shijian[2]=0;
                                                  else shijian[2]++;
                                                        DS_init();
                                                }
                                  else if(shijianshezhi==2)
            {
                                                        if(shijian[1]==59)shijian[1]=0;
                                                  else shijian[1]++;
                                                  DS_init();
                                                }
                                  else if(shijianshezhi==3)
            {
                                                        if(shijian[0]==59)shijian[0]=0;
                                                  else shijian[0]++;
                                                  DS_init();
                                                }
                                  else if(naozhongshezhi==1)
                                                {
                                                        if(clock[2]==23)clock[2]=0;
                                                        else clock[2]++;
                                                }
                                  else if(naozhongshezhi==2)
                                                {
                                                        if(clock[1]==59)clock[1]=0;
                                            else clock[1]++;
                                                }
                                  else if(naozhongshezhi==3)
                                                {
                                                        if(clock[1]==59)clock[0]=0;
                                           clock[0]++;
                                                }
                                }
                                else if(led==1)
                                {
                                        led=0;P2=0x80;P0=0xff;
                                }
                        }
                        while(!P32);
                }
                if(P33==0)
                {
                        delay(5);
                        if(P33==0)
                        {
                                s4=1;
                                if(shijianshezhi==5)wendu=1;
                        }
                }
                if((s4==1)&&(P33==1))
                {
                        s4=0;
                        if(led==0)
                        {
                                wendu=0;
                          if(shijianshezhi==1)
                                        {
                                                if(shijian[2]==0)shijian[2]=23;
                                    else shijian[2]--;
                                                DS_init();
                                        }
                    else if(shijianshezhi==2)
                                        {
                                                if(shijian[1]==0)shijian[1]=59;
                                    else shijian[1]--;
                                                DS_init();
                                        }
                          else if(shijianshezhi==3)
                                        {
                                                if(shijian[0]==0)shijian[0]=59;
                                    else shijian[0]--;
                                                DS_init();
                                        }
                          else if(naozhongshezhi==1)
          {
                                                if(clock[2]==0)clock[2]=23;
                                                else clock[2]--;
                                        }
                          else if(naozhongshezhi==2)
                                        {
                                                if(clock[1]==0)clock[1]=59;
                                    else clock[1]--;
                                        }
                          else if(naozhongshezhi==3)
                                        {
                                                if(clock[0]==0)clock[0]=59;
                                    else clock[0]--;
                                        }
                        }
                        else if(led==1)
                        {
                                led=0;P2=0x80;P0=0xff;
                        }
                }
        }
        void Timer0Init(void)               
  {
         AUXR |= 0x80;               
         TMOD &= 0xF0;               
         TL0 = 0x00;               
         TH0 = 0x28;       
         TF0 = 0;       
         TR0 = 1;       
         ET0=1;
         EA=1;
  }
        void Timer0() interrupt 1
        {
                tt++;miao++;
                if((tt==40)&&(led==1))
                {
                        tt=0;
                        if(flat==0){P2=0x80;P0=0xfe;flat=1;}
                        else if(flat==1){P2=0x80;P0=0xff;flat=0;}
                }
                if(miao==1000)
                {
                        led=0;miao=0;P2=0x80;P0=0xff;
                }
        }
回复

使用道具 举报

ID:431575 发表于 2019-2-1 13:47 | 显示全部楼层
如何下载呀
回复

使用道具 举报

ID:481759 发表于 2019-2-27 19:58 | 显示全部楼层
别的几个副文件在哪儿呀
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表