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

Mon Nov 12 2018, 05:58 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....
bgk3678
Tue Nov 06 2018, 02:36 PM
kindly any one give solution for my problem
ExperimenterUK
Mon Nov 05 2018, 09:48 PM
Pins high is the normal state. You need a program to set them low
mayengbam
Sun Nov 04 2018, 05:41 PM
hello, i am niranjoy, alll the port of my 8051 is always high, even i erase all the program. why is it so happen and what is the problem. any one please help me!
Sun Nov 04 2018, 02:16 PM
BASAVARAJ g kudamble
hi I am interfacing GSM 300 to 8051 microcontroller to receive message from mobile
ExperimenterUK
Sat Sep 29 2018, 06:28 PM
Please post questions in the forum.
Sat Sep 29 2018, 11:26 AM
Ashfaq Ch
hi i have some AT89C51RC microcontrollers already programed. some one help us to how to download from AT89C51RC and after study and edit all corractions reload to AT89C51RC controller
shshistiem
Wed Sep 12 2018, 10:58 PM
hii!! some1 please let me know how i ll get rfid code to 8051 by WEIGAND mode
DrNossberg
Tue Sep 11 2018, 08:09 PM
is there anyone here?
Mon Aug 27 2018, 07:30 AM
bun
Hello everyone´╝ü

Downloads

Comments

atalnet
Fri Nov 16 2018, 07:44 AM
genius784
Wed Nov 14 2018, 09:25 AM
katherineamt
Mon Nov 12 2018, 03:14 PM
wimac
Sun Nov 11 2018, 03:36 PM
suryanspn
Sat Nov 10 2018, 02:52 AM
RubenMarques
Tue Nov 06 2018, 06:35 PM
mayengbam
Sun Nov 04 2018, 05:36 PM
bgk3678
Sun Nov 04 2018, 02:27 PM

Online

Guests: 50, Members: 0 ...

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

Members: 38021
Newest member: atalnet
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 19 2018, 01:11 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Nov 15 2018, 06:48 PM
Unfortunately I have no experience of LabView,but ...
katherineamt Avatar
Posted By katherineamt
Mon Nov 12 2018, 03:22 PM
I have never used LabView and I have to implement ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 12 2018, 01:21 AM
wimac Avatar
Posted By wimac
Sun Nov 11 2018, 04:03 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 11 2018, 07:25 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 06 2018, 06:10 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 04 2018, 02:52 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 04 2018, 02:48 PM
Xuenan Avatar
Posted By Xuenan
Sat Nov 03 2018, 01:08 PM
Make the 8051 frequency exactly 11.0592 MHz in pro...