Electronic clock made by 51 single chip microcomputer

Publisher:创新思绪Latest update time:2016-05-31 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I have recently started researching single-chip microcomputers, using the domestically produced STC98C52 chip.

STC89C52 is a low-power, high-performance CMOS 8-bit microcontroller produced by STC, with 8K in-system programmable Flash memory. STC89C52 uses the classic MCS-51 core, but has made many improvements to give the chip functions that traditional 51 microcontrollers do not have. With a smart 8-bit CPU and in-system programmable Flash on a single chip, STC89C52 provides highly flexible and super-effective solutions for many embedded control application systems.

I bought it a long time ago but it has been lying there all the time. Today I took it out again and wrote a C++ program for an electronic clock. It uses a power bank to power it and it is pretty good as an electronic clock.

Function:

    Four seven-segment digital tubes serve as the main body of the clock display, two showing hours, two showing minutes, eight LED lights flashing for seconds, and four independent buttons, namely hour+1, hour+10, minute+1, and minute+10.

Electronic clock made by 51 single chip microcomputer
     Query the LED circuit, the access terminals are P1^0 to P1^7.

Electronic clock made by 51 single chip microcomputer
                                      The digital tube uses a driver chip, and the access terminals are P2^0 to P2^3.

Electronic clock made by 51 single chip microcomputer
                                                                             The access end of the button is shown in the figure.

 

With access to various circuits, we use Keil for programming.

 

/*
* Copyright (c) 2015, School of Computer Science, Yantai University
* All rights reserved.
* Author: Shao Shuai
* File: temp.c
* Completion date: May 29, 2015
*/  
#include 
#define uchar unsigned char
sbit P2_0 = P2^0;
sbit P2_1 = P2^1;
sbit P2_2 = P2^2;
sbit P2_3 = P2^3;
sbit key1=P3^5; // press the button
sbit key2=P3^4;
sbit key3=P3^3;
sbit key4=P3^2;
static unsigned char second,minute,hour;
unsigned int tcount;
unsigned char m;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
                        0xf8,0x80,0x90};

void delay(uchar i)
{
  uchar j,k;
  for(j=i;j>0;j--)
    for(k=125;k>0;k--);
}

void display()
{

   P0=table[hour/10];
   P2_0 = 0;
   delay(5);
   P2_0 = 1;

   P0=(table[hour%10]& 0x7f);
   P2_1 = 0;
   delay(5);
   P2_1 = 1;

   P0=table[minute/10];
   P2_2 = 0;
   delay(5);
   P2_2 = 1;

   P0=table[minute%10];
   P2_3 = 0;
   delay(5);
   P2_3 = 1;
   
}

void main(void)
{
    unsigned int a;
	TMOD=0x02;
    TH0=0x06;
    TL0=0x06;
    TR0=1;
    ET0=1;
    EA=1;
   
 while(1)
 {
   	if(key1==0)
		{
			if(key1==0) //Confirm that the key is pressed
			{
				while(!key1);//release detection
			     hour++;
			}
	   
		}
		if(key2==0)
		{
			if(key2==0)	 
			{
				while(!key2);
			    hour=hour+10;
			}
		}
		if(key3==0)
		{
			if(key3==0)	
			{
				while(!key3);
				minute++;
			}
		}
		if(key4==0)
		{
			if(key4==0)	  
			{
				while(!key4);
				minute=minute+10;
			}
		}	
   for(a=100;a>0;a--)
   {
     display();
   }
 
 }
}

 void t0(void) interrupt 1 using 0
  {	
  tcount++;
    if(tcount==4000)
	  {tcount=0;
	    second++;
		 if(second==60)
		  {second=0;
		   minute++;
		    if(minute==60)
			 {minute=0;
			  hour++;

			  if(hour==24)
			   {hour=0;
			   }
			 }
		  }
		P1=~P1;
	  }
	}

 

 

Package it into a hex file and burn it.

Electronic clock made by 51 single chip microcomputer

 

Run the microcontroller!

Electronic clock made by 51 single chip microcomputer

 

I originally planned to use a Xiaomi box as the outer shell, but later I found that the box was a bit small, so I just used the bare machine first. Anyway, the 5V power supply cannot reach it.

 
Reference address:Electronic clock made by 51 single chip microcomputer

Previous article:51 single chip microcomputer drives stepper motor (double four beats and eight beats)
Next article:51 MCU T0 as precise clock

Latest Microcontroller Articles
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号