久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9223|回復: 2
收起左側(cè)

MSP430F4XX系列LCD顯示通用驅(qū)動程序

[復制鏈接]
ID:108615 發(fā)表于 2016-3-14 18:38 | 顯示全部樓層 |閱讀模式
本程序是《MSP430系列單片機系統(tǒng)工程設(shè)計與實踐》書里面的源碼,完整例程下載(包含工程文件 (例4.1.4))):http://www.zg4o1577.cn/bbs/dpj-46245-1.html

關(guān)于本程序的詳細解說大家可以下載電子書點擊上圖即可
  1. /*
  2.                
  3.                   MSP430F4XX系列LCD顯示通用驅(qū)動程序


  4.   說明:該驅(qū)動程序庫包含了常用的LCD顯示功能,如顯示數(shù)字、字母等
  5.         可以作為各種程序的底層驅(qū)動使用。
  6.         要使用該庫函數(shù),需要將本文件(LCD_Display.c)添加進工程,并在
  7.         需要調(diào)用顯示函數(shù)的文件開頭處包含"LCD_Display.h"


  8.   (C)西安電子科技大學 測控技術(shù)與儀器教研中心 編寫:謝楷 2008/02/02
  9.   
  10. */
  11. //
  12. //
  13. //                  MSP430F4XX
  14. //               +---------------+         Digital Number
  15. //               |               |         左8+ 7654321右
  16. //               |               |    +----------------------+
  17. //               |A0+      S0-S15|--->|   SoftBaugh LCD_048  |
  18. //               |A0-   COM0-COM3|--->|   7.1Digit,4-Mux LCD |
  19. //               |P2.0           |    +----------------------+
  20. //               |P2.1           |
  21. //               |VRef    R03-R33|<---LCD Voltage Ladder Rs
  22. //               |               |
  23. //               |       XIN/XOUT|<---32.768KHz Watch Crystal
  24. //               |               |
  25. //               +---------------+

  26. #include "msp430x42x.h"

  27. /*宏定義,數(shù)碼管a-g各段對應(yīng)的比特,更換硬件只用改動以下8行*/
  28. #define d       0x01                            //  AAAA
  29. #define g       0x02                            // F    B
  30. #define b       0x04                            // F    B
  31. #define a       0x08                            //  GGGG
  32. #define DOTSEG  0x10                            // E    C
  33. #define e       0x20                            // E    C
  34. #define f       0x40                            //  DDDD
  35. #define c       0x80
  36. #define NEGSEG  0x02  
  37. /*用宏定義自動生成段碼表,很好的寫法,值得學習*/
  38. /*更換硬件無需重寫段碼表*/
  39. const char LCD_Tab[] = {
  40.   a + b + c + d + e + f,                        // Displays "0"
  41.   b + c,                                        // Displays "1"
  42.   a + b + d + e + g,                            // Displays "2"
  43.   a + b + c + d + g,                            // Displays "3"
  44.   b + c + f + g,                                // Displays "4"
  45.   a + c + d + f +g,                             // Displays "5"
  46.   a + c + d + e + f + g,                        // Displays "6"
  47.   a + b + c,                                    // Displays "7"
  48.   a + b + c + d + e + f + g,                    // Displays "8"
  49.   a + b + c + d + f + g,                        // Displays "9"
  50.   a + b + c + e + f + g,                        // Displays "A"
  51.   c + d + e + f + g,                            // Displays "B"  
  52.   a + d + e + f,                                // Displays "C"
  53.   b + c + d + e + g,                               // Displays "D"
  54.   a + d + e + f + g,                            // Displays "E"
  55.   a + e + f + g,                                // Displays "F"
  56.   a + c + d + e + f,                            // Displays "G"
  57.   b + c + e + f + g,                            // Displays "H"  
  58.   e + f,                                        // Displays "I"
  59.   b + c + d + e,                                    // Displays "J"
  60.   b + d + e + f + g,                            // Displays "K"
  61.   d + e + f,                                    // Displays "L"  
  62.   a + c + e + g,                                    // Displays "M"
  63.   a + b + c + e + f,                            // Displays "N"   
  64.   c + e + g,                                    // Displays "n"
  65.   c + d + e + g,                                    // Displays "o"
  66.   a + b + c + d + e + f,                        // Displays "O"
  67.   a + b + e + f + g,                            // Displays "P"
  68.   a + b + c + f + g,                            // Displays "Q"
  69.   e + g,                                        // Displays "r"
  70.   a + c + d + f +g,                             // Displays "S"
  71.   d + e + f + g,                                    // Displays "t"
  72.   a + e + f ,                                    // Displays "T"
  73.   b + c + d + e + f,                            // Displays "U"
  74.   c + d + e,                                    // Displays "v"
  75.   b + d + f + g,                                    // Displays "W"
  76.   b + c + d + f + g,                            // Displays "Y"
  77.   a + b + d + e + g,                            // Displays "Z"
  78.   g,                                            // Displays "-"
  79.   b,                                            // Displays "'"  
  80.   0                                                    // Displays " "
  81. };
  82. #undef a
  83. #undef b
  84. #undef c
  85. #undef d
  86. #undef e
  87. #undef f
  88. #undef g

  89. #define AA 10
  90. #define BB AA+1
  91. #define CC BB+1
  92. #define DD CC+1
  93. #define EE DD+1
  94. #define FF EE+1
  95. #define GG FF+1
  96. #define HH GG+1
  97. #define II HH+1
  98. #define JJ II+1
  99. #define KK JJ+1
  100. #define LL KK+1
  101. #define mm LL+1
  102. #define NN mm+1
  103. #define nn NN+1
  104. #define oo nn+1
  105. #define OO oo+1
  106. #define PP OO+1
  107. #define QQ PP+1
  108. #define rr QQ+1
  109. #define SS rr+1
  110. #define tt SS+1
  111. #define TT tt+1
  112. #define UU TT+1
  113. #define VV UU+1
  114. #define WW VV+1
  115. #define YY WW+1
  116. #define ZZ YY+1
  117. #define BR ZZ+1     /*   -  */
  118. #define DT BR+1     /*   '  */
  119. #define SP DT+1     /* 空白 */

  120. /****************************************************************************
  121. * 名    稱:LCD_Init()
  122. * 功    能:初始化LCD顯示屏。
  123. * 入口參數(shù):無
  124. * 出口參數(shù):無
  125. * 說    明: 在主程序LCD操作之前,需要調(diào)用該函數(shù)設(shè)置LCD參數(shù)。
  126. ****************************************************************************/
  127. void LCD_Init()
  128. { char i;
  129.   char *pLCD = (char *)&LCDM1;                  // 取LCDM1寄存器(最低位)的地址
  130.   for (i = 0; i < 8; i++)                       // Clear LCD memory
  131.   *pLCD++ = 0;                                  // 清屏
  132.   LCDCTL  = LCDSG0_1 + LCD4MUX + LCDON;         // LCD模式:4mux LCD, segs0-15
  133.   BTCTL  |= BT_fLCD_DIV64;                      // 設(shè)置 LCD 刷新率
  134.   /*刷新率越慢功耗越低,但速度太慢LCD會閃爍*/
  135. }

  136. /****************************************************************************
  137. * 名    稱:LCD_DisplayLongDecimal()
  138. * 功    能:在LCD上顯示一個帶有小數(shù)點的長數(shù)據(jù)。
  139. * 入口參數(shù):Number:顯示數(shù)值  (-999999~9999999)
  140.             DOT   :小數(shù)點位數(shù)(0~3)
  141. * 出口參數(shù):無
  142. * 范    例: LCD_DisplayDecimal( 123456,2); 顯示結(jié)果: 1234.56 (2位小數(shù))
  143.             LCD_DisplayDecimal(-123456,1); 顯示結(jié)果:-12345.6 (1位小數(shù))
  144. * 說    明: 該函數(shù)能夠顯示滿屏7位數(shù)字,但執(zhí)行時間較長,耗電大。
  145. ****************************************************************************/
  146. void LCD_DisplayLongDecimal( long int Number, char DOT)
  147. {
  148.   char Neg;
  149.   char i;unsigned char temp;
  150.   char *pLCD = (char *)&LCDM1;
  151.   char PolarLocate;
  152.   char DispBuff[8];

  153.   if(Number<0) {Number=-Number; Neg=1;}  //處理負數(shù)
  154.   else          Neg=0;
  155.   for(i=0;i<7;i++)                       //拆分數(shù)字
  156.    {
  157.      DispBuff[i]=Number%10;
  158.      Number/=10;
  159.    }
  160.   for(i=6;i>DOT;i--)                     //消隱無效"0"
  161.    {
  162.      if (DispBuff[i]==0) DispBuff[i]=SP;   
  163.      else break;
  164.    }
  165.   PolarLocate=i+1;    // 負號顯示在第一個有效數(shù)字左邊  
  166.   if(DOT>3) DOT=255;  // 無效的小數(shù)點不顯示
  167.   if(DOT<1) DOT=255;  // LCD048段碼中只有123位數(shù)字有小數(shù)點
  168.   for(i=0;i<7;i++)
  169.     {
  170.       temp=LCD_Tab[DispBuff[i]]; //查表
  171.       if (DOT==i)            temp|=DOTSEG;//顯示小數(shù)點
  172.       if ((PolarLocate==i)&&(Neg))   temp|=NEGSEG;//負號
  173.       pLCD[i]=temp; //寫入顯存
  174.     }
  175. }
  176. /****************************************************************************
  177. * 名    稱:LCD_DisplayDecimal()
  178. * 功    能:在LCD上顯示一個帶有小數(shù)點的短整型數(shù)據(jù)。
  179. * 入口參數(shù):Number:顯示數(shù)值  (-32768~32767)
  180.             DOT   :小數(shù)點位數(shù)(0~3)
  181. * 出口參數(shù):無
  182. * 范    例: LCD_DisplayDecimal( 12345,2); 顯示結(jié)果: 123.45 (2位小數(shù))
  183.             LCD_DisplayDecimal(-12345,1); 顯示結(jié)果:-1234.5 (1位小數(shù))
  184. * 說    明: 該函數(shù)顯示數(shù)值范圍小,但執(zhí)行時間短,耗電小。
  185. ****************************************************************************/
  186. void LCD_DisplayDecimal( int Number, char DOT)
  187. {
  188.   char Neg;
  189.   char i;unsigned char temp;
  190.   char *pLCD = (char *)&LCDM1;
  191.   char PolarLocate;
  192.   char DispBuff[8];

  193.   if(Number<0) {Number=-Number; Neg=1;}  //處理負數(shù)
  194.   else          Neg=0;
  195.   for(i=0;i<7;i++)                       //拆分數(shù)字
  196.    {
  197.      DispBuff[i]=Number%10;
  198.      Number/=10;
  199.    }
  200.   for(i=6;i>DOT;i--)                     //消隱無效"0"
  201.    {
  202.      if (DispBuff[i]==0) DispBuff[i]=SP;   
  203.      else break;
  204.    }
  205.   PolarLocate=i+1;    // 負號顯示在第一個有效數(shù)字左邊  
  206.   if(DOT>3) DOT=255;  // 無效的小數(shù)點不顯示
  207.   if(DOT<1) DOT=255;  // LCD048段碼中只有123位數(shù)字有小數(shù)點
  208.   for(i=0;i<7;i++)
  209.     {
  210.       temp=LCD_Tab[DispBuff[i]]; //查表
  211.       if (DOT==i)            temp|=DOTSEG;//顯示小數(shù)點
  212.       if ((PolarLocate==i)&&(Neg))   temp|=NEGSEG;//負號
  213.       pLCD[i]=temp; //寫入顯存
  214.     }
  215. }

  216. /****************************************************************************
  217. * 名    稱:LCD_DisplayLongNumber()
  218. * 功    能:在LCD上顯示一個長整數(shù)。
  219. * 入口參數(shù):Number:顯示數(shù)值  (-999999~9999999)
  220. * 出口參數(shù):無
  221. * 范    例: LCD_DisplayNumber( 123456); 顯示結(jié)果: 123456
  222.             LCD_DisplayNumber(-123456); 顯示結(jié)果:-123456
  223. * 說    明: 該函數(shù)能夠顯示滿屏7位數(shù)字,但執(zhí)行時間較長,耗電大。
  224. ****************************************************************************/
  225. void LCD_DisplayLongNumber(long int Number)
  226. {
  227.    LCD_DisplayLongDecimal(Number,0) ;//整數(shù)沒有小數(shù)點
  228. }
  229. /****************************************************************************
  230. * 名    稱:LCD_DisplayNumber()
  231. * 功    能:在LCD上顯示一個短整數(shù)。
  232. * 入口參數(shù):Number:顯示數(shù)值  (-32768~32767)
  233. * 出口參數(shù):無
  234. * 范    例: LCD_DisplayNumber( 12345); 顯示結(jié)果: 12345
  235.             LCD_DisplayNumber(-12345); 顯示結(jié)果:-12345
  236. ****************************************************************************/
  237. void LCD_DisplayNumber(int Number)
  238. {
  239.    LCD_DisplayDecimal(Number,0) ;//整數(shù)沒有小數(shù)點
  240. }
  241. /****************************************************************************
  242. * 名    稱:LCD_DisplayChar()
  243. * 功    能:在LCD上顯示一個字符。
  244. * 入口參數(shù):ch      :顯示內(nèi)容  可顯示字母請參考LCD_Display.h中的宏定義
  245.             Location:顯示位置  從左至右對應(yīng)76543210
  246. * 出口參數(shù):無
  247. * 說    明: 調(diào)用該函數(shù)不影響LCD其他位的顯示。但顯示數(shù)字的函數(shù)會覆蓋該函數(shù)的結(jié)
  248.             果,因此該函數(shù)要在顯示數(shù)據(jù)函數(shù)之后調(diào)用。
  249. * 范    例: LCD_DisplayChar(AA,4);
  250.             LCD_DisplayChar(PP,5);
  251.             LCD_DisplayChar(2 ,6); 顯示結(jié)果: 2PAXXXX
  252. ****************************************************************************/
  253. void LCD_DisplayChar(char ch,char Location)
  254. {
  255.    char *pLCD = (char *)&LCDM1;
  256.    pLCD[Location]=LCD_Tab[ch];
  257. }
  258. /****************************************************************************
  259. * 名    稱:LCD_InsertChar()
  260. * 功    能:在LCD最右端插入一個字符。
  261. * 入口參數(shù):ch      :插入字符  可顯示字母請參考LCD_Display.h中的宏定義
  262. * 出口參數(shù):無
  263. * 說    明: 調(diào)用該函數(shù)后,LCD所有已顯示字符左移一位,新的字符插入在最右端一位。
  264.             該函數(shù)可以實現(xiàn)滾屏動畫效果,或用于在數(shù)據(jù)后面顯示單位。
  265. * 范    例: LCD_DisplayDecimal(1234,1);
  266.             LCD_InsertChar(PP);
  267.             LCD_InsertChar(FF);顯示結(jié)果: 123.4PF
  268.             
  269. ****************************************************************************/
  270. void LCD_InsertChar(char ch)
  271. {  char i;
  272.    char *pLCD = (char *)&LCDM1;
  273.    for(i=6;i>=1;i--) pLCD[i]=pLCD[i-1];
  274.    pLCD[0]=LCD_Tab[ch];
  275. }
  276. /****************************************************************************
  277. * 名    稱:LCD_ON()
  278. * 功    能:開啟LCD顯示
  279. * 入口參數(shù):無
  280. * 出口參數(shù):無
  281. * 說    明: 調(diào)用該函數(shù)將開啟LCD顯示。開啟后LCD仍顯示最后一次顯示內(nèi)容
  282. ****************************************************************************/
  283. void LCD_ON()
  284. {
  285.    LCDCTL  |= LCDON;
  286. }
  287. /****************************************************************************
  288. * 名    稱:LCD_ON()
  289. * 功    能:關(guān)閉LCD顯示
  290. * 入口參數(shù):無
  291. * 出口參數(shù):無
  292. * 說    明: 調(diào)用該函數(shù)將關(guān)閉LCD顯示,可節(jié)省3~5uA電流。該函數(shù)不清除顯示內(nèi)容。
  293. ****************************************************************************/
  294. void LCD_OFF()
  295. {
  296.    LCDCTL  &=~ LCDON;
  297. }

  298. /****************************************************************************
  299. * 名    稱:LCD_Clear()
  300. * 功    能: 清除LCD顯示
  301. * 入口參數(shù):無
  302. * 出口參數(shù):無
  303. * 說    明: 調(diào)用該函數(shù)將LCD顯示清除,但并不關(guān)閉LCD模塊。
  304. ****************************************************************************/
  305. void LCD_Clear()
  306. { char i;
  307.   char *pLCD = (char *)&LCDM1;     // 取LCDM1寄存器(最低位)的地址
  308.   for (i = 0; i < 8; i++)          // Clear LCD memory
  309.   {
  310.     *pLCD++ = 0;                    //清屏
  311.   }
  312. }
