Changing the port values inside the loop (8051)

8051microcontrollerreceivertransmitter

I am using RX/TX module an ht12d/e for my project. I will make it short, in my program i am making a packet of data and sending it and the receiver is receiving it synchronously. The receiver is set in a way that it waits for the value 0x0a from the transmitter, when that is received then it waits for 0x05 when that is received then it waits for another 0x05 and in between 0x05's there is 2 bit data contained in nibble. after 0x05 is received it then waits for another 0x05 and in between 0x05's it gets the information. there are 16 information in one packet. The problem begins here, when i send the packet in controlled manner that is by pressing a button one 0x05 is sent and take off the button 0x00 is sent, in this manner whole packet is received successfully, but when i transmit the packet using a function, nothing happens, no indication that the packet has received or receiving.
Note: the value on PORT 1 is transmitted, 8051 micro controller is used using c language. Transmission is only 4 bits parrallel.

while(1){
        if(highh==0 )
        {P1=0x0a;while(highh==0);}
        if(loww==0 )
        {P1=0x05;while(loww==0);} 
        P1=00;
    }

the above code works , in which highh and loww are representing 3.7 and 3.6 pins of 8051. i press them in a manner of sending packet.

void transmit()
{   
    for(i=0;i<i2;i++)P1 = 0x0a;  
    for(i=0;i<i2;i++)P1 = 0;   
    for(i=0;i<i2;i++)P1 = 0x05;     
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05;  
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0;  
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05;
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    ///////
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0;  
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    for(i=0;i<i2;i++)P1 = 0; 
    for(i=0;i<i2;i++)P1 = 0x05; 
    P1=00;
}

The above is the function which is i am using, which is not working. I have used P1=0 as information. The receiver is waiting for eighteen 0x05 values and one 0x0a at start. i2 is variable for delay duration. i have checked different duration delay. How can i get the function working? Is this the reason that the port values should be changed once in the main program loop.
What actually i am doing is;
1; collect data from different sensors.
2; split every byte of data into 2 bits.
3; transmit 0x0a
4; transmit 0x05
5; transmit info(containing those 2 bits which is recieved from sensors but actually are 4bits).
6; transmit 0x05 again,
7; go in similar way. till total of 16 info nibbles are sent.

and the reciever gets info after 0x05 has finished recieving.

Best Answer

You may not be waiting long enough between 'button presses'. The HT12E always repeats each word packet (address bits + data bits) at least 4 times, even if transmission is only enabled momentarily. If you try to send too fast then some of the 'button presses' will be lost.

At its recommended 3KHz oscillator frequency the HT12E takes about 70ms to send the 4 words, so you need to delay for longer than that (eg. 100ms) between transmissions.