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
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html
ExperimenterUK
Thu Jul 11 2019, 07:44 PM
@praveen123. Can you give a link to the project ?
Thu Jul 11 2019, 04:47 PM
ramos
buenos dias alguien podria ayudarme necesito saber como descargar la libreria del l298n para proteus
Thu Jul 11 2019, 11:11 AM
praveen123
anyone can help me
Thu Jul 11 2019, 11:11 AM
praveen123
i need source code for 8051 -smart trolley rfid
Thu Jul 11 2019, 11:10 AM
praveen123
hii
ExperimenterUK
Thu Jun 27 2019, 09:14 PM
Hi.. good to see you again
۞ TPS ۞
Thu Jun 27 2019, 07:31 AM
Hello
AdiGhazi
Tue Jun 18 2019, 11:21 AM
Hlo Dear , I've to program AT89C51AC3 RT-LUM using flip but I'm getting time out error for RS232. Will you please suggest me which programmer will be supportable to program this Chip.
Sun Jun 16 2019, 07:48 PM
hanoch Taub
i need to interface sim800 to 8051, the problem is that on the module sim800 there are 9 pins connector and I don't know how to connect him to 8051, which pins to tx and rx on 8051 module sim there is

Downloads

Comments

3AAPC
Sun Jul 21 2019, 12:41 AM
rpels7707
Fri Jul 19 2019, 11:31 AM
ameya123
Fri Jul 19 2019, 07:36 AM
anhsieuno
Thu Jul 18 2019, 11:39 AM
zxcvbnm1234
Sat Jul 13 2019, 07:09 AM
surajghayal
Wed Jul 10 2019, 01:17 PM
figureyang
Fri Jul 05 2019, 04:25 AM
mousompal
Sat Jun 29 2019, 05:02 PM

Online

Guests: 39, Members: 0 ...

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

Members: 38081
Newest member: 3AAPC
Forum Activity
3AAPC Avatar
Posted By 3AAPC
Sun Jul 21 2019, 12:51 AM
3AAPC Avatar
Posted By 3AAPC
Sun Jul 21 2019, 12:47 AM
With the GPS antenna in the outdoors, I use the ub...
ameya123 Avatar
Posted By ameya123
Fri Jul 19 2019, 07:42 AM
Hello,Please share 8051 Assembly language code for...
figureyang Avatar
Posted By figureyang
Fri Jul 05 2019, 04:37 AM
here is the source code prepared for you download ...
figureyang Avatar
Posted By figureyang
Fri Jul 05 2019, 04:30 AM
Cheap_Flash_FS(Normal Version)--Embedded FAT16/32 ...
wimac Avatar
Posted By wimac
Sat Jun 22 2019, 01:26 PM
I’ve use the AT89C51ED2 which has a similar progra...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jun 20 2019, 10:08 PM
baud rate is 9600 at stop bits of 2. AdiGhaziThe u...
AdiGhazi Avatar
Posted By AdiGhazi
Thu Jun 20 2019, 05:24 AM
Dear,I'm using RS232 serial port cable to use flip...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jun 18 2019, 10:19 PM
Okay.. I have never programmed the AT89C51AC3 or ...
AdiGhazi Avatar
Posted By AdiGhazi
Tue Jun 18 2019, 11:20 AM
Hlo Dear ,I've to program AT89C51AC3 RT-LUM using ...