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

Sun May 20 2018, 01:16 PM
justinb
how to write and execute a program that read the keypad button and display the number on 7 segment on intel8051 at89s52 in assembly language?
Thu May 17 2018, 09:51 AM
HAMZA TAJ
sir iwant to ask about controller of three phase supply by using back to back thyristor instead of triac....will u give me some guideline?
Sat Apr 28 2018, 04:09 PM
ashutosh jain
IR Remote Switch using TV remote (RC5 Protocol) is not working properly. opp1 & opp2 is in problem.plz help
ExperimenterUK
Fri Apr 27 2018, 11:24 PM
@kaiserslautern Post in forum
Wed Apr 25 2018, 10:24 AM
kaiserslautern
Hello everyone, using software uart is a very good idea for a second serial port. Thank you so much. I would kindly like to know how to connect this port to the PC?
ExperimenterUK
Sat Apr 21 2018, 11:05 PM
This is a community site. Feel free to help anyone needing advice
hareeshchamiyar
Thu Mar 29 2018, 02:02 PM
please help me for the configuration bits for dspic30f2010
hareeshchamiyar
Thu Mar 29 2018, 02:00 PM
can any one using dspic30f2010.
Thu Mar 29 2018, 09:18 AM
Neena
can anybody give solar tracking in 8051 using proteus and keil to mail [email protected]
ExperimenterUK
Mon Mar 19 2018, 10:48 PM
sorry bedo.. maybe next time

Downloads

Comments

bdmehta
Tue May 22 2018, 02:30 AM
kmag1953
Sun Apr 29 2018, 07:09 PM
udiwonder
Sat Apr 28 2018, 12:41 PM
pirpiri
Sat Apr 21 2018, 03:35 PM
Pater
Fri Apr 20 2018, 02:38 PM
jamiel
Sat Apr 14 2018, 12:47 AM
akrepkral76
Wed Apr 04 2018, 07:51 PM
samanthaeaves
Mon Apr 02 2018, 06:27 AM

Online

Guests: 56, Members: 0 ...

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

Members: 37998
Newest member: bdmehta
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jul 12 2018, 08:27 PM
I'm glad we got there in the end :)>whats differen...
LAMBO Avatar
Posted By LAMBO
Thu Jul 12 2018, 06:51 AM
hi sir as u mentioned above to change crystal and ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jul 10 2018, 07:20 PM
I assume you meant a AT89S52.It seems to me that...
LAMBO Avatar
Posted By LAMBO
Tue Jul 10 2018, 06:06 AM
hi sir i have checked now much of the distortion ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 09 2018, 06:55 PM
Okay that is very interesting.I have attached two ...
LAMBO Avatar
Posted By LAMBO
Mon Jul 09 2018, 08:14 AM
hi sir as u mentioned above program i have tried ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Jul 06 2018, 11:58 PM
Okay..That motor creates a lot of sparks which mig...
LAMBO Avatar
Posted By LAMBO
Fri Jul 06 2018, 01:33 PM
hi sir as u told >Try the original code againi hav...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Jul 02 2018, 06:20 PM
>is it ok to work on 12.10 v Yes, that is ok.>now...
LAMBO Avatar
Posted By LAMBO
Mon Jul 02 2018, 08:22 AM
hi sir as u mentioned in the program i have checke...