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

Computer COM port & microcontroller COM port ??

Hi all,

I have written a program in VC++ to write a char array of 13 bytes on COM port using 9600-N-8-1 parameters.

when i send this to my target device it responds, but same program when i send through 89S51 my device does not respond.To set 9600-N-8-1 i have written 0xFD value.

Can anyone no the reason for such strange behaviour.

Please let me know....

rutu.

Parents
  • #include<reg52.h>
    #include<stdio.h>
    
    char m_Write[13]={0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xBF,0x0A};
    
    char loop=13;
    
    void main(void)
    {
    SCON=0x50;
    TMOD |=0x20;
    TH1=0xFD;
    TR1=1;
    TI=1;
    
    while(1)
      {
      while(loop--)
        putchar(m_Write[13-loop]);
      loop=13;
      }
    }
    

    The main problem I see is that the while loop you have only transmits 12 characters.

    At the beginning, you have set loop to 13. The while (loop--) decrements loop to 12. You then transmit m_Write[13-loop] and 13-12 is 1. However, the first array element is index 0. I would probably re-write the code as follows:

    #include<reg52.h>
    #include<stdio.h>
    
    static unsigned char m_Write[13] =
    {0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xBF,0x0A};
    
    void main(void)
    {
    unsigned char loop;
    
    SCON=0x50;
    TMOD |=0x20;
    TH1=0xFD;
    TR1=1;
    TI=1;
    
    while(1)
      {
      for (loop = 13; loop; loop--)
        {
        putchar(m_Write[13-loop]);
        }
      }
    }
    

    Jon

Reply
  • #include<reg52.h>
    #include<stdio.h>
    
    char m_Write[13]={0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xBF,0x0A};
    
    char loop=13;
    
    void main(void)
    {
    SCON=0x50;
    TMOD |=0x20;
    TH1=0xFD;
    TR1=1;
    TI=1;
    
    while(1)
      {
      while(loop--)
        putchar(m_Write[13-loop]);
      loop=13;
      }
    }
    

    The main problem I see is that the while loop you have only transmits 12 characters.

    At the beginning, you have set loop to 13. The while (loop--) decrements loop to 12. You then transmit m_Write[13-loop] and 13-12 is 1. However, the first array element is index 0. I would probably re-write the code as follows:

    #include<reg52.h>
    #include<stdio.h>
    
    static unsigned char m_Write[13] =
    {0x40,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x79,0xBF,0x0A};
    
    void main(void)
    {
    unsigned char loop;
    
    SCON=0x50;
    TMOD |=0x20;
    TH1=0xFD;
    TR1=1;
    TI=1;
    
    while(1)
      {
      for (loop = 13; loop; loop--)
        {
        putchar(m_Write[13-loop]);
        }
      }
    }
    

    Jon

Children