復制代碼



回復

使用道具 舉報

ID:874711 發(fā)表于 2021-1-7 11:19 | 顯示全部樓層
你好,頭文件還有么,能否發(fā)一份
回復

使用道具 舉報

ID:957828 發(fā)表于 2021-7-31 10:25 | 顯示全部樓層
請問能移植到msp432上嗎
回復

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产在线观看一区二区三区 | 国产99久久精品一区二区永久免费 | 日韩1区| 欧美电影在线 | av片免费| 久久精品国产一区二区三区 | 国产福利在线免费观看 | 成人激情视频免费在线观看 | 国产草草视频 | 亚洲福利电影网 | 黄色大片视频 | 欧美在线视频一区二区 | 亚洲精品电影 | 美女久久久久久久 | aaaaaaa片毛片免费观看 | 中文字幕在线观看一区 | 国产ts人妖一区二区三区 | 成人在线精品视频 | 国产精品毛片一区二区三区 | 99资源站| 精品国产精品三级精品av网址 | 国产福利在线视频 | 久久亚洲欧美日韩精品专区 | 日韩在线中文 | 中文字幕在线免费观看 | www.99精品 | 日韩精品1区2区3区 成人黄页在线观看 | 久久精品这里精品 | 欧美综合一区二区 | 色综合久久天天综合网 | 国产精品成人在线 | 瑟瑟视频在线看 | 亚洲国产精品久久久 | 午夜视频在线免费观看 | 精品乱人伦一区二区三区 | 日韩电影在线 | 久久日韩粉嫩一区二区三区 | 一级毛片成人免费看a | 成人精品久久 | 亚洲精品国产电影 | 欧美日韩视频在线播放 |