Communication between MCU and Serial Port 232 (Continued)

Publisher:BoldDreamerLatest update time:2016-01-13 Source: eefocusKeywords:MCU  Communication Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Purpose: After sending data through the serial port sending area, the serial port receiving area receives the sent data. //Note whether the serial port setting is hexadecimal or ASIIC code? If it is hexadecimal, the first data received is 00. If it is ASIIC, no data is displayed.

program:

#include
bit point=1;      //flag bit
unsigned char temp;
unsigned char i;

//---------------------------------------------------------
void init()      //Serial port initialization
{
 TMOD=0x20;
 SCON=0x50;
 TH1=0xfD;
 TR1=1;
 ES=1;
 EA=1;
}

//------------------------------------------------ -------------------------------
void send()
{
  SBUF=temp;
 while(TI==0);
   TI= 0;

}

//----------------------------------------------------------------------------------
void UART ()interrupt 4 //Serial communication interrupt

  if(RI==1)
   {
     RI=0;                                                               
     temp=SBUF;
     point=1;
     for(i=0;i<10;i++);
   }
}

//------------------------------------------------ -------------------------------------
void main()
{
  temp=0x00;
  init();
  while(1)
 {
   if(point==1)
   {
    point=0;
    send();
   }
 }
}

Keywords:MCU  Communication Reference address:Communication between MCU and Serial Port 232 (Continued)

Previous article:Why should the P0 port of AT89S51/52 be connected to a pull-up resistor?
Next article:MCU and 232 serial port communication

Recommended ReadingLatest update time:2024-11-16 13:50

MCU output C# lighting myth
This article was suddenly thought of by a friend while drinking coffee in Guangdong... I have been wanting to write a few blogs about microcontroller output recently, so I wrote them down as soon as I got home and published them.      Just like the Hello World of learning every programming language, lighting a lamp na
[Microcontroller]
Single chip LCD scrolling display (AT89C51, LCD1602)
1. Introduction This circuit is composed of AT89C51 minimum system and LCD1602 liquid crystal module. It can realize vertical scrolling, left and right scrolling and playback pause. 2. Implementation Effect Scroll up and down Scroll left and right 3. Code /*More projects in private!!!*/ #include reg52.h #includ
[Microcontroller]
Single chip LCD scrolling display (AT89C51, LCD1602)
Sound monitoring and wireless positioning system based on Atmega128L microcontroller
1. Choice of sound signal generation  The ATMEGA128L microcontroller generates a square wave with a frequency of 500Hz as a sound signal. The generation of the square wave signal is essentially to invert the state of the output I/O pin when the number of timer overflow interrupts reaches the specified number. The si
[Microcontroller]
Sound monitoring and wireless positioning system based on Atmega128L microcontroller
MCU machine number and encoding
script src="/jf/jf-arcMain-1.js" type=text/javascript /script script type=text/javascript /script script src="http://pagead2.googlesyndication .com/pagead/show_ads.js" type=text/javascript /script script src="http://pagead2.googlesyndication.com/pagead/js/r20110914/r20110914/show_ads_impl.js" /script script
[Microcontroller]
74HC595 driver control LED made by 51 single chip microcomputer
74HC595 driver control LED made by 51 single chip microcomputer The microcontroller code is as follows: #include reg51.h #include intrins.h sbit SRCLK=P3^6; sbit RCLK=P3^5; sbit SER=P3^4; void Hc595SendByte(unsigned char dat); void Delay10ms(unsigned int); void main() {         unsigned char ledNum;         l
[Microcontroller]
Use Proteus to learn the digital tube of 51 single chip microcomputer
Today we are learning how to use digital tubes and latches. The purpose of using latches is to reduce the use of IO ports. Originally, at least 15 IO ports were needed. After using latches, only 10 IO ports are needed. If more digital tubes are added, the number of IO ports will also increase one by one. The function
[Microcontroller]
Use Proteus to learn the digital tube of 51 single chip microcomputer
51 MCU-Timer-Countdown Alarm Clock
1. Video Bilibili video address: https://www.bilibili.com/video/av91943244 51 MCU-Timer-Countdown Alarm Clock 2. Documents Download the file: https://download.csdn.net/download/weixin_43130546/12194355 3. Description Note the KeyScan() function if statement! Buzzer frequency problem; I'll add more when I thi
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号