<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > S3C2440在MDK4.22下使用printf向串口打印調(diào)試

          S3C2440在MDK4.22下使用printf向串口打印調(diào)試

          作者: 時間:2016-11-19 來源:網(wǎng)絡 收藏
          背景知識:

          串口的基本知識已經(jīng)在上一篇講過了。這里重點講解如何在MDK4.22下使用printf函數(shù),這樣的話就可以很方便的打印調(diào)試信息,追蹤。

          本文引用地址:http://www.ex-cimer.com/article/201611/318140.htm

          這個知識來源于MDK自帶的幫助手冊。有現(xiàn)成的代碼提供。

          實現(xiàn)方式有2種,使用標準C庫下裁剪合適的函數(shù),使用微庫C下裁剪合適的函數(shù)。

          微庫下的情況,在魔術棒那里要勾選上使用微庫。然后需要定義如下結(jié)構(gòu)和改寫如下函數(shù)--FILE stdout fputc ferror。

          標準庫的情況,也是需要關注FILE stdout fputc ferror。注意網(wǎng)上很多文章說,在標準庫下,需要關掉半主機模式,我嘗試過,關掉后,需要定義_sys_exit函數(shù),可以達到效果,但是如果不關掉半主機模式,和微庫一樣也只定義該定義的,也可以達到效果。不知道,是不是MDK版本升級后,已經(jīng)統(tǒng)一了兩種模式。

          具體代碼:

          uart.c

          #include "S3C2440.h"#include "uart.h"void init_uart0(void){rULCON0 = 0x03;  rUCON0 = (0x05);//15---12   	11-10		9		8		7				6						5		 4			3-2				1-0//not pclk/n	pclk		Tpulse	Rpulse	timeout disable	rx error int disable   loop dis  break dis	int or poll		int or pollrUFCON0 = 0x00;	  			rUMCON0 = 0x0; 				rUBRDIV0 = UART_BRDIV;}struct __FILE  {  int handle;  /* Whatever you require here. If the only file you are using is */  /* standard output using printf() for debugging, no file handling */  /* is required. */  };  /* FILE is typedef’ d in stdio.h. */  FILE __stdout;  int fputc(int ch, FILE *f) { WrUTXH0_L(ch); /* Loop until the end of transmission */ while(!(rUTRSTAT0 & TXD0READY)) ;return ch; } int ferror(FILE *f) {/* Your implementation of ferror */return EOF;}

          main.c

          #include "S3C2440.h"#include "uart.h"#include int main(void){	init_uart0();printf("hello worldrn");}

          最終可以在UART0上打印hello world,這樣以后程序就可以拿來復用了!


          評論


          技術專區(qū)

          關閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();