Welcome, Guest
Username Password: Remember me

Nokia 5110 LCD (PCD8544)
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Nokia 5110 LCD (PCD8544)

Nokia 5110 LCD (PCD8544) 02 Dec 2012 04:05 #391

  • mikep
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
I ported a simple library for the Nokia 5110 LCDs, such as this one:
Graphic LCD 84x48

There is a lot of information abut these displays out there, the code is based on exiting work for the Arduino and LeafLabs Maple.

See it in action here: http://bit.ly/SD6gte

This display uses a simple protocol based on SPI.
It needs 4 GPIO pins (plus power) from the SimpleCortex.
The library just uses bit-banging to implement this protocol, so it can use pretty much any GPIO pins on the SimpleCortex.
It also uses the GPIO.h/GPIO.c files for simple GPIO access. That could of course be optimized as well to use direct register access.
I will probably optimize it to use the hardware SPI available on the SimpleCortex.

It includes a basic ASCII font, so you can use it as a 14x6 character LCD display.


Not sure how to attach files here in the forum, that seems to be disabled.

Sorry about the long post, here's the code. I didn't post the GPIO.h/GPIO.c files since they're in the repository/example libraries.

Cheers,
Mike



main.c

 
/*
* Example program for a Nokia 5110 LCD display based on controller PCD8544
*
* Author: Mike Pose
* Date: 12-01-2012
* Version: 1.0
*
*/

 
 
#include "lpc17xx.h"
#include "lpc_types.h"
#include "GPIO.h"
#include "lcd_pcd8544.h"

 
int main (void)
{
 
uint8_t but2;
uint8_t but3;
 
//initialize the buttons
GPIOSetDir(1, 27, INPUT); //declare button B2 (P1.27)
GPIOSetPull(1, 27, PULLUP); //pull-up resistor for button B2
GPIOSetDir(1, 26, INPUT); //declare button B3 (P1.26)
GPIOSetPull(1, 26, PULLUP); //pull-up resistor for button B3
 
 
// initialize the LCD
lcd_init();
 
lcd_setcursor(0,0);
lcd_putstring("Nokia 5110 LCD");
lcd_setcursor(1,2);
lcd_putstring_inverse("SimpleCortex");
lcd_setcursor(0,4);
lcd_putstring("Button2:");
lcd_setcursor(0,5);
lcd_putstring("Button3: ");
 
while(1)
{
but2 = GPIOGetValue(1, 27); // read the button B2 value
but3 = GPIOGetValue(1, 26); // read the button B3 value
 
lcd_setcursor(9,4);
if (but2 == 0) // the button is pushed
{
lcd_putstring_inverse(" ");
}
else
{
lcd_putstring(" ");
}
 
lcd_setcursor(9,5);
if (but3 == 0) // the button is pushed
{
lcd_putstring_inverse(" ");
}
else
{
lcd_putstring(" ");
}
 
}
 
}
 
 



lcd_pcd8544.h

 
 
/********************************************************************************
* Author: Mike Pose
* Date(DD-MM-YYYY): 12-01-2012
* Version: 1.0
*
* Description:
* This is a library to control an 84x48 pixel LCD display based on controller PCD8455
* such as the Nokia 5110 displays
*
* - a simple 6x8 font is included which allows a 14x6 characters display
* - this library uses bit-banging to send data to the LCD,
* - it could be optimized to use hardware SPI
* - graphics are not implemented yet
* ******************************************************************************
*
* Circuit Description:
*
* NOKIA 5110 LCD ---> SimpleCortex
* ========================================
* Pin 1 (VCC) --> 3.3V (DO NOT USE 5V !!!)
* Pin 2 (GND) --> GND
* Pin 3 (SCE) --> P0.2 (CS Pin - chip select, enable data transfer)
* Pin 4 (RST) --> P0.5 (RESET pin)
* Pin 5 (D/C) --> P0.6 (MODE pin - Command/Data)
* Pin 6 (MOSI) --> P0.4 (DATA pin)
* Pin 6 (SCLK) --> P0.3 (CLOCK pin)
* Pin 8 (LED) --> Resistor 180 OHM --> 3.3V (DO NOT CONNECT DIRECTLY TO 3.3V !!!)
*
*
*/

 
 
 
#ifndef _LCD_PCD8544_H
#define _LCD_PCD8544_H

#include "lpc17xx.h"
#include "lpc_types.h"

 
#define LCD_PORT 0 // all LCD lines are connected to Port 0

#define LCD_CS 2 // port 0.2 is CS pin
#define LCD_CLK 3 // port 0.3 is CLOCK pin
#define LCD_DATA 4 // port 0.4 is DATA pin
#define LCD_RST 5 // port 0.5 is RESET pin
#define LCD_MODE 6 // port 0.6 is MODE pin

 
#define LCD_MODE_CMD 0
#define LCD_MODE_DATA 1

#define LCD_PRINT_NORMAL 0
#define LCD_PRINT_INVERSE 1

 
void lcd_init(void);
void lcd_clear(void);
void lcd_setcursor(uint8_t x, uint8_t y);
 
void lcd_putstring(char *string);
void lcd_putstring_inverse(char *string);
void lcd_putchar(char c, uint8_t print_mode);
 
#endif

 
 


lcd_pcd8544.c

 
#include "lcd_pcd8544.h"
#include "font_6x8.h"
#include "GPIO.h"

 
/****************************************************************************
Function Name : delay()
Description :This function suspends the tasks for specified ticks.
Input : ticks:no of ticks in multiple of 1 usec
task: task to be suspended
Output : void
Note :
*****************************************************************************/

void delay(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
/* At 60Mhz, the below loop introduces delay of 10 us */
for(i=0;i<35;i++);
}
}
 
