Overview
The Nokia 5110 LCD module is very popular among electronics hobbyists. This LCD module use the Phillip PCD8544 LCD controller/driver with a display data RAM of 48x84 bit. It can operates between 2.7V and 5.0V DC. Its SPI interface could operate up to 4MBits/s.
Sample Program using PIC16F887 |
Its slave SPI interface is very easy to control using a dedicated hardware SPI module or even a software SPI bit-banging method.
Nokia 5110 LCD Module |
Nokia 5110 LCD Module Back Side |
Panel LPH7366 |
Panel LPH7366 |
Its operating voltage is between +3.3V and +5.0V DC, suitable for most of DIY hobbyist electronics projects.. Its 8 pins are,
- RST : Reset (Active Low)
- CE : Chip Enable (Active Low)
- DC : Data(1) or Command(0)
- DIN : Data In
- CLK : Clock In
- VCC : Positive Supply Voltage
- BL : Back Light
- GND : Ground
We can write the data to the display RAM using a vertical or horizontal addressing mode. Using the horizontal addressing mode is very common.
Instruction Set |
The controller accepts command or data via DC pin (logic 1 for data and logic 0 for command).
Serial Protocol |
The microprocessor can transfer the data to this chip using a single byte or multiple bytes transmission mode.
PIC16F887 SPI Interfacing using XC8 C compiler
Using the SPI module of PIC16F887 is very easy. It allow a high speed transmission of data to the LCD without interrupting the micro-controller program.
Simulating program in Proteus |
In this example, the micro-controller send graphic data and text to the LCD repeatedly.
Running Program on PIC16F887 Prototype Board |
Source Code:
#include <xc.h> #include "config.h" #include "pcd8544.h" #include "graphic_84x48.h" #define _XTAL_FREQ 8000000UL void main(void){ OSCCONbits.IRCF=7; lcd_initialize(); lcd_fill(0x00); while(1){ for(uint16_t i=0;i<sizeof(graphic_84x48);i++) lcd_write(LCD_D,graphic_84x48[i]); __delay_ms(5000); lcd_fill(0); lcd_text("PIC16F887"); lcd_new_line(); lcd_text("Nokia 5110"); lcd_new_line(); lcd_text("LCD Example"); lcd_new_line(); lcd_text("Using MPLABX"); lcd_text("XC8 Compiler"); lcd_text(" BLOGGER "); __delay_ms(5000); lcd_fill(0); } }
I make an PCD8544 driver included in this project. It based on Arduino Playground example.
The PCD8544.h header file:
/* Microchip Technology Inc. and its subsidiaries. You may use this software * and any derivatives exclusively with Microchip products. * * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. * * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. * * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE * TERMS. */ /* * File: * Author: * Comments: * Revision history: */ #include <xc.h> #include "spi.h" #define LCD_C 0 #define LCD_D 1 #define LCD_X 84 #define LCD_Y 48 #define D_C RC0 #define RST RC1 #define CS RC2 unsigned char char_count=0; void lcd_character(char charactor); void lcd_fill(unsigned char data); void lcd_initialize(void); void lcd_text(char *character); void lcd_write(char dc,unsigned char _data); void lcd_new_line(); static const char ASCII[][5] = { {0x00, 0x00, 0x00, 0x00, 0x00} // 20 ,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 ! ,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 " ,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 # ,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $ ,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 % ,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 & ,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 ' ,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 ( ,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 ) ,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a * ,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b + ,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c , ,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d - ,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e . ,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f / ,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0 ,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1 ,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2 ,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3 ,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4 ,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5 ,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6 ,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7 ,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8 ,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9 ,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a : ,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ; ,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c < ,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d = ,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e > ,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ? ,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @ ,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A ,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B ,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C ,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D ,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E ,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F ,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G ,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H ,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I ,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J ,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K ,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L ,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M ,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N ,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O ,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P ,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q ,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R ,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S ,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T ,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U ,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V ,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W ,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X ,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y ,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z ,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [ ,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥ ,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ] ,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^ ,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _ ,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 ` ,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a ,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b ,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c ,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d ,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e ,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f ,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g ,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h ,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i ,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j ,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k ,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l ,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m ,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n ,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o ,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p ,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q ,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r ,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s ,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t ,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u ,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v ,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w ,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x ,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y ,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z ,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b { ,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c | ,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d } ,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ~ ,{0x78, 0x46, 0x41, 0x46, 0x78} // 7f DEL };
The PCD8544.c source file:
#include "pcd8544.h" void lcd_character( char character){ int i; static int x_count=0; lcd_write(LCD_D,0x00); for(i=0;i<5;i++){ lcd_write(LCD_D,ASCII[character-0x20][i]); } lcd_write(LCD_D,0x00); x_count+=1; if(x_count>=12){ x_count=0; } char_count=x_count; } void lcd_fill(unsigned char data){ for(uint16_t i=0;i<LCD_X*LCD_Y/8;i++) lcd_write(LCD_D,data); } void lcd_new_line(){ int temp; temp=12-char_count; if(temp!=0){ for(int i=0;i<temp;i++) lcd_character(' '); } } void lcd_initialize(void){ spi_init(); TRISC0=0; TRISC1=0; CS=1; RST=1; lcd_write(LCD_C,0x21); // LCD Extended Commands lcd_write(LCD_C,0xB1); // SET LCD CONTRAST lcd_write(LCD_C,0x04); // set temp coefficient 0x04 lcd_write(LCD_C,0x14); // LCD bias lcd_write(LCD_C,0x20); lcd_write(LCD_C,0x0C); // LCD normal Mode /* lcd_write(LCD_C,0b00100001); lcd_write(LCD_C,0b10010000); lcd_write(LCD_C,0b00100000); lcd_write(LCD_C,0b00001101); */ } void lcd_text( char *character){ while(*character) lcd_character(*character++); } void lcd_write( char _dc, unsigned char _data){ D_C=_dc; CS=0; spi_send(_data); CS=1; }
Click here to download its source file.
Excellent blog post! The content is incredibly insightful and well-articulated, making complex ideas accessible and engaging. The thorough research and clear presentation are truly commendable. This piece is a valuable resource for anyone interested in the topic. Kudos to the author for their outstanding work! I look forward to more insightful and well-crafted articles in the future. Keep it up!
ReplyDeleteHalltronics
Thanks for the blog! Create led
ReplyDelete