#include
#define PORTLEN P0
sbit bit_select = P2^0;
sbit seg_select = P2^1;
unsigned char src[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f ,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char qrc [8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; unsigned
char second1[8];
shi = 0;
unsigned char fen = 0;
unsigned char miao = 0;
void timer0_init(void)
{
EA = 1;
TMOD |= 0x01;
TH0 = (65536 - 1000) / 256;
TL0 = (65536 - 1000) % 256; //Set the initial value of timer T0, generate an interrupt once every 1ms
ET0 = 1; //Open Timer T0 interrupt
TR0 = 1; //Turn on timer T0 and start adding 1 every 1ms
}
void timer1_init(void)
{
EA = 1;
TMOD |= 0x10;
TH1 = (65536 - 1000) / 256;
TL1 = ( 65536 - 1000) % 256; //Set the initial value of timer T1, generate an interrupt every 1ms
ET1 = 1; //Turn on timer T1 interrupt
TR1 = 1; //Turn on timer T1, start adding 1 every 1ms
}
void main()
{
timer0_init();
imer1_init();
while(1);
}
void display()//Dynamic display clock
{
static unsigned char i = 0;
PORTLEN = 0x0; // Eliminate ghosting
seg_select = 1;
seg_select = 0;
PORTLEN = 0xff;
bit_select = 1;
bit_select = 0;
PORTLEN = second1[i];
seg_select = 1;
seg_select = 0;
PORTLEN = qrc[i];
bit_select = 1;
bit_select = 0;
i++;
if(8 == i)
{
i = 0;
}
}
void timer0_isr() interrupt 1
{
static unsigned char i = 0;
TH0 = (65536 - 20000) / 256;
TL0 = (65536 - 20000) % 256; //Set the initial value of the timer to generate an interrupt every 20ms
i++;
if(50 == i) //Count down to 1s
{
i = 0;
miao++;
if(60 == miao)
{
miao = 0;
fen++;
if (60 == fen)
{
fen = 0;
shi++;
if(24 == shi)
{
shi = 0;
}
}
}
}
second1[0] = src[shi / 10]; // Assign values to each digit of the digital tube
second1[ 1] = src[shi % 10];
second1[2] = 0x40;
second1[3] = src[fen / 10];
second1[4] = src[fen % 10];
second1[5] = 0x40;
second1[ 6] = src[miao / 10];
second1[7] = src[miao % 10];
}
void timer1_isr() interrupt 3
{
TH1 = (65536 - 1000) / 256; re-initialize
TL1 = (65536 - 1000) % 256;
display();
}
Previous article:Realizing a Rectangular Wave Generator Using a Single Chip Microcomputer
Next article:Microcontroller Experiment - Using Timer to Generate Square Wave
Recommended ReadingLatest update time:2024-11-16 11:27
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
- Introduction and working principle of humidity sensitive capacitor (humicap)
- An electric mosquito swatter actually has so many circuits. Have you learned all of them?
- Web page control 430 single chip microcomputer
- Bicycle modification series: code table
- Huawei's internal hardware development and design process
- Sharing the basics of power management
- Power conversion assistance
- DM8168 DSP and ARM add library and call
- (A-Current Signal Detection Device) Tianjin First Prize_Topic A
- 3. Lighting Case and Extension