void lcd_write_byte(uint8_t data, uint8_t lcd_mode)
{
// enable the lcd
GPIOSetValue(LCD_PORT, LCD_CS, LOW);
 
if (LCD_MODE_CMD == lcd_mode)
GPIOSetValue(LCD_PORT, LCD_MODE, LOW);
else
GPIOSetValue(LCD_PORT, LCD_MODE, HIGH);
 
uint8_t i;
for(i=0; i<8; i++)
{
GPIOSetValue(LCD_PORT, LCD_DATA, data & 0x80); //SPI_MO = data & 0x80;
data = data<<1;
// toggle the clock pin
GPIOSetValue(LCD_PORT, LCD_CLK, LOW);//SPI_SCK = 0;
GPIOSetValue(LCD_PORT, LCD_CLK, HIGH);//SPI_SCK = 1;
}
// disable the lcd
GPIOSetValue(LCD_PORT, LCD_CS, HIGH);
 
 
}
 
 
void lcd_write_command(uint8_t data)
{
lcd_write_byte(data, LCD_MODE_CMD);
}
 
 
void lcd_write_data(uint8_t data)
{
lcd_write_byte(data, LCD_MODE_DATA);
}
 
 
void lcd_clear( void)
{
//LCD_clear();
uint8_t i,j;
for(i=0;i<6;i++)
for(j=0;j<84;j++)
lcd_write_data(0);
}
 
 
void lcd_init( void )
{
// set the direction of the pins
GPIOSetDir(LCD_PORT, LCD_CS, OUTPUT);
GPIOSetDir(LCD_PORT, LCD_CLK, OUTPUT);
GPIOSetDir(LCD_PORT, LCD_DATA, OUTPUT);
GPIOSetDir(LCD_PORT, LCD_RST, OUTPUT);
GPIOSetDir(LCD_PORT, LCD_MODE, OUTPUT);
 
// set the default state for the pins
GPIOSetValue(LCD_PORT, LCD_CS, HIGH);
GPIOSetValue(LCD_PORT, LCD_CLK, HIGH);
GPIOSetValue(LCD_PORT, LCD_DATA, HIGH);
GPIOSetValue(LCD_PORT, LCD_MODE, HIGH);
 
// reset the display
GPIOSetValue(LCD_PORT, LCD_RST, LOW);
delay(5);
GPIOSetValue(LCD_PORT, LCD_RST, HIGH);
 
// write commands to initialize
lcd_write_command(0x21);
lcd_write_command(0xc6);
lcd_write_command(0x06);
lcd_write_command(0x13);
lcd_write_command(0x20);
lcd_clear();
lcd_write_command(0x0c);
 
}
 
 
void lcd_setcursor(uint8_t x, uint8_t y)
{
lcd_write_command(0x40|y); //Y increments in rows of 8 pixels
lcd_write_command(0x80|x * 6); // X increments in pixels
}
 
 
void lcd_putchar(char c, uint8_t print_mode)
{
uint8_t line;
unsigned char ch = 0;
for(line=0;line<6;line++)
{
ch = font6x8[c-32][line];
//lcd_write_data(ch);
lcd_write_data((print_mode==LCD_PRINT_NORMAL)? ch: (ch^ 0xff));
}
}
 
 
void lcd_putstring(char *string)
{
// unsigned char len = MAX_CHAR_IN_ONE_LINE;
// while(*string != '\0' && len--)
 
while(*string != '\0')
{
lcd_putchar( *string, LCD_PRINT_NORMAL);
string++;
}
}
 
void lcd_putstring_inverse(char *string)
{
 
while(*string != '\0')
{
lcd_putchar( *string, LCD_PRINT_INVERSE);
string++;
}
}
 
 



font6x8.h

 
// 6 x 8 font
// 1 pixel space at left and bottom
// index = ASCII - 32
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 }, // $
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
{ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
{ 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
{ 0x00,0x00, 0x06, 0x09, 0x09, 0x06 } // horiz lines
};
 
 
Last Edit: 02 Dec 2012 04:07 by mikep.

Re: Nokia 5110 LCD (PCD8544) 03 Dec 2012 21:38 #392

  • rik
  • OFFLINE
  • Administrator
  • Posts: 105
Hah, very nice, thanks for the example
I ordered some of the small LCD's to try it out.
Do you mind if we add it to the tutorials after we tested it?

Re: Nokia 5110 LCD (PCD8544) 03 Dec 2012 22:00 #393

  • mikep
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
Please feel free to add it to the tutorials. One could remove the dependency on the GPIO.h/.c files by doing straight GPIO register manipulations in the library.
But this was just a quick way for me to use these LCDs for debug messages and simple output.
I can send you my CoIDE project, but I used 1.6.0 and as you mentioned, CoIDE 1.6.0 totally changes the project structure and project files around, it's a PITA. I might have to revert.

Re: Nokia 5110 LCD (PCD8544) 13 Jan 2013 19:23 #429

  • heitor
  • OFFLINE
  • Fresh Boarder
  • Posts: 6
Very nice work mikep,

I have one of these display here (from my old cel. phone ).

Maybe the developer guys could be upload the COIDE project with the files.

Best regards,

Re: Nokia 5110 LCD (PCD8544) 14 Jan 2013 11:22 #432

  • cornelis
  • OFFLINE
  • Administrator
  • Posts: 125
Hey,

Something went wrong with shipping of the lcd's so I was not able to test this example.
Please let me now if it's working properly. Then I can add it to the repository.

I copied the example to the attachment.

Regards, Cornelis


File Attachment:

File Name: LCD_5110_CoIDE.zip
File Size: 101 KB
  • Page:
  • 1
Time to create page: 5.39 seconds
Copyright 2011. Joomla 1.7 templates - Joomla template maker. The Simplecortex is developed by BRC-Electronics