[应用方案] 【新唐资料分享月】基于NuTiny-EVB-M058S开发板实现LCD5110显示

[复制链接]
 楼主| jinglixixi 发表于 2016-12-13 09:25 | 显示全部楼层 |阅读模式
NuTiny-EVB-M058S开发板是一款小巧的学习工具,为了便于进行人机交互,为它配置一块液晶显示屏是一个不错的选择。LCD5110在众多的液晶显示屏中是一种比较有特点的显示器件,它能耗低,显示字符量相对较高,价格也较为便宜,故选取LCD5110为显示目标。
图片1.png
    图1  LCD5110显示效果
    图片2.png    
    图2 配温湿度传感器的显示效果

程序代码如下:
  1. //基于NuTiny-EVB-M058SSAN-LQFP64 V2.1开发板
  2. //实现LCD5110液晶屏显示功能
  3. #include <stdint.h>
  4. #include "M051.h"
  5. #include "Register_Bit.h"
  6. #include "Common.h"
  7. #include "Macro_SystemClock.h"
  8. #include "Macro_Timer.h"
  9. #define CLOCK_SETUP           1
  10. #define CLOCK_EN              0xF
  11. #define PLL_Engine_Enable       1
  12. #define PLL_SEL               0x00000000
  13. #define CLOCK_SEL             0x0
  14. #define GPIO_SETUP            1
  15. #define P3_MODE                    0x5555
  16. //SCE --GND
  17. //SCLK--P3.3
  18. //DIN --P3.2
  19. //DC  --P3.1
  20. //RST --P3.0
  21. #define SetLCD_RST_High()          P3_DOUT|=  1UL<<0
  22. #define SetLCD_RST_Low()          P3_DOUT&=~(1UL<<0)
  23. #define SetLCD_DC_High()          P3_DOUT|=  1UL<<1
  24. #define SetLCD_DC_Low()            P3_DOUT&=~(1UL<<1)
  25. #define SetLCD_SDIN_High()        P3_DOUT|=  1UL<<2
  26. #define SetLCD_SDIN_Low()          P3_DOUT&=~(1UL<<2)
  27. #define SetLCD_SCLK_High()        P3_DOUT|=  1UL<<3
  28. #define SetLCD_SCLK_Low()          P3_DOUT&=~(1UL<<3)
  29. void TMR0_Delay1ms(uint32_t ulCNT);
  30. void Timer0_Init(void);
  31. unsigned char font6x8[][6] =
  32. {    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },   // sp
  33.     { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 },   // !
  34.     { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
  35.     { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 },   // #
  36.     { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 },   // $
  37. 。。。
  38. }
  39. // 向LCD5110写指令
  40. void LCD_write_CMD(unsigned char com)
  41. {
  42.     unsigned char uci;
  43.     SetLCD_DC_Low();
  44.         for(uci=0;uci<8;uci++)
  45.         {
  46.                 if(com & 0x80)
  47.                 {
  48.                         SetLCD_SDIN_High();
  49.                   }
  50.                 else
  51.                 {
  52.                         SetLCD_SDIN_Low();
  53.                   }
  54.                 SetLCD_SCLK_Low();         
  55.                 com = com << 1;
  56.                 SetLCD_SCLK_High();
  57.         }
  58. }
  59. //  显示定位
  60. void LCD_set_XY(unsigned char X, unsigned char Y)
  61. {
  62.     LCD_write_CMD(0x40 | (Y & 0X07));                // column
  63.     LCD_write_CMD(0x80 | (X & 0X7F));             // row
  64. }
  65. // 向LCD5110写字节数据
  66. void LCD_write_Data(unsigned char dt)
  67. {
  68.      unsigned char uci;
  69.      SetLCD_DC_High();
  70.          for(uci=0;uci<8;uci++)
  71.          {
  72.                 if(dt & 0x80)
  73.                 {
  74.                         SetLCD_SDIN_High();
  75.           }
  76.                 else
  77.                 {
  78.                         SetLCD_SDIN_Low();
  79.             }
  80.                 SetLCD_SCLK_Low();
  81.                 dt = dt << 1;
  82.                 SetLCD_SCLK_High();
  83.          }
  84. }
  85. // 清屏
  86. void LCD_Clear(void)
  87. {
  88.         int uii;
  89.         LCD_set_XY(0,0);
  90.         for(uii=0; uii<504; uii++)
  91.         {
  92.                 LCD_write_Data(0x00);
  93.         }
  94. }
  95. //  LCD5110初始化
  96. void LCD_Init(void)
  97. {
  98.          SetLCD_RST_Low();   
  99.          delay_1us();
  100.          SetLCD_RST_High();   
  101.          delay_1us();
  102.          delay_1us();
  103.      LCD_write_CMD(0x21);
  104.          LCD_write_CMD(0xc0);
  105.          LCD_write_CMD(0x06);
  106.          LCD_write_CMD(0x13);
  107.          LCD_write_CMD(0x20);
  108.          LCD_Clear();  
  109.          LCD_write_CMD(0x0c);
  110. }
  111. // 在LCD5110 显示一个字符
  112. void LCD_write_char(unsigned char c)
  113. {
  114.     unsigned char line;
  115.     c -= 32;
  116.     for (line=0; line<6; line++)
  117.           {
  118.               LCD_write_Data(font6x8[c][line]);
  119.             }
  120. }
  121. // 在LCD5110 显示字符串
  122. void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
  123. {
  124.     LCD_set_XY(X,Y);
  125.     while (*s)
  126.     {
  127.                  LCD_write_char(*s);
  128.                 s++;
  129.            }
  130. }
  131. //  显示测试
  132. void TestLCD_Nokia5110(void)
  133. {
  134.         LCD_Init();
  135.         LCD_Clear();
  136.         LCD_write_english_string(0,0,"LCD 5110 Test");               
  137.         delayms(100);       
  138.     LCD_write_english_string(0,1,"ARM Cortex-M0");                 
  139.         delayms(100);
  140.         LCD_write_english_string(0,2," NuTiny-EVB- ");
  141.         delayms(100);
  142.         LCD_write_english_string(0,3,"M058SSAN V2.1");
  143.     delayms(100);  
  144.         LCD_write_english_string(0,4,"Design:lijing");
  145.         delayms(100);  
  146. }
  147. //  主函数
  148. main(void)
  149. {
  150.     Un_Lock_Reg();
  151.         PWRCON |= XTL12M_EN;
  152.         while((CLKSTATUS & XTL12M_STB) == 0);                 // Wait until 12M clock is stable.       
  153.         CLKSEL0 = (CLKSEL0 & (~HCLK)) | HCLK_12M;        //Set external crystal as the system clock
  154.     Timer0_Init();
  155.     TestLCD_Nokia5110();
  156.         while(1);
  157. }
在使用YBDZ转换板替代原Smart M05X时,需将YBDZ上的RSTP3.5连接,通过按K4键来实现复位处理来执行显示功能。否则不能执行正常显示。
在使用NuTiny-EVB-M058SSAN-LQFP64 V2.1开发板替代原Smart M05X时,需使用开发板上的USB接口来供电,否则用外接的稳压电源无法工作,原因待查。
      图片3.png
   图3  YBDZ转换板的LCD5110显示效果

dongnanxibei 发表于 2016-12-13 21:20 | 显示全部楼层
这个显示屏貌似SPI接口的,非常流行,作为学习的显示器。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

518

主题

2934

帖子

39

粉丝
快速回复 在线客服 返回列表 返回顶部