小弟 在用51调试串口。波特率设成9600 串口输出是-P 。但把波特率设成600后串口输出是P,少了一个字符。所以在接600波特率的外设时无法通信。请高手指点。非常感谢。 在send_com()子程序中删除TI=1程序无法运行。这是我在网上看的 不太理解为什么!!请高手解释一下!!谢谢! 如果有好的程序 发小弟邮箱一份!谢谢!zhenyongan2008@163.com
  程序如下: #include <REGX51.H> #include <stdio.h> #include <string.h> #include <math.h> //#define INBUF_LEN 2
  unsigned char sendbuf[2]={0x1b,0x70}; unsigned char inbuf[13]; unsigned char count,point,time=0; bit read_flag=0;
  void delay(char x)//延时函数 {      char i;      while(x--)      for(i=0;i<125;i++)      continue; } 
   void com_init(void) { SCON=0x58;//interrupt enable TMOD=0x21;    //T1 generate 600 baund rate T0 is timer as 60ms PCON=0x00; TH0=0x28; //28 TL0=0x00; TH1=0xd0;                             TL1=0xd0; TR0=1; TR1=1; ET0=1;                        ET1=0; ES=1; PS=1; EA=1; //TI=1; }
  void com_send(void) {  for(point=0;TI==1,point<=1;point++)  {   SBUF=sendbuf[point];  TI=0;  } }
  time0_interrupt(void) interrupt 1 using 1 {  if(time==15)  {  /*unsigned char i=0;  SBUF=sendbuf;  //delay(5);  //if(TI)  SBUF=sendbuf[++i];  //delay(10);  //TI=0;*/   com_send();   point=0;   time=0;  }  else  time++;  TH0=0x28;  TL0=0x00; }  com_interrupt(void) interrupt 4 using 3 {    if(RI)  {  unsigned char ch;  RI=0;  ch=SBUF;  if(count>13)  count=0;  else  {   inbuf[count]=ch;   count++;  if(count==1)  read_flag=1;  }      }  if(TI)  TI=0;  /*if(TI)  {unsigned char i=0;   SBUF=sendbuf;   SBUF=sendbuf[++i];   TI=0;   }*/   }  main(void)  {   SP=0x50;  EA=0;  com_init();  while(1)  {   if(read_flag==1)  {   P0=0xaa;   P2=0xb0;   delay(20);   read_flag=0;  }  if(read_flag==0)  {  P0=0x55;P2=0xc0;  }  }  } |   
     
  
 |