找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5816|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

MSP430單片機printf函數(shù)移植

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:108615 發(fā)表于 2016-3-14 18:39 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本程序是《MSP430系列單片機系統(tǒng)工程設(shè)計與實踐》書里面的源碼,完整例程下載(包含工程文件 (例4.1.4))):http://www.torrancerestoration.com/bbs/dpj-46245-1.html

關(guān)于本程序的詳細解說大家可以下載電子書點擊上圖即可
  1. #include "msp430x42x.h"  /*單片機寄存器頭文件*/
  2. #include "ctype.h"       /*isdigit函數(shù)需要該頭文件*/
  3. #include "LCD_Display.h" /*LCD函數(shù)庫頭文件*/
  4. char  FirstChrFlag=1;  //第一個字符標志位


  5. /****************************************************************************
  6. * 名    稱:putchar()
  7. * 功    能:向LCD顯示屏輸出一個ASCII字符。
  8. * 入口參數(shù):ch: 待發(fā)送的字符  
  9. * 出口參數(shù):發(fā)出的字符
  10. * 說    明: printf函數(shù)會調(diào)用該函數(shù)作為底層輸出。該函數(shù)將字符輸出到LCD上
  11.             因此printf的結(jié)果將顯示在LCD上。
  12. ****************************************************************************/
  13. int putchar(int ch)
  14. {
  15. if(FirstChrFlag) LCD_Clear(); //第一個字符到來的時候清除上一屏顯示內(nèi)容
  16. FirstChrFlag=0;
  17. if(ch=='\f')     LCD_Clear(); //'\f'表示走紙翻頁,相當于清除顯示
  18. if(isdigit(ch))  LCD_InsertChar(ch-0x30); //若字符是數(shù)字則顯示數(shù)字
  19. //數(shù)字和對應(yīng)ASCII字母之間差0x30   '1'=0x31 '2'=0x32... isdigit也是C語言標準函數(shù)
  20. else             //否則,不是數(shù)字,是字母
  21. {
  22.     switch(ch)    //根據(jù)字母選擇程序分支
  23.     {
  24.       case 'A': case 'a':  LCD_InsertChar(AA);break;  //字符A
  25.       case 'B': case 'b':  LCD_InsertChar(BB);break;  //字符B
  26.       case 'C': case 'c':  LCD_InsertChar(CC);break;  //...
  27.       case 'D': case 'd':  LCD_InsertChar(DD);break;  
  28.       case 'E': case 'e':  LCD_InsertChar(EE);break;
  29.       case 'F': case 'f':  LCD_InsertChar(FF);break;
  30.       case 'G': case 'g':  LCD_InsertChar(GG);break;
  31.       case 'H': case 'h':  LCD_InsertChar(HH);break;
  32.       case 'I': case 'i':  LCD_InsertChar(II);break;
  33.       case 'J': case 'j':  LCD_InsertChar(JJ);break;
  34.       case 'K': case 'k':  LCD_InsertChar(KK);break;
  35.       case 'L': case 'l':  LCD_InsertChar(LL);break;
  36.       case 'M': case 'm':  LCD_InsertChar(mm);break;
  37.       case 'N':            LCD_InsertChar(NN);break;
  38.       case 'n':            LCD_InsertChar(nn);break;
  39.       case 'O':            LCD_InsertChar(OO);break;
  40.       case 'o':            LCD_InsertChar(oo);break;
  41.       case 'P': case 'p':  LCD_InsertChar(PP);break;
  42.       case 'Q': case 'q':  LCD_InsertChar(QQ);break;
  43.       case 'R': case 'r':  LCD_InsertChar(rr);break;
  44.       case 'S': case 's':  LCD_InsertChar(SS);break;
  45.       case 'T': case 't':  LCD_InsertChar(tt);break;
  46.       case 'U': case 'v':  LCD_InsertChar(UU);break;
  47.       case 'V': case 'u':  LCD_InsertChar(VV);break;
  48.       case 'W': case 'w':  LCD_InsertChar(WW);break;
  49.       case 'Y': case 'y':  LCD_InsertChar(YY);break;  //...
  50.       case 'Z': case 'z':  LCD_InsertChar(ZZ);break;  //字符Z
  51.       case '-':            LCD_InsertChar(BR);break;  //字符-
  52.       case '`':            LCD_InsertChar(DT);break;  //字符`
  53.       case ' ':            LCD_InsertChar(SP);break;  //空格
  54.       case '.':            LCDM1|=0x10;       break;  //小數(shù)點,直接顯示在右下角
  55.       case '\n': case '\r':  FirstChrFlag=1;  break;  //換行符的下一個字母將清屏
  56.       default :            LCD_InsertChar(SP);break;//顯示不出來的字母用空格替代
  57.       }
  58.   }
  59. return(ch);  //返回顯示的字符(putchar函數(shù)標準格式要求返回顯示字符)
  60. }

  61. /****************************************************************************
  62. * 名    稱:putchar()
  63. * 功    能:向標準終端設(shè)備發(fā)送一字節(jié)數(shù)據(jù)(1個ASCII字符)
  64. * 入口參數(shù):ch: 待發(fā)送的字符  
  65. * 出口參數(shù):發(fā)出的字符
  66. * 說    明: UART.c內(nèi)的putchar函數(shù)printf函數(shù),這里從串口輸出字符到PC機的超
  67.             級終端軟件上,printf的結(jié)果將打印到超級終端上。供對比。
  68. ****************************************************************************/
  69. /*
  70. int putchar(int ch)
  71. {
  72.   if (ch == '\n')        //  '\n'(回車)擴展成 '\n''\r' (回車+換行)
  73.   {
  74.     UART_PutChar(0x0d) ; //'\r'
  75.   }
  76.   UART_PutChar(ch);      //從串口發(fā)出數(shù)據(jù)  
  77.   return (ch);
  78. }
  79. */
復(fù)制代碼



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:521781 發(fā)表于 2019-5-23 21:14 | 只看該作者
LCD庫頭文件是什么
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表