当前位置:网站首页>Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data

Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data

2022-04-23 14:24:00 Jiang Yuzhi

Get the full set of resources , Please refer to the following description ~

The design requirements
1. Display Gregorian calendar year 、 month 、 Japan 、 week 、 when 、 branch 、 second ;
2. The year can be adjusted at any time 、 month 、 Japan 、 when 、 branch 、 second ;
3. It can display the time of the lunar calendar , And can mark the year of pingrun ;
4. With alarm clock setting reminder function ;
5. Able to display the current ambient temperature ;

Design Overview
The electronic perpetual calendar system is based on AT89C52 MCU as the core , Constitute a single-chip microcomputer control circuit , combination DS1302 Clock chip and DS18B20 Temperature sensor , Complete the reading of time and temperature , All information is provided by LCD1602 LCD real-time display .

The calibration of calendar time and the setting of alarm clock are realized by four independent keys , The calendar can show the year of the Gregorian calendar and the lunar calendar 、 month 、 Sunday and Sunday 、 when 、 branch 、 second , When the lunar year is displayed , It can also indicate the year of pingrun .

The whole system consists of the following modules , As shown in the figure below .
 Insert picture description here
Schematic diagram
 Insert picture description here
Simulation circuit diagram
 Insert picture description here
 Insert picture description here
Analysis of simulation results
open Proteus Simulation file , File suffix DSN. Double click the MCU , load WanNianLi.hex file ( be located Keil C In the program folder ), Run the simulation , The results are shown in the following figure .
 Insert picture description here
As you can see from the picture above ,LCD The displayed time information is similar to DS1302 Clock-U3 The windows are exactly the same , It shows that the single chip microcomputer successfully reads DS1302 Chip data . Current date is 2020 year 10 month 9 Sunday, Friday , Time is 21 spot 30 branch 39 second , The temperature is 31.0℃.

Set the time to : Click on “ Set up ” key , The second hand flashes , At this time, you can use the “ Add the key ” and “ Minus the key ” Increase or decrease adjustment , The second hand setting is shown below .
 Insert picture description here
After setting the second hand , Click again on the “ Set up ” key , The minute hand flickers , Continue to set through the plus and minus keys , And so on , To set the hours 、 Japan 、 Month and year , year ( The range can reach 2099 year ) After setting up , Press again “ Set up ” key , Exit time , go back to LCD Normal display interface .

Click on “ Lunar calendar / alarm clock ” Key , Displays the lunar date of the current date , And pingrun year ( Ordinary year :PING Leap year :RUN), As shown in the figure below , Gregorian calendar 2020 year 10 month 9 The lunar day corresponding to the day is 8 month 23, And 2020 A year is a leap year , The conversion information of Gregorian calendar and lunar calendar is accurate .
 Insert picture description here
Click again on the “ Lunar calendar / alarm clock ” key , Display the alarm time , And the switch state of the alarm clock (ON: Indicates that the alarm clock is on ,OFF: Indicates that the alarm clock is off ), The default alarm time of the system in the figure is 01:01, The alarm clock is on ON.
 Insert picture description here
Set the alarm operation to : Under the current alarm clock display interface , Click on “ Set up ” key , The hours of the alarm clock blink , adopt “ Add the key ” and “ Minus the key ” Adjust the number of hours , When the hours are set , Click again on the “ Set up ” key , Minutes flashing , Enter the setting of minutes .

Empathy , After the minutes are set , Click again on the “ Set up ” key , It should be noted that , When setting the alarm switch , No cursor blinks . Click on “ Add the key ” or “ Minus the key ”, Set the alarm clock on and off ,ON And OFF Switch between .

After all the above are set up , Click again “ Set up ” key ,ON or OFF A flash , Indicates that the alarm clock is set . Now press “ Lunar calendar / alarm clock ” Press the key to exit the alarm clock interface , Return to the interface of normal time display .

for example , Set the alarm time to morning 8:30, Alarm clock on , Status as ON, give the result as follows .
 Insert picture description here
When the alarm clock is timed , The buzzer makes a sound , The alarm clock rings ; The alarm clock can be set by clicking “ Add the key ” or “ Minus the key ” or “ Lunar calendar / alarm clock ” Key to close .

By clicking on DS18B20 The red color of the module is upward 、 down arrow , It can simulate the change of temperature ,LCD The liquid crystal displays the current temperature value in real time . For example, set the temperature 22.0℃, As shown in the figure .
 Insert picture description here
in summary , Electronic perpetual calendar Proteus The running effect of simulation design meets the design requirements .

