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

serial communication in proteus via virtual terrminal

hi....
i want to send some strings serially using virtual terminal in proteus but i get garbage value on virtual terminal
can any one mail me proteus design for it on
hayatkhan015@yahoo.com
or
help me by some other way..

or there is some error in my program?
which is..

#include <reg51.h>
void Delay();
void serialsend(char *ptr);

void main ()
{ char z;
code char command1[]={"AT12"};
code char command2[]={"ATC51" };
code char command3[]={"ADSING"};
code char command4[]={"12"};
code char command5[]={"ATMEL"};
code char command6[]={"CIPSEND"};
code char command7[]={"GPRS"};
code char command8[]={"26"};
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
serialsend(command1);
Delay();
serialsend(command2);
Delay();
serialsend(command3);
for(z=0; z<3; z++)
{ Delay(); }
serialsend(command4);
Delay();
serialsend(command5);
for(z=0; z<10; z++)
{ Delay();
} serialsend(command6);
for(z=0; z<5; z++)
{ Delay(); }
serialsend(command7);
serialsend(command8);

}
void serialsend(char *ptr)
{ while(*ptr != '\0')
{ SBUF=*ptr;
while(TI==0);
TI=0;
ptr++;
} }

void Delay()
{ unsigned char x;
for(x=0; x<40; x++)
{ TMOD=0x01;
TL0=0xFD;
TH0=0x4B;
TR0=1;
while (TF0==0);
TR0=0;
TF0=0;
} }

Parents
  • TMOD is configured at main for serial communications and at delay for Timer
    This SFR operates on both Timers T0 and T1, so be creative to use right.

    //for serial using T1
    TMOD = 0x20;
     |
     +---> TMOD &= 0x0F;      // Clear the upper nibble for T1 config (T0 part unchanged)
           TMOD |= 0x20;      // Set parameters for T1 on TMOD, lower nibbe must be 0.
    
    //for delay using T0
    TMOD = 0x010;             // This reconfigures T1 and T0 wich is not right for the situation
     |
     +---> TMOD &= 0xF0;      // Clear the lower nibble for T0 config (T1 part unchanged)
           TMOD |= 0x01;      // Set parameters for T0 on TMOD, upper nibble must be 0
    

    or set TMOD for both Timers T0 and T1 at main ONLY, no need to re-configure TMOD at delay()

    TMOD = 0x21;                     // T1 as 8bit autoreload and T0 as 16bit timer
    

    Tutorial for 8051 Timers is here: www.8052.com/tuttimer.phtml

Reply
  • TMOD is configured at main for serial communications and at delay for Timer
    This SFR operates on both Timers T0 and T1, so be creative to use right.

    //for serial using T1
    TMOD = 0x20;
     |
     +---> TMOD &= 0x0F;      // Clear the upper nibble for T1 config (T0 part unchanged)
           TMOD |= 0x20;      // Set parameters for T1 on TMOD, lower nibbe must be 0.
    
    //for delay using T0
    TMOD = 0x010;             // This reconfigures T1 and T0 wich is not right for the situation
     |
     +---> TMOD &= 0xF0;      // Clear the lower nibble for T0 config (T1 part unchanged)
           TMOD |= 0x01;      // Set parameters for T0 on TMOD, upper nibble must be 0
    

    or set TMOD for both Timers T0 and T1 at main ONLY, no need to re-configure TMOD at delay()

    TMOD = 0x21;                     // T1 as 8bit autoreload and T0 as 16bit timer
    

    Tutorial for 8051 Timers is here: www.8052.com/tuttimer.phtml

Children
No data