Design of 51 single chip microcomputer intelligent clock

Publisher:开元轩Latest update time:2020-02-17 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

        tml = DS18b20ReadByte(); //Read the temperature value, a total of 16 bits, read the low byte first

        tmh = DS18b20ReadByte(); // read high byte again

        temp = tmh;

        temp <<= 8;

        temp |= tml;

        if(tmh>0x07)

        {

                temp=~temp+1;

                temp=temp*6.25;

                temp=temp+5;

                temp=temp/10;

                temp=temp+10000;

        }

        else

        {

                temp=temp*6.25;

                temp=temp+5;

                temp=temp/10;

        }

        return temp;

}


/***********************************************************************************************************

* Function name: xianshiwendu()

* Input parameters: void 

* Output parameters: void

*

* Function: Convert temperature data

*

* Note: None

*

*

* Completion date: 2019.12.25

************************************************************************************************************/


void getFile()

{

          wendu=DS18b20ReadTemp();

                if(wendu<10000) xianshi5(28,wendu%1000/100,wendu%100/10+17,wendu%10,12);

                if(wendu>10000) xianshi5(27,wendu%1000/100,wendu%100/10+17,wendu%10,12);


}


Menu program (main logic):

#include <STC8.H>

#include

#include

#include

#include

#include

#include

#include

#include <18b20.H>


extern uchar shijian[13];                

extern uint ms1; // used for flashing timing

extern uint ms2; //Used to long press the button to quickly increase the timing

extern uint ms4; // used for loop display timing

bit changan=0; //Long press flag


uint n=0; //Calculate the leap year

uint y=0; //Calculate the month

bit runnian=1; //leap year flag

uchar yue=0; //big month flag 1 big month 2 February 0 small month


uchar tiaozheng[13]={0,0,0,0,0,0,0,0,0,0,0,0,0}; //Adjust the time data temporary storage array


uchar cd=0; //Menu

bit aj1,aj2,aj3,aj4;


extern int nao_kaiguan,nao_shi,nao_fen,nao2_kaiguan,nao2_shi,nao2_fen,wendu_kaiguan; //eeprom data


bit s; //Alarm 1, 2 switch flag


extern int wendu; //temperature information


/***********************************************************************************************************

* Function name: caidan()

* Input parameters: void

* Output parameters: void

*

* Function: Menu program

*

* Note: This program is the core of this work  

*Level 0 menu is used to display time, date and temperature normally; 

* Level 1 menu is used to flash all time (prompt whether to modify)

*Level 2 menu is used to display the full flash of the date (prompt whether to modify it) 

*Level 3 menu is used to flash al (prompt whether to modify the alarm information) 

* Level 4 menu is used to flash temp (prompt whether to modify the temperature switch)   

* Level 5 menu reserved

*10-level menu for flashing hour digits                       

*Level 11 menu for flashing minute digits

*12-level menu for flashing seconds                         

*13-level menu is used to flash the year position

*14-level menu is used to flash the moon position                          

*15-level menu for flashing day position

*16-level menu for flashing alarm 1 switch                  

*17-level menu is used to flash the time position of the alarm clock

*18-level menu for flashing alarm 1 minute position                

*19-level menu for flashing temperature switch

*20-level menu for flashing alarm 1 and alarm 2 selection bits          

* Level 21 menu is used to turn on and off the flashing alarm 2

* Level 22 menu is used to flash the time position of alarm 2               

* Level 23 menu is used to flash the second minute position of the alarm clock

*

*

* Completion date: 2019.12.25

************************************************************************************************************/


void caidan()

