Discussion in "Project Help" started by    Pater    Apr 20, 2018.
Fri Apr 20 2018, 02:40 PM
#1
Actually I want to transmit 3 bits serially using AT89C51 micro-controller.

I have written the code in ".c" file, using c programming trying to transmit the bits serially using SBUF register.

As the SBUF register is the single register available in serial programming of 89C51, it is not updating its value. The bit which is first transmitted is only repeated in the next 2 bits, it is not being updated and then transmitted.

So I want guidance regarding sending 3 bits(number / integer) using serial communication( with SBUF register).

Following is the code I have written,

#include<reg51.h>

void decimal();
void MSB();
void MIDDLE();
void LSB();

void main()
{
while(1)
{
decimal();

MSB();

MIDDLE();

LSB();


}

}

void decimal()
{
unsigned char x,bin,d1,d2,d3;

bin = Data_Bus;
x = bin /10;
d1 = bin %10;
d2 = x %10;
d3 = x/10;

}

void MSB()
{
unsigned char d1,a;
TMOD = 0X20;
TH1 = 0XFD;
SCON = 0X50;
TR1 = 1;
a = d1 +0x30;
SBUF = a;
while(TI==0);
TI = 0;

}

void MIDDLE()
{
unsigned char d2,b;
TMOD = 0X20;
TH1 = 0XFD;
SCON = 0X50;
TR1 = 1;
SBUF = 0x00;
b= d2 + 0x30;
SBUF = b;
while(TI==0);
TI = 0;
}


void LSB()
{
unsigned char d3,c;
TMOD = 0X20;
TH1 = 0XFD;
SCON = 0X50;
TR1 = 1;
SBUF = 0x00;
c= d3 + 0x30;
SBUF = c;
while(TI==0);
TI = 0;
}
Sat Apr 21 2018, 07:45 PM
#2
I have attached sample code to do what you want.

There are a couple of points to note.

When you declare a variable in a function
it only exists in that function.
Variables d1,d2,d3 declared in void decimal() can't be
seen anywhere else.
When you declare d1 in MSB() it is a new variable (value 0 or unknown).

Declare d1,d2,d3 as global.

The serial port only needs to be set up once,
not every time it is used.

When functions do very much the same thing
as MSB(), void MIDDLE() and void LSB() do
find a way to use one call for all three.
Such as passing the variable to print.

sendChar(char c) does that.

Attachment


[ Edited Sat Apr 21 2018, 07:47 PM ]
 Pater like this.
Mon Apr 23 2018, 03:13 AM
#3
Thank You, ExperimenterUK for your valuable response.

You made it very clear for me to understand the errors and your sample code helped me to solve the issue.

Once again a big THANKS to you !!!
Mon Apr 23 2018, 08:51 PM
#4
Thanks
glad it helped

Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Fri Mar 15 2019, 02:14 AM
We don't send code,but you can ask for help in the 8051 forum
Thu Mar 14 2019, 04:30 PM
Jui Sanjay Kapare
Hello sir, I want code of interfacing DS18B20 with 8051.plz send the code as early as possible
ExperimenterUK
Mon Jan 07 2019, 09:01 AM
@REVOCATUS please post in the AVR forum
Mon Dec 24 2018, 02:55 PM
REVOCATUS MATEMU
sorry I mean referee boards for player substitution
Mon Dec 24 2018, 02:54 PM
REVOCATUS MATEMU
hi am.looking how to build referee by using Atmega 328 and its codes
Sat Dec 15 2018, 07:15 PM
Arslan ayoub
Hii ,, can I get the simulation of numeric keypad lock on proteus
ExperimenterUK
Mon Dec 03 2018, 10:47 PM
Please post questions in the forum. The chat box is for chat
Mon Dec 03 2018, 12:13 PM
help!me!
help! I don't understand busy flag!
Mon Dec 03 2018, 01:31 AM
ile
hello
Mon Nov 12 2018, 11:28 AM
Pavan_user
i have seen your replica of I2C programming using AT89C51 but i am unable to understand the "ack_bit" variable usage ...looks like it is always 1...can you elaborate how acknowledgment is working....

Downloads

Comments

tutu10
Tue Mar 12 2019, 07:11 AM
Raj243
Fri Mar 08 2019, 02:08 AM
bharatsb
Thu Mar 07 2019, 04:34 PM
Yass7
Thu Mar 07 2019, 03:55 PM
mashabed
Mon Mar 04 2019, 11:08 PM
AccelMotion
Tue Feb 26 2019, 06:06 PM
turbovps
Mon Feb 25 2019, 06:26 AM
the_Doker
Thu Feb 14 2019, 02:21 PM

Online

Guests: 27, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38052
Newest member: tutu10
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Mar 24 2019, 09:52 PM
Counting pulses can be as simple asvoid interrupt ...
Ansh12 Avatar
Posted By Ansh12
Sat Mar 23 2019, 05:08 PM
Using the external interrupt on pin B0 is the best...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Mar 22 2019, 09:10 PM
Using the external interrupt on pin B0 is the best...
Ansh12 Avatar
Posted By Ansh12
Fri Mar 22 2019, 03:45 PM
I have pic16f877a and MPLABX8 and I want to count ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Mar 13 2019, 02:32 AM
HiI looked at" Atmel AVR042: AVR Design Considera...
tutu10 Avatar
Posted By tutu10
Tue Mar 12 2019, 07:13 AM
Hi...My firmware upgradable code lock seems to be ...
Yass7 Avatar
Posted By Yass7
Sat Mar 09 2019, 12:52 AM
It's exactly that ! it's my teacher who asked me t...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Mar 09 2019, 12:27 AM
As I understand it, you want to use a P89LPC952 /...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Mar 09 2019, 12:21 AM
After you get the string what do you want to do wi...
bharatsb Avatar
Posted By bharatsb
Thu Mar 07 2019, 04:40 PM
help me to write code for 8051 to receive string ...