查看: 2534|回复: 1

[分享] 【YL-KL26Z试用】自制LCD5110显示系统__3

[复制链接]
  • TA的每日心情
    奋斗
    2023-2-15 00:12
  • 签到天数: 969 天

    连续签到: 1 天

    [LV.10]以坛为家III

    175

    主题

    2843

    帖子

    34

    金牌会员

    Rank: 6Rank: 6

    积分
    7123
    最后登录
    2023-4-20
    发表于 2016-1-30 19:00:08 | 显示全部楼层 |阅读模式
        有了前面的相关知识,那才能通过软件与硬件的结合来实现显示系统的构建呢?
    在YL-KL26Z开发板上,为了驱动LCD5110显示屏,需要构建相应的显示电路,其接口电路如下图所示。


    在显示电路中,除了电源的连接外,仅需4GPIO口即可完成线路的连接,且4GPIO口均作为输出口来使用。在传送数据和指令时,是采用串行方式模拟SPI接口来执行操作的。
    在显示过程中,需用到的函数有:字节指令写入函数LCD_write_byte Cmd()、字节数据写入函数LCD_write_byte Data()、显示定位函数LCD_set_XY()、清屏函数LCD_clear()、填充函数LCD_Fill()、LCD5110初始化函数LCD_Init()、单字符显示函数LCD_write_char()、字符串输出函数LCD_write_english_string()、 16*32点阵汉字输出函数LCD_write_dangehanz()、 12*24点阵汉字输出函数LCD_write_hanzi()、 界面显示函数jm()及延时函数等。
         具体的LCD5110显示程序其代码如下:
    1. #include "includes.h"
    2. // LCD5110显示汉字正常
    3. // RST   PD2   复位控制
    4. // DC    PD3   数据/指令选择
    5. // SDIN  PD4   SPI接口数据收发
    6. // SCLK  PD5  SPI接口时钟输出
    7. #define true  1
    8. #define flase 0
    9. #define SetLCD_SCLK_High()  { GPIO_SET(MKL_PORTD,5);}      
    10. #define SetLCD_SCLK_Low()          { GPIO_CLR(MKL_PORTD,5);}
    11. #define SetLCD_SDIN_High()  { GPIO_SET(MKL_PORTD,4);}      
    12. #define SetLCD_SDIN_Low()          { GPIO_CLR(MKL_PORTD,4);}
    13. #define SetLCD_DC_High()          { GPIO_SET(MKL_PORTD,3);}
    14. #define SetLCD_DC_Low()            { GPIO_CLR(MKL_PORTD,3);}      
    15. #define SetLCD_RST_High()          { GPIO_SET(MKL_PORTD,2);}      
    16. #define SetLCD_RST_Low()          { GPIO_CLR(MKL_PORTD,2);}
    17. #define Lcd_Max_x 84
    18. #define Lcd_Max_y 6
    19. #define LCD_Max_Dot_X 84   //84 48
    20. #define LCD_Max_Dot_Y 48   //84 48
    21. #define COM  0
    22. #define DAT  1
    23. #define STR  1  
    24. #define HAN  2
    25. #define Nokia5110_basic_fun_set  0x20
    26. #define Nokia5110_expand_fun_set 0x21
    27. #define Nokia5110_dis_set  0x0c
    28. #define Nokia5110_DispMode_AllLightOff 0x08
    29. #define Nokia5110_DispMode_AllLightOn 0x09
    30. #define Nokia5110_DispMode_Reverse 0x0d
    31. #define Nokia5110_add_Yset  0x40          //Y
    32. #define Nokia5110_add_Xset  0x80          //X
    33. #define Nokia5110_tem_set   0x06
    34. #define Nokia5110_vot_set   0xD7
    35. void myDelay (INT32U ulTime)
    36. {   INT32U i;
    37.     i = 0;
    38.    while (ulTime--)
    39.    {
    40.       for (i = 0; i < 5000; i++);
    41.     }
    42. }
    43. unsigned char font6x8[][6] =
    44. {
    45.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },   // sp
    46.     { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 },   // !
    47.     { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
    48.     { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 },   // #
    49.                 ... ...
    50. };
    51. //    色彩识别仪
    52. unsigned char font16x16[][32]={
    53. {0x20,0x10,0xE8,0x24,0x27,0x24,0x24,0xE4,
    54. 0x24,0x34,0x2C,0x20,0xE0,0x00,0x00,0x00,
    55. 0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x43,
    56. 0x42,0x42,0x42,0x42,0x43,0x40,0x78,0x00},//色
    57. {0x00,0x14,0x64,0x04,0x0C,0xB2,0x02,0x23,
    58. 0x1A,0x00,0x20,0x10,0x08,0x86,0x60,0x00,
    59. 0x40,0x21,0x11,0x0D,0x03,0xFF,0x05,0x09,
    60. 0x11,0x80,0x84,0x42,0x21,0x10,0x0C,0x00},//彩
    61. {0x40,0x40,0x42,0xCC,0x00,0x00,0x00,0xFC,
    62. 0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,
    63. 0x00,0x00,0x00,0x3F,0x10,0x88,0x40,0x23,
    64. 0x19,0x01,0x01,0x09,0x11,0x23,0xC0,0x00},//识
    65. {0x00,0x3E,0x22,0xE2,0x22,0x22,0x22,0x3E,
    66. 0x00,0x00,0xF8,0x00,0x00,0xFF,0x00,0x00,
    67. 0x81,0x41,0x31,0x0F,0x41,0x81,0x41,0x3F,
    68. 0x00,0x00,0x0F,0x40,0x80,0x7F,0x00,0x00},//别
    69. {0x00,0x80,0x60,0xF8,0x07,0x00,0x1C,0xE0,
    70. 0x01,0x06,0x00,0xE0,0x1E,0x00,0x00,0x00,
    71. 0x01,0x00,0x00,0xFF,0x00,0x80,0x40,0x20,
    72. 0x13,0x0C,0x13,0x20,0x40,0x80,0x80,0x00},//仪
    73. };
    74. const unsigned char chinese_character[][24]=
    75. {
    76. //0 tian 天
    77. {0x20,0x22,0x22,0x22,0xA2,0x7E,0xA2,0x22,0x22,0x22,0x20,0x00,0x08,0x08,0x04,0x02,0x01,0x00,0x01,0x02,0x04,0x08,0x08,0x00},
    78. //1 jin  津
    79. {0x22,0x44,0x00,0x08,0xAA,0xAA,0xFF,0xAA,0xAA,0xBE,0x08,0x00,0x04,0x02,0x01,0x02,0x02,0x02,0x0F,0x02,0x02,0x02,0x02,0x00},
    80. //2 li   理
    81. {0x12,0x12,0xFE,0x12,0x3F,0xA5,0xA5,0xFF,0xA5,0xA5,0x3F,0x00,0x02,0x02,0x01,0x05,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x00},
    82. //3 gong 工
    83. {0x00,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x03,0x02,0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0x04,0x00},
    84. //4 da   大
    85. {0x08,0x08,0x08,0x08,0xC8,0x3F,0xC8,0x08,0x08,0x0C,0x08,0x00,0x04,0x04,0x02,0x01,0x00,0x00,0x00,0x01,0x02,0x04,0x04,0x00},
    86. //5 xue  学
    87. {0x9C,0x84,0x95,0x96,0x95,0xD6,0xB4,0x94,0x87,0x94,0x8C,0x00,0x00,0x00,0x00,0x04,0x04,0x07,0x00,0x00,0x00,0x00,0x00,0x00}
    88. };
    89. long int delay_1us(void)
    90. {
    91.         long int count=2;
    92.         while(count--);
    93.         return 0;
    94. }
    95. /*-----------------------------------------------------------------------
    96. LCD_write_byte Cmd   
    97. -----------------------------------------------------------------------*/
    98. void LCD_write_CMD(unsigned char com)
    99. {   unsigned char uci;
    100.     SetLCD_DC_Low();
    101.         for(uci=0;uci<8;uci++)
    102.         {
    103.                 if(com & 0x80)
    104.                 {
    105.                         SetLCD_SDIN_High();
    106.                   }
    107.                 else
    108.                 {
    109.                         SetLCD_SDIN_Low();
    110.                   }
    111.                 SetLCD_SCLK_Low();       
    112.                 com = com << 1;
    113.                 delay_1us();       
    114.                 SetLCD_SCLK_High();
    115.         }
    116. }
    117. /*-----------------------------------------------------------------------
    118. LCD_write_byte Data         
    119. -----------------------------------------------------------------------*/
    120. void LCD_write_Data(unsigned char dt)
    121. {   unsigned char uci;
    122.     SetLCD_DC_High();
    123.         for(uci=0;uci<8;uci++)
    124.         {        if(dt & 0x80)
    125.                 {
    126.                         SetLCD_SDIN_High();
    127.                   }
    128.                 else
    129.                 {
    130.                         SetLCD_SDIN_Low();
    131.                   }
    132.                 delay_1us();
    133.                 SetLCD_SCLK_Low();
    134.                 dt = dt << 1;
    135.                 SetLCD_SCLK_High();
    136.         }
    137. }
    138. /*-----------------------------------------------------------------------
    139. LCD_set_XY        
    140. x:0-83 Y:0-5
    141. -----------------------------------------------------------------------*/
    142. void LCD_set_XY(unsigned char X, unsigned char Y)
    143. {
    144.     LCD_write_CMD(0x40 | (Y & 0X07));                // column
    145.     LCD_write_CMD(0x80 | (X & 0X7F));              // row
    146. }
    147. /*-----------------------------------------------------------------------
    148. LCD_clear  
    149. -----------------------------------------------------------------------*/
    150. void LCD_Clear(void)
    151. {        int uii;
    152.         LCD_set_XY(0,0);
    153.         for(uii=0; uii<504; uii++)
    154.         {
    155.                 LCD_write_Data(0x00);
    156.         }
    157. }
    158. /*-----------------------------------------------------------------------
    159. LCD_Fill   
    160. -----------------------------------------------------------------------*/
    161. void LCD_Fill(void)
    162. {        uint16_t uii;                       
    163.         LCD_set_XY(0,0);
    164.         for(uii=0; uii<504; uii++)
    165.         {
    166.                 LCD_write_Data(0xff);
    167.         }
    168. }
    169. /*-----------------------------------------------------------------------
    170. LCD_Init   LCD5110
    171. -----------------------------------------------------------------------*/
    172. void LCD_Init(void)
    173. {        //RST   PD2   复位控制
    174.     //DC    PD3   数据/指令选择
    175.     //SDIN  PD4   SPI接口数据收发
    176.     //SCLK  PD5   SPI接口时钟输出
    177.         //PORT_ENABLE_CLK(MKL_PORTB);                                         /* 使能PORT时钟        */
    178.     PORT_ENABLE_CLK(MKL_PORTD);
    179. /* IO功能选择*/
    180.     IO_FUN_SEL(MKL_PORTD,2,1);  
    181.     IO_FUN_SEL(MKL_PORTD,3,1);                                                     
    182.     IO_FUN_SEL(MKL_PORTD,4,1);   
    183.     IO_FUN_SEL(MKL_PORTD,5,1);
    184. /* IO设置为输出模式     */               
    185.     GPIO_DDR_OUTPUT(MKL_PORTD,2);                                      
    186.     GPIO_DDR_OUTPUT(MKL_PORTD,3);
    187.     GPIO_DDR_OUTPUT(MKL_PORTD,4);
    188.     GPIO_DDR_OUTPUT(MKL_PORTD,5);     
    189. /* IO设置为高电平      */  
    190.     GPIO_SET(MKL_PORTD,2);                                             
    191.     GPIO_SET(MKL_PORTD,3);
    192.     GPIO_SET(MKL_PORTD,4);  
    193.     GPIO_SET(MKL_PORTD,5);
    194.         SetLCD_RST_Low();   
    195.         delay_1us();
    196.         SetLCD_RST_High();   
    197.         delay_1us();
    198.         delay_1us();
    199.         LCD_write_CMD(0x21);
    200.         LCD_write_CMD(0xc0);
    201.         LCD_write_CMD(0x06);
    202.         LCD_write_CMD(0x13);
    203.         LCD_write_CMD(0x20);
    204.         LCD_Clear();          
    205.         LCD_write_CMD(0x0c);       
    206. }
    207. /*-----------------------------------------------------------------------
    208. LCD_write_char  
    209. -----------------------------------------------------------------------*/
    210. void LCD_write_char(unsigned char c)
    211. {   unsigned char line;
    212.     c -= 32;
    213.     for (line=0; line<6; line++)
    214.         {
    215.               LCD_write_Data(font6x8[c][line]);
    216.           }
    217. }
    218. /*-----------------------------------------------------------------------
    219. LCD_write_english_string  
    220. -----------------------------------------------------------------------*/
    221. void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
    222. {   LCD_set_XY(X,Y);
    223.     while (*s)
    224.     {
    225.                  LCD_write_char(*s);
    226.                 s++;
    227.           }
    228. }
    229. void LCD_write_dangehanzi(unsigned char X,unsigned char Y,char s)
    230. {   do
    231.     {        char line;
    232.                 LCD_set_XY(X,Y);       
    233.                  for (line=0; line<16; line++)
    234.                 {       
    235.                         LCD_write_Data(font16x16[s][line]);
    236.                   }
    237.                 LCD_set_XY(X,Y+1);
    238.                 for (line=16; line<32; line++)
    239.                 {               
    240.                         LCD_write_Data(font16x16[s][line]);
    241.                   }
    242.           }while(0);               
    243. }
    244. void LCD_write_hanzi(unsigned char X,unsigned char Y,char s)
    245. {   do
    246.     {   char line;
    247.                 LCD_set_XY(X,Y);       
    248.                  for (line=0; line<12; line++)
    249.                 {       
    250.                         LCD_write_Data(chinese_character[s][line]);
    251.                   }
    252.                 LCD_set_XY(X,Y+1);
    253.                 for (line=12; line<24; line++)
    254.                 {               
    255.                         LCD_write_Data(chinese_character[s][line]);
    256.                   }
    257.           }while(0);               
    258. }
    259. void  jm(void)
    260. {        LCD_Clear();
    261.     LCD_write_dangehanzi(0,0,0);
    262.         LCD_write_dangehanzi(16,0,1);
    263.         LCD_write_dangehanzi(32,0,2);
    264.         LCD_write_dangehanzi(48,0,3);
    265.         LCD_write_dangehanzi(64,0,4);
    266.         LCD_write_hanzi(2,3,0);
    267.         LCD_write_hanzi(14,3,1);
    268.         LCD_write_hanzi(26,3,2);
    269.         LCD_write_hanzi(38,3,3);
    270.         LCD_write_hanzi(50,3,4);
    271.         LCD_write_hanzi(62,3,5);
    272.         LCD_write_english_string(0,5,"nokia5110 v1.0");
    273. }
    274. int  main (void)
    275. {
    276.     SystemCoreClockUpdate();
    277.     SIM_SCGC5 |= (SIM_SCGC5_PORTA_MASK
    278.                   | SIM_SCGC5_PORTB_MASK
    279.                   | SIM_SCGC5_PORTC_MASK
    280.                   | SIM_SCGC5_PORTD_MASK
    281.                   | SIM_SCGC5_PORTE_MASK );   
    282.    
    283.     /* 使能PORT时钟                 */
    284.     PORT_ENABLE_CLK(MKL_PORTD);
    285.     LCD_Init();
    286.     LCD_Clear();
    287.     jm();
    288.     while(1);
    289. }
    复制代码
    经程序的编译和下载,整个系统的构成和显示效果如图所示。


    显示接口电路图

    显示接口电路图

    LCD5110显示系统构成

    LCD5110显示系统构成
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    2025-5-7 09:07
  • 签到天数: 353 天

    连续签到: 1 天

    [LV.8]以坛为家I

    141

    主题

    8056

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    5785
    最后登录
    2025-5-7
    发表于 2016-1-31 12:29:59 | 显示全部楼层
    谢谢分享 ,5110看上去很靓
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-7-22 20:19 , Processed in 0.087669 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表