The 8051 microcontroller serial port receives characters and displays their ASCII codes (less than 100) on the digital tube.

Publisher:AlisallllLatest update time:2021-08-04 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include <STC89C5xRC.H>

 

unsigned char code DIG_CODE[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};

 

char buf;

 

void delay()//provide delay

{

int i, j;

for(i = 0; i < 15; i ++)

for(j = 0; j < 15; j ++)

;

}

 

void disp_digit(char d)

{

//Display the single digit

P0 = DIG_CODE[d % 10];

P2 = 0; // 0000 0000 -> (P24, P23, P22) = (0, 0, 0) -> The first digit from the right is lit

delay();

//Display ten digits

P0 = DIG_CODE[d / 10];

P2 = 1 << 2; // 0000 0100 -> (P24, P23, P22) = (0, 0, 1) -> The second digit from the right is lit 

delay();

}

 

void UART_INT() interrupt 4 //UART中断

{

if(RI == 1)

{

RI = 0;

buf = SBUF;

}

}

 

int main()

{

TMOD = 0x21; //Set the working mode of timer1

SCON = 0x50; //Set serial communication format

TH1 = 0xE6; //Set the initial value of timer1

TL1 = 0xE6; 

IE = 0x90; // Main switch closed (EA) + serial port interrupt switch closed (ES)

TR1 = 1; //Start timer1

while(1)

{

disp_digit(buf);

}

return 0;

}


Reference address:The 8051 microcontroller serial port receives characters and displays their ASCII codes (less than 100) on the digital tube.

Previous article:8051 MCU implements a single countdown timer with modifiable initial value (and command to start and stop)
Next article:8051 MCU realizes serial communication in polling mode (51 receives data and sends it back to PC)

Recommended ReadingLatest update time:2024-11-15 11:30

8051 MCU Basics 5: Data Type Occupancy Size and Value Range
References: Keil Help uVision Help Cx51 Compiler User's Guide Language Extensions Data Types Keil Help uVision Help Arm Compiler 5 User's Guides Compiler User Guide C and C++ Implementation Details When using variables in C language, you need to define the data type first. After defining the data type, the
[Microcontroller]
8051 MCU Basics 5: Data Type Occupancy Size and Value Range
Implementation of 8051 microcontroller int byte
When using a microcontroller, unsigned int occupies 2 bytes and unsigned char occupies one byte. The microcontroller implements byte addressing. 16-byte bit addressing is really difficult to use. It's not easy to use because you can't create an array. In the actual development process, DPTR must be used, as well as
[Microcontroller]
Implementation of 8051 microcontroller int byte
Variable speed temperature control system based on 8051
The 8051 is used as the core component to form a variable speed temperature control system, which can adapt to special temperature curves, and different software systems can adapt to different process requirements, with good portability and expansibility. This paper gives the overall design of the system hardware and
[Microcontroller]
Design of Waveform Generator Based on C8051F410
Most of this program is official information from Xinhualong Company. I have modified it slightly, simplified a lot of codes, and added several waveforms. You can switch by just pressing the P1.4 key. //----------------------------------------------------------------------------- // F41x_DACs_SineCosine.c //----------
[Microcontroller]
Design of air flow meter with C8051F microcontroller as the control core
introduction The cotton airflow meter studied in this project is based on the relevant provisions of the GB6468-1992 cotton fiber "micronaire" test method, combined with the current microcomputer monitoring system technology, and uses the single-chip computer C8051F, which has the characteristics of fast testing speed
[Microcontroller]
Design of air flow meter with C8051F microcontroller as the control core
Reset state of 8051 microcontroller
  Reset means to make some resources inside the microcontroller a fixed initial state by some means, so as to ensure that the microcontroller can start running from a fixed entry address in a fixed environment every time it is reset. The status of the special function registers in the 8051 chip after reset is as follo
[Microcontroller]
Reset state of 8051 microcontroller
Introduction to the usage of 8051 microcontroller instruction system
A computer's instruction set is the collection of all instructions it can execute. The 8051 instruction system has a total of 111 instructions, which are composed of 42 mnemonics and 7 addressing modes. 8051 instructions usually include two parts: opcode and operand. The opcode specifies what operation the instructi
[Microcontroller]
Introduction to the usage of 8051 microcontroller instruction system
Application scheme for designing ring coil vehicle detector based on C8051F121 chip
1 Introduction With the accelerated development of my country's transportation infrastructure construction, traffic volume is growing rapidly, followed by road congestion and air pollution. and the harm caused by traffic accidents. In order to alleviate road congestion, improve travel conditions and improve road safet
[Microcontroller]
Application scheme for designing ring coil vehicle detector based on C8051F121 chip
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号