打印

程序为什么多跑一次

[复制链接]
1278|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
irisjyf|  楼主 | 2009-10-14 10:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
程序如下:
while (1)
  {   
      /* Loop forever */
      if ( UART0Count != 0 )
      {
           U0IER = IER_THRE | IER_RLS;   /* Disable RBR */
           UARTSend( 0, (BYTE*)UART0Buffer, UART0Count );
             UART0Count = 0;
            U0IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
           LCD_gotoxy(1,1);
           LCD_puts(UART0Buffer);
  }
串口程序1
void UARTSend( DWORD portNum, BYTE *BufferPtr, DWORD Length )
{
  WORD i=0;
if ( portNum == 0 )
  {
    while ( Length != 0 )
    {
   /* THRE status, contain valid data */
   while ( !(UART0TxEmpty & 0x01) );
   U0THR = BufferPtr[i];
   UART0TxEmpty = 0; /* not empty in the THR until it shifts out */
  //BufferPtr++;
  Length--;
  i++;
}
  }
  else
  {
while ( Length != 0 )
    {
   /* THRE status, contain valid data */
   while ( !(UART1TxEmpty & 0x01) );
   U1THR = BufferPtr[i];
   UART1TxEmpty = 0; /* not empty in the THR until it shifts out */
   //BufferPtr++;
   Length--;
    i++;
  }
  }
  return;
}
串口程序2
void UARTSend( DWORD portNum, BYTE *BufferPtr, DWORD Length )
{
  WORD i=0;
if ( portNum == 0 )
  {
    while ( Length != 0 )
    {
   /* THRE status, contain valid data */
   while ( !(UART0TxEmpty & 0x01) );
   U0THR = *BufferPtr;
   UART0TxEmpty = 0; /* not empty in the THR until it shifts out */
  BufferPtr++;
  Length--;
}
  }
  else
  {
while ( Length != 0 )
    {
   /* THRE status, contain valid data */
   while ( !(UART1TxEmpty & 0x01) );
   U1THR = *BufferPtr;
   UART1TxEmpty = 0; /* not empty in the THR until it shifts out */
   BufferPtr++;
   Length--;
  }
  }
  return;
}
  
上面的lcd_puts(char*)
为1602的字符形液晶显示器;
我碰到的问题是,我想串口写段数据,然后在用串口发回pc机,从lcd上显示刚才的字符;
可是在单步调试能正常显示,全速运行后只能显示1个字符,就是最后一个,谁碰到国这个问题?给解释下

相关帖子

沙发
阿南| | 2009-10-14 10:58 | 只看该作者
楼主慢慢的研究一下,这种实践的问题还是需要通过自己的不断调试来找出问题

使用特权

评论回复
板凳
irisjyf|  楼主 | 2009-10-14 10:59 | 只看该作者
解释下多跑一次:当显示字符后,然后显示器在第一行第一个字符区显示上次的最后一个字符,所以我认为是程序多跑了一次。

使用特权

评论回复
地板
irisjyf|  楼主 | 2009-10-15 11:45 | 只看该作者
谁用1602碰到过这个问题

使用特权

评论回复
5
john_light| | 2009-10-15 13:11 | 只看该作者
先把代码缩进好再说吧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

12

帖子

0

粉丝