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.
Query the LED circuit, the access terminals are P1^0 to P1^7.
The digital tube uses a driver chip, and the access terminals are P2^0 to P2^3.
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.
Run the microcontroller!
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.
Previous article:51 single chip microcomputer drives stepper motor (double four beats and eight beats)
Next article:51 MCU T0 as precise clock
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- Four-bit parallel 9012 drive digital tube
- Design of Industrial Temperature Transmitter
- How to calculate the gain of this amplifier?
- Almost 10 years later, I started to work on C++ again
- Technical Article: Reliable Power-Up and Power-Down Sequencing
- What skills do embedded software development engineers need?
- What are switch quantity and analog quantity?
- ZigBee Wireless Soc EFR32MG Series 2 (MG21) Timer Features
- How does micropython concatenate strings received multiple times?
- 230 bought 2 crystal oscillators