Convert the long integer variable sec into a single-byte BCD code and store it in the display buffer array
unsigned char a[10];
void long_to_bcd(unsigned long sec)
{
a[0] = sec % 10; // Get the ones digit
a[1] = sec / 10 % 10; // Get the tens digit
a[2] = sec / 100 % 10; // Get the hundreds digit
a[3] = sec / 1000 % 10; // Get the thousands digit
a[4] = sec / 10000 % 10; // Get the ten thousand digit
a[5] = sec / 100000 % 10; // Get the hundred thousand digit
a[6] = sec / 1000000 % 10; // Get the million digit
a[7] = sec / 10000000 % 10; // Get the ten million digit
a[8] = sec / 100000000 % 10; // get the billionth digit
a[9] = sec / 1000000000 % 10; // get the billionth digit
}
Reference address:The most commonly used Long variable to BCD code
unsigned char a[10];
void long_to_bcd(unsigned long sec)
{
a[0] = sec % 10; // Get the ones digit
a[1] = sec / 10 % 10; // Get the tens digit
a[2] = sec / 100 % 10; // Get the hundreds digit
a[3] = sec / 1000 % 10; // Get the thousands digit
a[4] = sec / 10000 % 10; // Get the ten thousand digit
a[5] = sec / 100000 % 10; // Get the hundred thousand digit
a[6] = sec / 1000000 % 10; // Get the million digit
a[7] = sec / 10000000 % 10; // Get the ten million digit
a[8] = sec / 100000000 % 10; // get the billionth digit
a[9] = sec / 1000000000 % 10; // get the billionth digit
}
Previous article:Single LED indicator flashing control
Next article:Common algorithms for microcontroller data collection
- Popular Resources
- Popular amplifiers
- STC MCU Principles and Applications: Analysis and Design from Devices, Assembly, C to Operating Systems: A Three-Dimensional Tutorial (He Bin)
- Introduction to CodeVisionAVR C language library functions
- Introduction to AVR Common Library Functions
- Data Communication and Networking Tutorial Abbreviations
Latest Microcontroller Articles
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
MoreDaily News
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
Guess you like
- Hey guys, I can't find the following libraries on Cadence's Psipce
- First look at Texas Instruments' C2000 series
- MCU serial port sends data frame
- [Project source code] Digital tube companion - binary to BCD
- Talk about the method of suppressing the self-excited howling of the microphone
- 【CLUE】Programming with CircuitPython
- Uncover the mystery of MOS tube damage! What other reasons do you know?
- Let's discuss whether GaN materials are a key technology in 5G applications.
- FPGA Basics (I)
- Sensortile.box