Zaindroid
Newbie level 6
- Joined
- Dec 10, 2013
- Messages
- 11
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 79
hi,
i need help with my manchester encoding code, i have written a code (code and proteus simulation is provided below).this code takes an input from virtual terminal and then encodes that received input using manchester encoding. after encoding it sends the encoded data back to virtual terminal. The problem i am im facing is: i am receiving something back but it is some garbage value. Plz help me in this regard.
#include <reg51.h>
sbit rs= P2^0;
sbit rw= P2^1;
sbit en= P2^2;
void SendData(int txbyte);
void delay(unsigned int itime);
void lcdcmd(unsigned char digit);
void lcd_data(unsigned char alpha);
void lcd_init();
void serial_port();
void main(void)
{
int mybyte;
serial_port();
lcd_init();
while (1)
{ //repeat forever
while (RI==0); //wait to receive
mybyte=SBUF; //save value
lcd_data(mybyte); //write value to port
//delay(250);
SendData(mybyte);
RI=0;
}
}
void SendData( int txbyte)
{
int i,j,b,me,x;
b = txbyte;
for (i=0; i<2; i++)
{
me = 0; // manchester encoded txbyte
for (j=0 ; j<4; j++)
{
me >>=2;
if ((b & x) == x)
me |=0x40; // 1->0
else
me |=0x80; // 0->1
b >>=1;
}
SBUF=me; //place value in buffer
while (TI==0);
TI=0;
delay(50);
}
}
void delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(int digit)
{
P1=digit;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
}
void lcd_data(int alpha)
{ if (alpha==0x08)
lcdcmd(1);
else
P1=alpha;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
void serial_port()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
void lcd_init()
{
lcdcmd(0x38);
//delay(250);
lcdcmd(0x0E);
//delay(250);
lcdcmd(0x01);
//delay(250);
lcdcmd(0x06);
lcdcmd(0x80);
} //delay(250);
i need help with my manchester encoding code, i have written a code (code and proteus simulation is provided below).this code takes an input from virtual terminal and then encodes that received input using manchester encoding. after encoding it sends the encoded data back to virtual terminal. The problem i am im facing is: i am receiving something back but it is some garbage value. Plz help me in this regard.
#include <reg51.h>
sbit rs= P2^0;
sbit rw= P2^1;
sbit en= P2^2;
void SendData(int txbyte);
void delay(unsigned int itime);
void lcdcmd(unsigned char digit);
void lcd_data(unsigned char alpha);
void lcd_init();
void serial_port();
void main(void)
{
int mybyte;
serial_port();
lcd_init();
while (1)
{ //repeat forever
while (RI==0); //wait to receive
mybyte=SBUF; //save value
lcd_data(mybyte); //write value to port
//delay(250);
SendData(mybyte);
RI=0;
}
}
void SendData( int txbyte)
{
int i,j,b,me,x;
b = txbyte;
for (i=0; i<2; i++)
{
me = 0; // manchester encoded txbyte
for (j=0 ; j<4; j++)
{
me >>=2;
if ((b & x) == x)
me |=0x40; // 1->0
else
me |=0x80; // 0->1
b >>=1;
}
SBUF=me; //place value in buffer
while (TI==0);
TI=0;
delay(50);
}
}
void delay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(int digit)
{
P1=digit;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
}
void lcd_data(int alpha)
{ if (alpha==0x08)
lcdcmd(1);
else
P1=alpha;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
void serial_port()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
void lcd_init()
{
lcdcmd(0x38);
//delay(250);
lcdcmd(0x0E);
//delay(250);
lcdcmd(0x01);
//delay(250);
lcdcmd(0x06);
lcdcmd(0x80);
} //delay(250);