How to display numbers on 7 segment display using 8051 microcontroller?
Source: InternetPublisher:张小哥 Keywords: Display 8051 microcontroller Updated: 2025/02/14
When using a single-chip microcomputer to develop a project, a 7-segment display is often used. The 7-segment display can display letters and numbers. It actually has a light-emitting LED inside. By controlling different interfaces, the internal LED lights are lit to display numbers. At present, it is used to display information in many electronic products, such as power banks, hair straighteners, etc.
The 7-segment display is constructed of 8 LEDs connected in a sequential manner to facilitate displaying the digits from 0 to 9 when certain combinations of LEDs are turned on. When lit, it displays only one digit at a time.
Schematic diagram of displaying numbers on a 7-segment display using an 8051 microcontroller:
The program to display numbers from "0 to F" on a 7-segment display is:
#include< reg51.h > sbit a= P3^0; sbit x = P3^1; sbit y = P3^2; sbit z = P3^3; void main() { unsigned char m[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0xE00,0x10}; unsigned int i,j; a=x=y=z=1; while(1) { for(i=0;i<10;i++) { P2=m[i]; for(j=0;j<60000;j++); } } } The program to display numbers from "00 to 10" on a 7-segment display is: #include< reg51.h > sbit x = P3^0; sbit y = P3^1; void display1(); void display2(); void delay(); void main() { unsigned char m[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0xE00,0x10}; unsigned int i,j; ds1=ds2=0; while(1) { for(i=0,i<20;i++) display1(); display2(); } } void display1() { x=1; y=0; P2=m[ds1]; delay(); x=1; y=0; P2=m[ds1]; delay(); } void display2() { ds1++; if(ds1 >=10) { ds1=0; ds2++; if(ds2 >=10) { ds1=ds2=0; } } } void delay() { unsigned int k; for(k=0;k<30000;k++); }
- An article explains the undervoltage reset of the microcontroller
- What are the functions of microcontrollers for IoT?
- How to connect ADC to 8051 microcontroller?
- What is the difference between RISC-V, ARM and x86 microprocessors?
- How to Interface PCF8591 ADC Module with Raspberry Pi
- How to Program an Arduino via Bluetooth
- SN75370 Dual MOS Memory Interface Circuit
- Interface circuit composed of 74LS164 and 8051 microcontroller
- Using 89C2051 to make a four-way digital display water level controller circuit
- Use PC’s RS232 port to control LED lights
- Spectrum display with memory function (b)
- Spectrum display with memory function (a)
- 60 seconds display circuit
- Using cathode ray tubes as display drive circuits
- 5-digit electromechanical display control circuit
- Power supply circuit diagram of CASPER CM-1489 dual-band monochrome display
- CXS-78A type transistor bed display circuit
- Priority encoder for keyboard encoding and decoding display
- Cycle counter display
- Pulse sound and light display circuit