everyone.
I am using PIC18F452 micro-controller. I receive data on UART, frame it by attaching extra sync words and transmit it, I face problems in sending the sync words in sequence. What I want is to send words say... EA 09 C3 with the data. Now I have this code written in MikroC:
int j=0;
SPBRG = 129;
TXSTA = 0b00100110;
RCSTA = 0b10010000;
while(1)
{
if(j == 0)
{
TXREG = 0xEA;
}
else if(j == 1)
{
TXREG = 0x09;
}
else if(j == 2)
{
TXREG = 0xC3;
}
else
{
TXREG = RCREG;
}
while(!TRMT); // wait for whole data frame to be ready for transmission
if(j == 100)
j = 0; // reset j after 100 bytes
else
j++;
}
Now what happens here is that sync words are transmitted but out of sequence and sometimes byte duplication also occurs. What I want is that j should only increment after one byte is transmitted, here I think j increments independently of the transmission.
Thanking in anticipation.
Regards, Hassan