Need help in serial communication using SBUF register using 89C51 !!! Answered

145Views1Replies

Author Options:

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;

b= d2 + 0x30;

SBUF = b;

while(TI==0);

TI = 0;

}

void LSB()

{

unsigned char d3,c;

TMOD = 0X20;

TH1 = 0XFD;

SCON = 0X50;

TR1 = 1;

c= d3 + 0x30;

SBUF = c;

while(TI==0);

TI = 0;

}

Discussions

None
steveastrouk

1 year ago

Don't do this:

TMOD = 0X20;

TH1 = 0XFD;

SCON = 0X50;

Every byte and every routine. It needs to be in your initialisation. Check your baud rate calculation.

Clear TI before you start transmitting (wrtiing to SBUF), just to make sure