This is a program from the 51hei development board area. The comments are very detailed and there is no problem running it. The original address is: http://www.51hei.com/bbs/dispbbs.asp?boardid=10&id=4140
/*The design idea of dynamic digital display is that we first need to know how to make which bit light up and what the displayed segment is. The next
step is the interruption time. The design steps are as follows. If we want the eight digital tubes to display 1 to 8 statically, we can modify the interruption time, such as changing 50000 to 100 or lower*/
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit duan=P2^6;
sbit wei=P2^7;
uchar a,numw,numd;
uchar code tabled[]={
0x3f,0x06,0x5b,0x4f,0x66
, 0x6d,0x7d,0x07,0x7f,0x6f}; /*The second step is to create a code table for the segment display values 0~9. If you want to display values 1~8, it is best to add the two digits 0 and 9 before and after,
because when the ++ is shifted later, it can light up in our regular order. As for how to display the corresponding values, please see the digital display circuit diagram first*/
uchar code tablew[]={
0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f}; //The second step is to create a bit display, that is, the display position. This code table is relatively simple. It is represented by binary 11111110~01111111, and 0 is the position of the eight-digit display tube.
void main()
{
a=0; //Define a time function
numl=0; //The initial value of the attached bit display is 0
numd=0; //The initial value of the attached segment display is 0
TMOD=0X01; //The fourth step, attach the initial value of the interrupt register
TH0=(65535-50000)/256; //Attach the initial value of the interrupt request time, the high 8 bits
TL0=(65536-50000)%256; //Attach the initial value of the interrupt request time, the low 8 bits
EA=1; //Turn on the total interrupt
ET0=1; //Turn on the timer interrupt
TR0=1; //Start the timer interrupt
while(1)
{
if(a==10) //The third step, execution speed, if 20 is almost 1 second, then execute the next step, which is equivalent to the time when the unit value is on
{
a=0; //Re-attach the initial value 0
numd++; //Segment display value++
if(numd==9) //If the segment value is in the 9th position of the matching code table, then execute
the next step
numd=1; /*Re-append the first bit of the segment display value to the corresponding code table. Because of ++, the 0th bit is not displayed in the digital tube.
If it is to be displayed, it will be displayed in the second round because of ++*/
duan=1; //Open the segment display terminal
P0=tabled[numd];//Append the segment display P0 value to the segment display value code table
duan=0; //Latch
wei=1; //Open the bit display terminal
P0=tablew[numw];//Append the bit display P0 value to the bit display value code table
wei=0; //Latch
numw++; //Equivalent to bit display shift
if(numw==8) //If the bit display value reaches the eighth bit of the corresponding bit display code table, then execute
numw=0; //Re-append the bit display value to the corresponding code table from the 0th bit
/*
The following is a simple single digital tube display example in the first step. After modification, in the third step
#include "reg52.h"
#include "intrins.h"
sbit duan=P2^6; //segment display port
sbit wei=P2^7; //bit display port
void main()
{
//P0=0xff; The digital tube does not display any signal. By default, it does not display when powered on, so
duan=1 is not required; //Open the segment display port
P0=0x06; //The value of the valued segment display is 1. You can refer to the code table corresponding to the display in the digital tube circuit diagram
duan=0; //Latch, keep the previous segment display state, please refer to the 74HC573 function for hardware description
wei=1; //Open the bit display port
P0=0xfe; //The valued bit display position, 01111111, the first bit on the left, is displayed as 0
wei=0; //Latch, keep the previous bit display state, please refer to the 74HC573 function for hardware description
}
*/
}
}
}
void timer0() interrupt 1 /*The fourth step, the interrupt time function is equivalent to the speed of shifting
the digital display. If the speed is fast enough, the human eye will have an afterglow effect, and it feels that the 8-digit display is always on, which is equivalent to the film being played*/
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
}
/*
If there is anything that needs to be improved, please let me know.
*/
Previous article:Smart timing socket program
Next article:Learning infrared remote control assembly language program
- 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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- Let's discuss: How to debug the appropriate parameters of this RC
- Simple MicroPython IoT Smart Home (ESP8266)
- Ultrasonic standing wave axial suspension mobile device word supplementary materials
- With the explosion of 5G, the future development of Wi-Fi is promising
- Questions about the two array forms of LSM6DSO FSM gesture recognition?
- What are the advantages and disadvantages of complementary push-pull H-bridge (2 NMOS + 2 PMOS) and totem pole H-bridge (4 NMOS), and their applications...
- The problem of turning frequency in LC filter circuit design
- Live broadcast at 10 am today [The rapid growth of Renesas RA MCU family members helps build safe and stable industrial control systems]
- Evaluation Weekly Report 20220411: GigaDevice's value-for-money MCU F310 is here, TI's heterogeneous multi-core AM5708 thousand yuan industrial board
- Program space issues