The Nokia 5110 LCD is such a nice, small, multi-line display (as well as fairly inexpensive and ubiquitous) that I've been determined to use it for this project. I've worked through code from a number of sources, some use proprietary compilers (like MikroC) and other are written for different chip series (PIC18F, etc.) or require purchasing the right to use the code. The one source that has been most useful to me is Nokia 5110 Example C source – PIC16F, which I mentioned in an earlier post.
Changing pin assignments was the first order of business and was thankfully pretty straightforward (one important note is that I changed from a 5v to a 3.3v supply - I'm stating it now because I don't think I did in any earlier posts). Below is the code assigning Pins on the PIC16F1786 and corresponding pins on the Nokia 5110:
/******************************************************************************/
/* User Defines */
/******************************************************************************/
// Connections from PIC to LCD and LCD to Power
// LCD GND LCD 8 on Nokia 5110
// LCD Backlight LCD 7 to GND
// LCD V+ 3.3 LCD 6
#define LCD_CLK LATCbits.LATC5 //Pin 16 on PIC16F1786 LCD 5
#define LCD_DIN LATCbits.LATC4 //Pin 15 LCD 4
#define LCD_DC LATCbits.LATC3 //Pin 14 LCD 3
#define LCD_CE LATCbits.LATC6 //Pin 17 LCD 2
#define LCD_RST LATCbits.LATC7 //Pin 18 LCD 1
//The DC pin tells the LCD if we are sending a COMMAND or DATA
#define LCD_COMMAND 0 //Logic Low sent to DC to indicate sending COMMAND
#define LCD_DATA 1 //Logic High sent to DC to indicate sending DATA
#define _INTOSC 800000 //Internal Oscillator set to 8MHz
/*Even though using Internal Oscillator have to set XTAL Frequency
to enable __delay_ms() function*/
#define _XTAL_FREQ 800000
//Nokia 5110 is 84 by 48 pixels
#define LCD_X 84
#define LCD_Y 48
The first issue I encountered was trying to display lower case
characters. Letters would come up but they were not the correct
ones, so the search was on to find out why. Looking at my printouts
of the code didn't find anything. I decided to look at just where
errors began to appear – just looking at alphabetical characters it
found that lower case 'a' was the first letter and it was switched to
lower case 'b'. Looking closer at the code for characters I noticed
that the text after the line for the '\' character was displayed in a
lighter text. As it turns out the comment on the line signifying
that it stood for '\'commented out the following line which is for
the lower case 'a'. This then shifted the rest of the table forward
one value.//array for character display data
const unsigned char ASCII[][5] = {
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
.............................................................continues
This is where the problem was:
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c \
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
I changed it to the following and it works correctly now:,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c “\” need quotes or it skips next line seeing it as a comment
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
I've been trying all week to understand how I can send graphic bitmaps. Using LCD_Assistant. I'm able to generate hexadecimal arrays in C. I just haven't figured out how to send them to the LCD correctly – my code compiles but no graphics appear on the screen. I shelved this issue for later and decided to look at how characters are encoded in the ASCII array. Having read the datasheet for the Nokia 5110 display, and driver plus numerous code examples for sending text to the Nokia - I knew the most common font used 5 bits wide by 8 bits high (5x8 pixels on the screen). Looking at the code above you can see that each letter is assigned 5 hex bytes which equals 5 wide by 8 high. To verify this I plotted out some lines of the array on graph paper:
Editing unused characters in the ASCII file I've been able to make 5x8 graphics (blood drop - visible above).
My next challenges were figuring out how to insert calculated values from variables into the text I send to the LCD. This took me quite a while to figure out since I couldn't think of how to even state the question clearly. As it turns out, this is generally covered early for people taught 'C' and involves using printf and sprintf.
I'll try and go over this tomorrow.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Sorry for the late reply, I didn't see the comment until yesterday. You are correct, it is just that the code I've adapted has a buffer around the edge of the display and that limits the characters to 12 per line.
Are you sure? yes | no
Those displays are 84x48, so you'll get 14x6 of text using a 5x8 font with a pixel wide character spacing.
Are you sure? yes | no
Sorry for the late reply, I didn't see the comment until a few days ago and only just realized I replied as a comment and not as a direct reply to your comment.
You are correct, it is just that the code I've adapted has a buffer around
the edge of the display and that limits the characters to 12 per line.
Are you sure? yes | no