part C Code

void main()
{
    
	init_eeprom();  // Start initializing the saved data 
	P1=0xff;
// flag=ReadTemperature();
// delay(2000);
	lcd_init();      // Call the LCD initialization sub function 
	ds1302_init();   // call DS1302 Initialization sub function of clock 
	init();          // Call the setting sub function of the timing counter 
	led1=0;           // open LCD Backlight power supply 
    buzzer=0;		 // The buzzer rings for a long time 
    delay(100);
    buzzer=1;
	init_eeprom();
	while(1)  // Infinite loop the following statement :
	{
    		
   	 	keyscan();      // Call the keyboard scanning sub function 
		led=led1;		
		if(timerOn==1)
			alarm();	// Alarm output 
		if((fen==0)&&(miao==0))
		{
    
			if(shi>12)
				temp_hour=shi-12;
			else
			{
    
				if(shi==0)
					temp_hour=12;
				else
					temp_hour=shi;
			}
			shangyimiao=miao;
			baoshi=1;
		}
		if(baoshi==1)
		{
    
			ZD_baoshi();
			do 
				keyscan();
			while(shangyimiao==miao);	
			shangyimiao=miao;
		}
    }
}
void timer0() interrupt 1  // Get and display calendar and time 
{
    
   //Init_DS18B20();// Temperature sensor DS18b2 Initialize sub functions , In the header file 
// flag=ReadTemperature();// take 18b2 The result of the function returned by the header file is sent to the variable FLAG in , Used for display 

  // Read seven data of week, day, month and year in seconds (DS1302 The read register is different from the write register ):
	
    miao = BCD_Decimal(read_1302(0x81));
	fen = BCD_Decimal(read_1302(0x83));
	shi  = BCD_Decimal(read_1302(0x85));
	ri  = BCD_Decimal(read_1302(0x87));
	yue = BCD_Decimal(read_1302(0x89));
	nian=BCD_Decimal(read_1302(0x8d));
	//week=BCD_Decimal(read_1302(0x8b)); // Don't read , Calculated directly from the date 
	if((led1==0))
	{
    
		if(temp_miao!=miao)
		{
    
			temp_miao=miao;
			bltime++;
		}
		if(bltime==10)
		{
    
			led1=1;
			bltime=0;
		}
	}


    if(T_NL_NZ==1)							// Show the lunar calendar 
	{
    
		uint nian_temp,temp12;
		temp12=nian;
		nian_temp=2000+(temp12&0xF0)*10+temp12&0x0F;
		if((nian_temp%400==0)||((nian_temp%100!=0)&&(nian_temp%4==0)))  // Determine if it's a leap year 
			p_r=1;
		else
			p_r=0;
		Conversion(0,nian,yue,ri);
		write_1602com(er);// Time shows the writing position of the fixed symbol ?
		for(a=0;a<16;a++)
		{
    
			if(p_r==0)
				write_1602dat(nlp[a]);// Write and display time fixed symbol , Two colons 
			else 
				write_1602dat(nlr[a]);
		}

	  	write_nl(3,year_moon);// Lunar calendar   year 
		write_nl(6,month_moon);// Lunar calendar   month 
		write_nl(9,day_moon);// Lunar calendar   Japan 

		do
			keyscan();
		while(T_NL_NZ==1);

		write_1602com(er);// Time shows the writing position of the fixed symbol , From 2 Start displaying... After the first position 
		for(a=0;a<16;a++)
		{
    
			write_1602dat(qk[a]);// Write and display time fixed symbol , Two colons 
		}

		write_1602com(er);// Time shows the writing position of the fixed symbol , From 2 Start displaying... After the first position 
		for(a=0;a<8;a++)
		{
    
			write_1602dat(tab2[a]);// Write and display time fixed symbol , Two colons 
		}
	}

The shared resources are

(1) be based on 51 MCU electronic calendar design paper complete version ;
(2)Altium Designer Schematic file ;
(3)Keil C Program ;
(4)Proteus Simulation file ;
(5)Visio Program design flow chart ;
(6) Design assignment ;
(7) Chip technology manual ;
(8) List of components ;
(9) Introduction to component knowledge ;

The full set of resources is as follows
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
Important things are to be repeated for 3 times !!!

Important things are to be repeated for 3 times !!!

Important things are to be repeated for 3 times !!!

This design is my original , Obtain the full set of design data of the above electronic perpetual calendar design !

WeChat search for my official account : Jiaoyuan Xiaozhi

版权声明
本文为[Jiang Yuzhi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231412472069.html