NuTiny-EVB-M058S开发板是一款小巧的学习工具,为了便于进行人机交互,为它配置一块液晶显示屏是一个不错的选择。LCD5110在众多的液晶显示屏中是一种比较有特点的显示器件,它能耗低,显示字符量相对较高,价格也较为便宜,故选取LCD5110为显示目标。 图1 LCD5110显示效果 图2 配温湿度传感器的显示效果
程序代码如下: - //基于NuTiny-EVB-M058SSAN-LQFP64 V2.1开发板
- //实现LCD5110液晶屏显示功能
- #include <stdint.h>
- #include "M051.h"
- #include "Register_Bit.h"
- #include "Common.h"
- #include "Macro_SystemClock.h"
- #include "Macro_Timer.h"
- #define CLOCK_SETUP 1
- #define CLOCK_EN 0xF
- #define PLL_Engine_Enable 1
- #define PLL_SEL 0x00000000
- #define CLOCK_SEL 0x0
- #define GPIO_SETUP 1
- #define P3_MODE 0x5555
- //SCE --GND
- //SCLK--P3.3
- //DIN --P3.2
- //DC --P3.1
- //RST --P3.0
- #define SetLCD_RST_High() P3_DOUT|= 1UL<<0
- #define SetLCD_RST_Low() P3_DOUT&=~(1UL<<0)
- #define SetLCD_DC_High() P3_DOUT|= 1UL<<1
- #define SetLCD_DC_Low() P3_DOUT&=~(1UL<<1)
- #define SetLCD_SDIN_High() P3_DOUT|= 1UL<<2
- #define SetLCD_SDIN_Low() P3_DOUT&=~(1UL<<2)
- #define SetLCD_SCLK_High() P3_DOUT|= 1UL<<3
- #define SetLCD_SCLK_Low() P3_DOUT&=~(1UL<<3)
- void TMR0_Delay1ms(uint32_t ulCNT);
- void Timer0_Init(void);
- unsigned char font6x8[][6] =
- { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
- { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
- { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
- { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
- { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
- 。。。
- }
- // 向LCD5110写指令
- void LCD_write_CMD(unsigned char com)
- {
- unsigned char uci;
- SetLCD_DC_Low();
- for(uci=0;uci<8;uci++)
- {
- if(com & 0x80)
- {
- SetLCD_SDIN_High();
- }
- else
- {
- SetLCD_SDIN_Low();
- }
- SetLCD_SCLK_Low();
- com = com << 1;
- SetLCD_SCLK_High();
- }
- }
- // 显示定位
- void LCD_set_XY(unsigned char X, unsigned char Y)
- {
- LCD_write_CMD(0x40 | (Y & 0X07)); // column
- LCD_write_CMD(0x80 | (X & 0X7F)); // row
- }
- // 向LCD5110写字节数据
- void LCD_write_Data(unsigned char dt)
- {
- unsigned char uci;
- SetLCD_DC_High();
- for(uci=0;uci<8;uci++)
- {
- if(dt & 0x80)
- {
- SetLCD_SDIN_High();
- }
- else
- {
- SetLCD_SDIN_Low();
- }
- SetLCD_SCLK_Low();
- dt = dt << 1;
- SetLCD_SCLK_High();
- }
- }
- // 清屏
- void LCD_Clear(void)
- {
- int uii;
- LCD_set_XY(0,0);
- for(uii=0; uii<504; uii++)
- {
- LCD_write_Data(0x00);
- }
- }
- // LCD5110初始化
- void LCD_Init(void)
- {
- SetLCD_RST_Low();
- delay_1us();
- SetLCD_RST_High();
- delay_1us();
- delay_1us();
- LCD_write_CMD(0x21);
- LCD_write_CMD(0xc0);
- LCD_write_CMD(0x06);
- LCD_write_CMD(0x13);
- LCD_write_CMD(0x20);
- LCD_Clear();
- LCD_write_CMD(0x0c);
- }
- // 在LCD5110 显示一个字符
- void LCD_write_char(unsigned char c)
- {
- unsigned char line;
- c -= 32;
- for (line=0; line<6; line++)
- {
- LCD_write_Data(font6x8[c][line]);
- }
- }
- // 在LCD5110 显示字符串
- void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
- {
- LCD_set_XY(X,Y);
- while (*s)
- {
- LCD_write_char(*s);
- s++;
- }
- }
- // 显示测试
- void TestLCD_Nokia5110(void)
- {
- LCD_Init();
- LCD_Clear();
- LCD_write_english_string(0,0,"LCD 5110 Test");
- delayms(100);
- LCD_write_english_string(0,1,"ARM Cortex-M0");
- delayms(100);
- LCD_write_english_string(0,2," NuTiny-EVB- ");
- delayms(100);
- LCD_write_english_string(0,3,"M058SSAN V2.1");
- delayms(100);
- LCD_write_english_string(0,4,"Design:lijing");
- delayms(100);
- }
- // 主函数
- main(void)
- {
- Un_Lock_Reg();
- PWRCON |= XTL12M_EN;
- while((CLKSTATUS & XTL12M_STB) == 0); // Wait until 12M clock is stable.
- CLKSEL0 = (CLKSEL0 & (~HCLK)) | HCLK_12M; //Set external crystal as the system clock
- Timer0_Init();
- TestLCD_Nokia5110();
- while(1);
- }
在使用YBDZ转换板替代原Smart M05X时,需将YBDZ上的RST与P3.5连接,通过按K4键来实现复位处理来执行显示功能。否则不能执行正常显示。 在使用NuTiny-EVB-M058SSAN-LQFP64 V2.1开发板替代原Smart M05X时,需使用开发板上的USB接口来供电,否则用外接的稳压电源无法工作,原因待查。 图3 YBDZ转换板的LCD5110显示效果
|