Hello,
I would like to ask you that I used this two follow program to send and recive DATA serially via port C where I use start_byte (8bit) to begin the DATA and parity byte (8bit) to check the DATA recieved is right ( maybe the parity byte is enought) where I get the parity byte right but the data recieved not correct , I won't chang my code but if there is small modifucations?
thank you
Transmitter :
void main() {
void init();
int info=0b10010110, byte_start = 0b10110010, compare = 0b00000001, count, Parity=0b11001000, DATA=0b0, byte_end=0b11010010;
/* Configure the port C as output */
DDRC = 0xff;
while (DATA!=byte_end)/*!= byte_start)*/
{
for (count = 0; count < 8; count++)
{
DATA = (byte_start >> count); // output = number shifted right * count
if(DATA & compare)
{
PORTC = (1<< PINC0);
}
else
{
PORTC&= ~(1<< PINC0);
}
Delay_ms(1);
}
DATA=0;
for (count = 0; count < 8; count++)
{
DATA = (info >> count); // output = number shifted right * count
if(DATA & compare)
{
PORTC = (1<< PINC0);
}
else
{
PORTC&= ~(1<< PINC0);
}
Delay_ms(1);
}
for (count = 0; count < 8; count++)
{
DATA = (Parity >> count); // output = number shifted right * count
/*PORTC = DATA; */
if(DATA & compare)
{
PORTC = (1<< PINC0);
}
else
{
PORTC&= ~(1<< PINC0);
}
Delay_ms(1);
}
DDRC=0x00;
for (count = 0; count < 8; count++)/*; count++)*/
{
if(PINC & (1<<PINC0))
{
PORTD= (1<< PIND3);
DATA|=(1<<count);
}
else
{
DATA &= ~(1<<count);
}
Delay_ms(1);
}
}
}
**************************************************************************************************************************
Reciever
void main() {
void init();
int info=0b10010110, byte_start = 0b10110010, count=0x00, Parity=0b11001000, DATA=0b0, byte_end=0b11010010;
DDRC = 0x00;
DDRA = 0xff;
while(DATA!=byte_start)
{
for (count = 0; count < 8; count++)/*; count++)*/
{
if(PINC & (1<<PINC0))
{
DATA|=(1<<count);
}
else
{
DATA &= ~(1<<count);
}
Delay_us(500);
}
}
while (DATA!=Parity)
{
for (count = 0; count < 8; count++)/*; count++)*/
{
if(PINC & (1<<PINC0))
{
DATA|=(1<<count);
}
else
{
DATA &= ~(1<<count);
}
Delay_us(500);
}
PORTA=DATA;
for (count = 0; count < 8; count++)/*; count++)*/
{
if(PINC & (1<<PINC0))
{
DATA|=(1<<count);
}
else
{
DATA &= ~(1<<count);
}
Delay_us(500);
}
}
DDRC = 0xff;
for (count = 0; count < 8; count++)
{
DATA = (byte_end >> count); // output = number shifted right * count
if(DATA & 1)
{
PORTC = (1<< PINC0);
}
else
{
PORTC&= ~(1<< PINC0);
}
Delay_ms(1);
}
}