{

        zhuanhuan(); //Get time information

        naozhong(); //Detect alarm clock

        if(cd==0)//0 level menu

        {

                if(ms4>0&&ms4<10000) xianshi(shijian[6],shijian[7],27,shijian[8],shijian[9],27,shijian[10],shijian[11]);

    if(ms4>10000&&ms4<10100)         wendu=DS18b20ReadTemp();                

                if(ms4>10100&&ms4<15000) xianshi(2,0,shijian[0],shijian[1]+17,shijian[2],shijian[3]+17,shijian[4],shijian[5]);

                if(wendu_kaiguan==0&&ms4>15000) ms4=0;

                if(ms4>15200&&ms4<20000) xianshiwendu();         

                if(ms4>20000) ms4=0;

                if(anjian1==0&&aj1==0)

                {

                        delay(5);

                        if(anjian1==0) aj1=1;

                }

                if(anjian1==1&&aj1==1) aj1=0,cd=1,ms1=0; //Press and release button 1 to go to level 1 menu        

        }

        if(cd==1) //1st level menu flashes all the time

        {

                if(ms1>0&&ms1<300) xianshi(shijian[6],shijian[7],27,shijian[8],shijian[9],27,shijian[10],shijian[11]);

                if(ms1>300&&ms1<600)  xianshi(28,28,27,28,28,27,28,28);

                if(ms1>600) ms1=0;

                

                if(anjian1==0&&aj1==0)//Detect key 1

                {

                        delay(5);

                        if(anjian1==0) aj1=1;

                }

                if(anjian1==1&&aj1==1) aj1=0,cd=2,ms1=0; //Press and release button 1 to go to level 2 menu

                

                if(anjian2==0&&aj2==0)//Detect key 2

                {

                        delay(5);

                        if(anjian2==0) aj2=1;

                }

                if(anjian2==1&&aj2==1) 

                {

                        tiaozheng[0]=shijian[0];

                        tiaozheng[1]=shijian[1];

                        tiaozheng[2]=shijian[2];

                        tiaozheng[3]=shijian[3];

                        tiaozheng[4]=shijian[4];

                        tiaozheng[5]=shijian[5];

                        tiaozheng[6]=shijian[6];

                        tiaozheng[7]=shijian[7];

                        tiaozheng[8]=shijian[8];

                        tiaozheng[9]=shijian[9];

                        tiaozheng[10]=shijian[10];

                        tiaozheng[11]=shijian[11];

                        aj2=0;

                        cd=10;

                        ms1=0; //Press and release button 2 to go to level 10 menu

                }

        }

        

        if(cd==2) //Level 2 menu flashes all dates

        {

                if(ms1>0&&ms1<300) xianshi(2,0,shijian[0],shijian[1]+17,shijian[2],shijian[3]+17,shijian[4],shijian[5]);

                if(ms1>300&&ms1<600)  xianshi(28,28,28,29,28,29,28,28);

                if(ms1>600) ms1=0;

                

                if(anjian1==0&&aj1==0)//Detect key 1

                {

                        delay(5);

                        if(anjian1==0) aj1=1;

                }

                if(anjian1==1&&aj1==1) aj1=0,cd=3,ms1=0; //Press and release button 1 to go to level 3 menu

                

                if(anjian2==0&&aj2==0)//Detect key 2

                {

                        delay(5);

                        if(anjian2==0) aj2=1;

                }

                if(anjian2==1&&aj2==1)

                {

                        tiaozheng[0]=shijian[0];

                        tiaozheng[1]=shijian[1];

                        tiaozheng[2]=shijian[2];

                        tiaozheng[3]=shijian[3];

                        tiaozheng[4]=shijian[4];

                        tiaozheng[5]=shijian[5];

                        tiaozheng[6]=shijian[6];

                        tiaozheng[7]=shijian[7];

                        tiaozheng[8]=shijian[8];

                        tiaozheng[9]=shijian[9];

                        tiaozheng[10]=shijian[10];

                        tiaozheng[11]=shijian[11];


                        aj2=0;

                        cd=13;

                        ms1=0; //Press and release button 2 to go to level 13 menu

                }

        }

        if(cd==3) //Level 3 menu displays the alarm clock

        {

                if(ms1>0&&ms1<300)        xianshi(27,27,27,30,31,27,27,27);

                if(ms1>300&&ms1<600)  xianshi(27,27,27,28,28,27,27,27);

                if(ms1>600) ms1=0;

        

                 if(anjian1==0&&aj1==0)//Detect key 1

          {

                  delay(5);

                  if(anjian1==0) aj1=1;

          }

          if(anjian1==1&&aj1==1) aj1=0,cd=4,ms1=0; //Press and release button 1 to go to level 4 menu

                

                if(anjian2==0&&aj2==0)//Detect key 2

                {

                        delay(5);

                        if(anjian2==0) aj2=1;

                }

                if(anjian2==1&&aj2==1)

                {

                        aj2=0;

                        cd=20;

                        dunaozhong(); //Read alarm data

                        ms1=0; //Press and release button 2 to go to level 20 menu

                }

        }

        

        if(cd==4) //Level 4 menu displays temp temperature

        {

                if(ms1>0&&ms1<300)        xianshi(27,27,32,33,34,33,27,27);

                if(ms1>300&&ms1<600)  xianshi(27,27,28,28,28,28,27,27);

                if(ms1>600) ms1=0;

                

                if(anjian1==0&&aj1==0)//Detect key 1

          {

                        

                  delay(5);

                  if(anjian1==0) aj1=1;

          }

          if(anjian1==1&&aj1==1) aj1=0,cd=0,ms1=0; //Press and release button 1 to go to level 0 menu

                

                if(anjian2==0&&aj2==0)//Detect key 2

                {

                        delay(5);

                        if(anjian2==0) aj2=1;

                }

                if(anjian2==1&&aj2==1)

                {

                        aj2=0;

                        cd=19;

                        wendu_kaiguan=IapRead(0x0800);

                        ms1=0; //Press and release button 2 to go to level 19 menu

[1] [2] [3] [4] [5] [6] [7] [8] [9]
Reference address:Design of 51 single chip microcomputer intelligent clock

Previous article:Stepper Motor Control and Simulation Based on 51 Single Chip Microcomputer
Next article:51 MCU 12864 display electronic password lock source code

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号