The simulation circuit diagram is as follows:
code show as below:
#include "reg51.h"
#define uint unsigned int
#define uchar unsigned char
uint code segcode[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D, 0x07, 0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
uchar code weicode[4]={0x0e,0x0d,0x0b,0x07};
uchar disbuf[4]={0,0,0,0}; //Define and initialize the digital tube data buffer
void delayms(uint x) //delay 1ms function
{
uchar i;
while(x--)
{
for(i=0;i<125;i++);
}
}
void usart_Init() //Serial interrupt initialization routine
{
TMOD=0x20;
TH1=0xfa;
TL1=0xfa; //Configure the serial port baud rate to 9600
SCON=0x50; //Set the serial port to work in mode 1, 8 data bits
PCON=0x80; //Configure baud rate multiplication
IE=0x90; // Enable interrupt
TR1=1; // Start the timer/counter
}
void segdisplay() //digital tube display function
{
uchar i;
for(i=0;i<4;i++)
{
P1=weicode[i];
P0=segcode[disbuf[i]];
delayms(1);
P0=0x00;
}
}
void main() //Main function
{
usart_Init() ; //Serial port initialization
while(1) { segdisplay(); } //CPU loops to execute display function
}
void usart_Int() interrupt 4 //Serial interrupt service routine
{
if(RI==1) //Judge whether it is a receive interrupt
{
uint temp; //Temporarily open up a memory space to store the received data
RI=0; //Set RI to 0 in time to prevent data loss
temp=SBUF; //Read the contents of the receive data buffer into the specified memory space
SBUF=temp; //Resend the input data to the host computer and echo it
while(TI==0);
TI=0; //Wait for sending to complete and reset TI
disbuf[3]=disbuf[1];
disbuf[2]=disbuf[0];
disbuf[1]=temp/0x10;
disbuf[0]=temp%0x10; //Modify the display buffer
}
}
After running the simulation, input the character '1', and the digital tube displays "31", as shown below:
Entering other characters in sequence will display their ASCII codes accordingly. When you enter the second character '2', the digital tube displays "3132"; when you enter the third character '5', the digital tube displays "3235" (the previous 31 is removed), and so on after entering characters continuously.
Previous article:Serial communication based on 51 single chip microcomputer (PC sends characters)
Next article:Serial port receiving and sending experiment - type the number **.* on the keyboard, and the PC will receive and display **.* in a loop
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Cadence creates a new component
- TMS320F28335 SVPWM source program
- A professor said that due to the needs of safety and stability, 8-bit microcontrollers are used on satellites. Is this true?
- Battle of MicroPython Forks
- [Project source code] FPGA-based snake transplantation
- 【Perf-V Review】Summary
- MOJO V3 ISE Engineering
- Using TI DLP technology to drive structured light systems for bin picking accuracy
- Help, AltiumDesigner suddenly doesn't work
- FPGA design pin allocation points.pdf