• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

8051 serial communication help

Status
Not open for further replies.

neo_himura

New Member
hi,
Im new to the microcontroller world. Im using AT89S51 (8051) microcontroller to receive data from PC. I know that microcontroller can receive one byte per cycle from serial port. Does anyone have example code to receive two bytes at the same time and put the data in two separate variable.
thnx
 

neo_himura

New Member
oo ic... how can i receive them one after the other and then put them in one variable. I need to receive data that is bigger than 255.
 

Ubergeek63

Well-Known Member
Yours is a UART question and not an 8051 question...it is the same as in any other chip-multiply the high byte by 256 and add it to the low byte.
 
Last edited:

Papabravo

Well-Known Member
Well if you have two bytes of RAM you put the first byte in one of them and the second byte in the other one. At some later time you can pick up the two pieces of data and treat them as a single number with a high byte and a low byte. It's the same for ANY 8-bit processor including the precious PIC and the equally precious AVR.
 

johankrava

New Member
Does anyone have example code to receive two bytes at the same time and put the data in two separate variable.
To receive two bytes at the same time you need two UARTs. Your uC (AT89S51) has only one hardware UART. You can make also a software UART but this code is much more complex.

On this page you have some simple code example for serial communication.
8051 serial code example
Please take some time and study it, check what instructions mean, how 8051 UART works and then you will understand how to write your own code.
 

sa11

New Member
oo ic... how can i receive them one after the other and then put them in one variable. I need to receive data that is bigger than 255.
If the value you want to send is more thatn 255 then it cant get fit in just 1 byte. Say for example you want to send 3123(decimal) = 0x0C33(hex)

On transmit side, send 1st byte (0x0C) and then 2nd byte (0x33)

On reception side

Receive 1st byte and save it in a variable
Receive 2nd variable and save it in another variable



For example,

unsigned char myVar[2] = {0};
unsigned int myInt = 0;

myVar[0] = GetUartByte();//results in myVar[0] = 0x0C
myVar[1] = GetUartByte();//results in myVar[0] = 0x33

myInt = myVar[0];//results in myInt = 0x000C
myInt = myInt << 8;//results in myInt = 0x0C00
myInt = myInt | myVar[1];//results in myInt = 0x0C33

I have tried to be very very simple in the approach.

Hope this helps
 

Wond3rboy

Member
If you are using assembly then its easy.Use any of R0 or R1 to point to a memory location and save the recieved data. Remember to increment them after every save.
To make things simple use R0 for the Low Order Byte and R1 for the High Order Byte.
 

Speakerguy

Active Member
Can't help you with 8051, it's mostly used in India and countries round there.
It is quite common in the US, SiLabs and TI both use them in their products extensively. I've seen TI Audio chips that use 8051's in them and several of their system on a chip products use them. Right now I am working with an SoC from them that has an RF transceiver, USB 2.0 interface, and an 8051 with a bunch of peripherals (ADC, temp sensor, etc).
 

silvarblade

Member
A lot of TI's stuff comes with a built in 8051 core uc. Nearly all their Zigbee Protocol devices.Although many would like it to be kept simple and the options open.
 
Last edited:

colin mac

New Member
The 8051 architecure had the biggest share in the market with 19%. PIC was 4th with 12%. ARM 5th with 10% and ATMEL AVR in 8th place with 3%.
 

Arjun_prrsad

New Member
refer

hi,
Im new to the microcontroller world. Im using AT89S51 (8051) microcontroller to receive data from PC. I know that microcontroller can receive one byte per cycle from serial port. Does anyone have example code to receive two bytes at the same time and put the data in two separate variable.
thnx
there is no way for that becasue 8951 or 8051 is a 8-bit processor u can't do that..refer a online book by mazidi......a famous author for micro-controller with c-language programming....jai ho
 

rushi53

Member
hi,
Im new to the microcontroller world. Im using AT89S51 (8051) microcontroller to receive data from PC. I know that microcontroller can receive one byte per cycle from serial port. Does anyone have example code to receive two bytes at the same time and put the data in two separate variable.
thnx
Hi,
you can not receive two bytes at the same time.
But you can write a program to receive two bytes after one another.
and then store them in two separate variable.

Please let me know if you need any help.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top