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

about serial communication!

I can't step over this instruction ( while(TI==0);//  )
the program :

#include "reg51.h"
main()
{
  TCON = 0x50;
  TMOD = 0x20;
  TL1 = 0xFD;
  TH1 = 0xFD;
  TR1 = 1;
  while(1)
  {
   SBUF = 0xFF;
   while(TI==0);//  I can't step over here .
   TI = 0;
  }
  

  • But I can, used your code,I just copied the code to a file,compiled and ran,OK
    Kel C51 7.06a

  • Sorry, but I do not see where you initialized the SCON (and T2CON if it is presents) register(s)? May it be possible that T2 configured as baud rate generator but does not run?
    As well there are not shown interrupts settings, do you use ISR of T0 and T1?
    Another note about your example is that

    TCON = 0x50;
    has already run timers T0 and T1 via set bits TR0 and TR1.

  • "...Sorry, but I do not see where you initialized the SCON (and T2CON if it is present)... May it be possible that T2 configured as baud rate generator but does not run?
    As well there are not shown interrupts settings, do you use ISR of T0 and T1?..."


    The default value of SCON is 0x00, so if the user is satisfied with the shift register mode @ Fosc/12 (SM1=SM0=0), it needn't be set up (nevertheless it's better practice expressing it explicitly).
    Note: In this mode the 8-bit data output is RXD pin! TXD pin outputs the shift clock signal. Sending 0xFF repeatedly (as in the shown program) will result in continuous H level at RXD pin (no START bit).

    It's evident that T1 is used as a baudrate generator (default for MCS51 Family). T2 needn't be present nor set up. T0 is also running - in the program it is evidently useless. (I suppose the complete tested program is shown).
    No interrupts needn't be shown for no interrupt is evidently needed neither used. (polling method, ie. "is TI set?", is used for serial comm handling).

    The shown program should work and it really works! Therefore, I think, the primary problem must be elsewhere, not in the program itself.

  • Note: In fact, in the shift register mode no baudrate generator is needed because the rate is constant and equals Fosc/12. So if this mode were the intention, no set up of any timer or baudrate generator is needed.

  • I asked about showing of ISR of timers because it may be that ISR of timer1 contains a typpo, for example, JMP $ etc... Really, what is the initialization of Timer1 at start of main for if UART uses just mode 0? Seems Jeny rejected some important code parts...

    Good days!

  • Yes, you are probably right.

    Best wishes