LCD5110显示屏是一款基于SPI接口的显示屏,其工作电压为3.3V,正常显示时工作电流200uA以下,适用于电池供电的便携式移动设备。 LCD5110满屏可显示30个字符,相当于LCD1602来讲,其速度是LCD1602的40倍,占用的I/O引脚则比LCD1602少。 在使用中,LCD5110显示屏与开发板的连接关系如下: SCE ---RB7 RESET---RC0 DC ---RC5 SDIN ---RC4 SCLK ---RC6 LED ---RC1 在MCC中的引脚配置如图1所示,相应的引脚命名如图2所示。 图1 引脚配置 图2 引脚命名 用于在驱动程序设计中需用到延时函数,故启用的了系统的延时功能,其配置如图3所示。 图3 配置延时功能 LCD5510显示屏的初始化函数为: - void LCD5510_Init(void)
- {
- __delay_ms(800);
- RST_SetLow();
- __delay_us(2);
- RST_SetHigh();
- LCD_write_cmd(0x21);
- LCD_write_cmd(0x06);
- LCD_write_cmd(0x13);
- LCD_write_cmd(0xc8);
- LCD_write_cmd(0x20);
- LCD_write_cmd(0x0c);
- LCD_write_cmd(Y_Page_Addr);
- LCD_write_cmd(X_Col_Addr);
- LCD_clr_scr();
- }
使用I/O口模拟SPI发送字节数据的函数为: - void LCD_write_byte(unsigned char wbyte, unsigned char dat_cmd)
- {
- unsigned char i;
- if(dat_cmd)
- {
- DC_SetHigh(); //LCD_DC_H;
- }
- else
- {
- DC_SetLow(); //LCD_DC_L;
- }
- for(i = 8; i; i--)
- {
- if(wbyte & 0x80)
- {
- SDIN_SetHigh(); //LCD_DIN_H;
- }
- else
- {
- SDIN_SetLow(); //LCD_DIN_L;
- }
- SCLK_SetLow(); //LCD_CLK_L;
- wbyte <<= 1;
- __delay_us(1);
- SCLK_SetHigh(); //LCD_CLK_H;
- }
- }
实现清屏功能的函数为: - void LCD_clr_scr(void)
- {
- unsigned int i;
- LCD_write_cmd(X_Col_Addr);
- LCD_write_cmd(Y_Page_Addr);
- for(i = 504; i; i--) LCD_write_dat(0x00);
- }
实现字符及字符串显示的函数为: - void LCD_printc(unsigned char x, unsigned char y, unsigned char c_dat)
- {
- unsigned char i, j;
- c_dat -= 32;
- x <<= 3; //8
- y <<= 1; //16
- for(j = 0; j < 2; j++)
- {
- LCD_pos_byte(x, (y + j));
- for(i = 0; i < 8; i++)
- LCD_write_dat(Font_code[c_dat][8 * j + i]);
- }
- }
- void LCD_prints(unsigned char x, unsigned char y, unsigned char *s_dat)
- {
- while(*s_dat && x < 10)
- {
- LCD_printc(x++, y, *s_dat);
- s_dat++;
- }
- }
实现图4所示显示效果的主程序为: - void main(void)
- {
- SYSTEM_Initialize();
- LED_SetHigh();
- LCD5510_Init();
- LCD_prints(0,0,"PIC18F16Q41");
- LCD_prints(0,1,"LCD5510 ");
- LCD_prints(0,2,"jinglixixi");
- while (1)
- {
- // Add your application code
- }
- }
图4 显示效果
|