//***********************************
// LED digital display electronic clock
//***************************************
//***********************************
//Programming ideas:
//Use timer interrupt type digital tube dynamic scanning.
//Because the timekeeping part requires more precision, the timer automatic loading type is adopted, and timer 2 is used as the second generator, because timer 2 can be set to 16 bits for automatic loading,
#include
#include
#define uchar unsigned char
sure_time (void);
bit dis;
uchar code LED_DATA[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //0~9 digital data
uchar data DATA_TEMP[8]; //Display buffer area, display 00-00-00 when booting
uchar data digit; //Shift variable (for dynamic scanning)
static uchar data t,k,i;
static uchar data sec=0,min=55,hour=22;
main ()
{
TMOD=0X01; //Timer 0
ET0=1; //Open timer 0 interrupt
EA=1; //Open general interrupt
TH0=0XFC; //Timer 0 timing 1ms
TL0=0X18;
TR0=1; //Start timer
RCAP2H=0X3C; //Timer 2 timing 50ms
RCAP2L=0XB0;
ET2=1;
TR2=1;
digit=0xfe;
P3=0XFF; //Close display
sure_time ();
DATA_TEMP[2]=0XBF;
DATA_TEMP[5]=0XBF;
while (1)
{
}
}
void displayscanf (void) interrupt 1 //dynamic display scanning function
{
TH0=0XFC;
TL0=0X18;
P0=DATA_TEMP[i];
i++;
P3=digit;
digit=_crol_(digit,1);
if (i>7)
{
i=0;
digit=0xfe;
}
}
void timer_server (void) interrupt 5 //Clock timing
{
TF2=0;
t++;
if (t==20)
{
t=0;
sec++;
if (sec>59)
{
sec=0;
min++;
if (min>59)
{
min=0;
hour++;
if (hour>23) hour=0;
DATA_TEMP[1]=LED_DATA[hour%10];
DATA_TEMP[0]=LED_DATA[hour/10];
}
DATA_TEMP[4]=LED_DATA[min%10];
DATA_TEMP[3]=LED_DATA[min/10];
}
DATA_TEMP[7]=LED_DATA[sec%10];
DATA_TEMP[6]=LED_DATA[sec/10];
}
}
sure_time (void) //Initialize the time and update the data in the DATA_TEMP array
{
DATA_TEMP[1]=LED_DATA[hour%10];
DATA_TEMP[0]=LED_DATA[hour/10];
DATA_TEMP[4]=LED_DATA[min%10];
DATA_TEMP[3]=LED_DATA[min/10];
DATA_TEMP[7]=LED_DATA[sec%10];
DATA_TEMP[6]=LED_DATA[sec/10];
}
Previous article:Digital tube scrolling display of numbers... (C program)
Next article:Design of frequency measurement system based on AT90S8515
Recommended ReadingLatest update time:2024-11-16 21:49
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Kuyuan Electric Allegro video training
- What are the differences between precision op amps, instrument op amps, and general-purpose op amps?
- TI Engineer's Annual Review: Selected Q&A on Amplifiers, Interface/Clocking, and More
- Ten key takeaways about the Internet of Things
- Assisting RF chip testing
- Synchronous Rectification and Synchronous Boost
- TEC Controller
- Has anyone seen this usage in C language?
- I would like to ask about the problem of the flyback power supply making noise when the load is small
- Allwinner heterogeneous multi-core AI intelligent vision V853 development board evaluation - repo installation error solution