This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Need help in serial programming using SBUF register !!!!

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; }