LCD5110显示屏原是诺基亚手机上使用的一款显示屏,该屏采用SPI接口工作,共有8个引脚。 在使用时,除电源引脚外,其它引脚与开发板的连接关系为: DC --- D2 RST --- D3 CS --- GND SCL -- SCL SDA -- SDA LEDB-- A4 故引脚的相关定义为: #define LED_PIN D9 #define DC D2 #define RST D3 LCD5110的初始化函数为: - void LCD5110_Init(void)
- {
- delay(1600);
- digitalWrite(RST, LOW);
- digitalWrite(RST, HIGH);
- LCD_write_byte(0x21, 0);
- LCD_write_byte(06, 0);
- LCD_write_byte(0x13, 0);
- LCD_write_byte(0xc8, 0);
- LCD_write_byte(0x20, 0);
- LCD_write_byte(0x0c, 0);
- LCD_write_byte(Y_Page_Addr, 0);
- LCD_write_byte(X_Col_Addr, 0);
- LCD_clr_scr();
- }
复制代码
相应的清屏函数为: - void LCD_clr_scr(void)
- {
- unsigned int i;
- LCD_write_byte(X_Col_Addr, 0);
- LCD_write_byte(Y_Page_Addr,0);
- for(i = 504; i; i--) LCD_write_byte(0x00, 1);
- }
复制代码
发送字节数据的函数为: - void LCD_write_byte(unsigned char wbyte, unsigned char dat_cmd)
- {
- unsigned char i;
- digitalWrite(CS, LOW);
- if(dat_cmd) digitalWrite(DC, HIGH);
- else digitalWrite(DC, LOW);
- for(i = 8; i; i--)
- {
- if(wbyte & 0x80) digitalWrite(SDA, HIGH);
- else digitalWrite(SDA, LOW);
- digitalWrite(SCL, LOW);
- wbyte <<= 1;
- digitalWrite(SCL, HIGH);
- }
- digitalWrite(CS, HIGH);
- }
复制代码
定位显示字符的函数为: - 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_byte(Font_code[c_dat][8 * j + i],1);
- }
- }
复制代码
实现显示效果的配置程序和循环程序为: - void setup() {
- pinMode(LED_PIN, OUTPUT);
- pinMode(SCL,OUTPUT);
- pinMode(SDA,OUTPUT);
- pinMode(DC, OUTPUT);
- pinMode(RST,OUTPUT);
- pinMode(CS,OUTPUT);
- pinMode(LEDB, OUTPUT);
- digitalWrite(LEDB, HIGH); // LCD_LED_High();
- LCD5110_Init();
- LCD_printc(0, 0, 'F');
- LCD_printc(1, 0, 'i');
- LCD_printc(2, 0, 'r');
- LCD_printc(3, 0, 'e');
- LCD_printc(4, 0, 'B');
- LCD_printc(5, 0, 'e');
- LCD_printc(6, 0, 'e');
- LCD_printc(7, 0, 't');
- LCD_printc(8, 0, 'l');
- LCD_printc(9, 0, 'e');
- LCD_printc(0, 1, 'E');
- LCD_printc(1, 1, 'S');
- LCD_printc(2, 1, 'P');
- LCD_printc(3, 1, '3');
- LCD_printc(4, 1, '2');
- LCD_printc(5, 1, '-');
- LCD_printc(6, 1, 'E');
- LCD_printc(0, 2, 'j');
- LCD_printc(1, 2, 'i');
- LCD_printc(2, 2, 'n');
- LCD_printc(3, 2, 'g');
- LCD_printc(4, 2, 'l');
- LCD_printc(5, 2, 'i');
- LCD_printc(6, 2, 'x');
- LCD_printc(7, 2, 'i');
- LCD_printc(8, 2, 'x');
- LCD_printc(9, 2, 'i');
- }
- void loop() {
- digitalWrite(LED_PIN, HIGH);
- delay(500 );
- digitalWrite(LED_PIN, LOW);
- delay(500 );
- }
复制代码
经编译与上传,其结果如图1所示, 图1 编译与上传 图2 运行效果
|