<thead id="hmjeg"><listing id="hmjeg"></listing></thead>
      
      
      <dl id="hmjeg"></dl>
    1. <strike id="hmjeg"></strike>
        您好,歡迎訪問(wèn)上海意泓電子科技有限責(zé)任公司網(wǎng)站!
        4新聞資訊
        您的位置: 首頁(yè) ->  新聞資訊 -> 單片機(jī)

        ?Keil MDK環(huán)境下使用printf函數(shù)的解決方法

        文章出處:?jiǎn)纹瑱C(jī) 責(zé)任編輯:上海意泓電子科技有限責(zé)任公司 發(fā)表時(shí)間:
        2018
        05-20

        printf()函數(shù)可以直接向窗口格式化輸出,給我們調(diào)試程序帶來(lái)很大的方便,然而在Keil MDK環(huán)境下直接使用printf()函數(shù)就會(huì)陷入軟件中斷,導(dǎo)致死循環(huán)的產(chǎn)生;因而不能進(jìn)入main()函數(shù)。

        單步調(diào)試程序時(shí)會(huì)發(fā)現(xiàn)程序指針一直在 SWI_Handler     B       SWI_Handler 打轉(zhuǎn);

        解決方法:

        工程選擇NXP的LPC21XX器件。

        1.首先在Keil安裝目錄下面ARM——Startup找到Retarget.c文件將其復(fù)制到你的工程文件夾下面;并將其加入到工程中;

        2. 在Keil安裝目錄下面ARM——Examples——Hello找到Serial.c文件將其復(fù)制到你的工程文件夾下面;并將其加入到工程中;

        3.Serial.c代碼如下:

        /******************************************************************************/
        /* SERIAL.C: Low Level Serial Routines                                        */
        /******************************************************************************/
        /* This file is part of the uVision/ARM development tools.                    */
        /* Copyright (c) 2005-2006 Keil Software. All rights reserved.                */
        /* This software may only be used under the terms of a valid, current,        */
        /* end user licence from KEIL for a compatible version of KEIL software       */
        /* development tools. Nothing else gives you the right to use this software.  */
        /******************************************************************************/

        #include                      /* LPC21xx definitions               */

        #define CR     0x0D


        void init_serial (void)  {               /* Initialize Serial Interface       */
          PINSEL0 = 0x00050000;                  /* Enable RxD1 and TxD1              */
          U1LCR = 0x83;                          /* 8 bits, no Parity, 1 Stop bit     */
          U1DLL = 97;                            /* 9600 Baud Rate @ 15MHz VPB Clock  */
          U1LCR = 0x03;                          /* DLAB = 0                          */
        }


        /* implementation of putchar (also used by printf function to output data)    */
        int sendchar (int ch)  {                 /* Write character to Serial Port    */

          if (ch == '\n')  {
            while (!(U1LSR & 0x20));
            U1THR = CR;                          /* output CR */
          }
          while (!(U1LSR & 0x20));
          return (U1THR = ch);
        }


        int getkey (void)  {                     /* Read character from Serial Port   */

          while (!(U1LSR & 0x01));

          return (U1RBR);
        }

        4.在頭文件中加入#include。

        5.在使用printf函數(shù)之前對(duì)串口進(jìn)行初始化;可以直接使用Serial.c中的 init_serial ()函數(shù)對(duì)串口初始化。


        上海意泓電子科技有限責(zé)任公司 版權(quán)所有 未經(jīng)授權(quán)禁止復(fù)制或鏡像

        CopyRight 2020-2025 m.nntrj.com All rights reserved   滬ICP備2021005866號(hào)

        在线观看理论片国产,久久精品成视频播放,国产在线国语对白,国产拍拍拍无码免费视频
        <thead id="hmjeg"><listing id="hmjeg"></listing></thead>
            
            
            <dl id="hmjeg"></dl>
          1. <strike id="hmjeg"></strike>