HI3531ARM调试printf的实现 分类: HI3531 arm-linux-Ubuntu 2013-12-16 15:56 501人阅读 评论(0) 收藏

void UART_Putc(char c)
{
    if (c == '\n')
  *(unsigned int *)(UART0_ADDR  + 0X00) =  '\r';
    delay_x(0x800);
 *(unsigned int *)(UART0_ADDR  + 0X00) = c;
 
}
unsigned int val_i=0;
void UART_Print(const char *str,...)
{
    va_list unnamed_p;
    char *sval;
    unsigned int tmp=0;
    va_start( unnamed_p, str);


    while (*str)
 {
     //
     if(*str=='%')
     {
       switch(*++str)
       {
           case 'd'://输出十进制
               break;
           case 'c'://输出字符
               break;
           case 's'://输出字符串
               for(sval = va_arg(unnamed_p,char*);*sval;sval++)
               {
                   UART_Putc(*sval);
               }
               str++;
               break;
           case 'X'://输出16十进制
           case 'x'://输出16十进制
               val_i = va_arg(unnamed_p,unsigned int);
               //
               UART_Putc('0');delay_x(0X800);
               UART_Putc('x');delay_x(0X800);
               for(i=0;i<8;i++)
               {
                   delay_x(0X800);
                   tmp = val_i>>(4*(7-i));
                   val_i = val_i&(~(0xff<<(4*(7-i))));
                   //
                   if(tmp<10)
                       UART_Putc('0'+tmp);
                   else
                       UART_Putc('A'+tmp-10);
                   //
               }
               //
               str++;
               break;
          default://输出字符
               break;
         
       }
     }
     //
  UART_Putc(*str++);
  
 }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2013-12-16 15:56  毛毛虫的薄刻  阅读(152)  评论(0编辑  收藏  举报