lcd panel 1x16 character made in china
PIN6-9 DATA Orange LCD pin 6 to Ardu Pin 5, LCD7 to 4, 8 to 3 and the LCD Pin 9 to Ardu Pin2. (kind of cross wired, I have tried the other way around with identical result)
With this Setup I can set a cursor to any position, have it blinking, turn the display on/off, but I don´t get any characters displayed with the "print" or "write" commands.
This code kind of "grew" out of the basic "Hello World" sketch when I was adding different LCD related commands to see what the action is. Basic result: all commands in that sketch work except "print" and "write".
1)After I pull and re-connect the +5V to the LCD it weakly shows the 8 dark squares on the left side of the display, with a cursor blinking and scrolling slowly from left to right, blinking for 5 sec on each slot, then disappear for good. The squares remain dimmed until I re-load the code to the Arduino. Then the squares disappear and the blinking cursor has its full contrast again and it is doing its sketched blinking.
4) During the initial PIN identification phase, I had situations, where all kinds of different characters were displayed. That looked pretty promising and tells me that the character ROM worked then. I cannot recall, which PIN combinations caused these indications. At that time I had not figured out yet, that there is no R/W pin.
Liquid crystal displays (LCD) come in two main types that are of interest to hobby and DIY makers; Character LCD displays and pixel / graphic LCD displays. This intro “How To” will be covering the more popular and less expensive character LCD displays based on the very common Hitachi HD44780 controller.
LCD displays come in many sizes most often named by the number of rows and then the length of the display line. For example a 1x16 LCD display will have one row of sixteen characters and a 4x20 LCD display will have four rows with twenty characters in each.
LCDs can be have backlighting or be reflective (think calculator). In either case the programming that goes into working these displays is the same. LCDs with backlight normally use two pins to provide power to the backlighting.
2x16 character LCD with backlighting. Note, screen is all black, but to display characters the crystals move to allow the backlighting to show through.
Most LCDs that are being made now come with one row of sixteen pins. The first fourteen pins are used to control the display and the last two are for the backlighting (if the display has backlighting).
Older LCDs sometimes came with two rows of seven making a fourteen pin connector. These fourteen pins, most often, have the same signals on them that the 1x16 pin displays do. For example, pin #1 on the 2x7 connector is the same signal as pin #1 on the 1x16 connector, they are just arranged differently. If you have a 2x7 pin display but need to connect it to a 1x14 (1x16) backpack or device, the basic
LCDs based on the Hitachi HD44780 controller must be initialized after they are powered-up. The reason that the LCDs must be initialized is because there are a few critical options that the display must “know” before it can work or communicated properly.
The most import of which is wether to use an eight or four bit data interface. Hitachi and compatible LCDs can be set to use either 8 or 4 of the data pins to communicate with the host controller that is driving it. Using a four pin data bus lets you save on pins, but your controller must divide each instruction into two four bit segments and then send them one at a time to the display. So the trade off is less pins versus more programming and slower communication. (The reduced speed of having to send data twice has little effect on the display, but it does busy your processor for a longer amount of time.)
Ok, so you initialized your new 1x16 display and cleared it so that the cursor is at the first character position. Now you start sending your “Hello World” message to the screen.
When you send the LCD a character to display, you are not actually sending it to the screen part of the display, but rather a memory location that the display uses to know what to display on the screen. The problem here is that the memory location and the mapping to positions on the screen are not always sequential.
The “Hello World” example above is often what gives people trouble using a 1x16 LCD for the first time. Here the “r” “l” “d” went into memory address 0x88,0x89 and 0x8A which are not visible on this display !
Note that from the eight to the ninth character position the memory jumps. So, to finish displaying “Hello World” the controller would have to jump to memory location 0xC0 (at the red arrow) to continue displaying “rld”.
Solution: When you are ready to display a character in the ninth position on a 1x16 display you simply send the memory address to the display, but as a command.
For 1x16 and all the display larger then this, the memory mapping of the DDRAM (Display RAM) is not in the same range as the other commands, such as “clear display”, “home display” etc... so there is no problem sending the memory address as a command.
When it is actually time to use an LCD you have a few choices of how to do it. You can connect it directly to your Arduino or micro-controller (MCU) and use a lot of pins and wires or your could use a backpack.
Using a backpack has a few advantages over connecting the LCD directly to your micro-processor. Besides using less wires, (and pins) some backpacks take over the entire job of driving the display. All your code has to do is send the text out of the appropriate interface, I2C, serial, SPI etc ... This can save your micro-controller a lot of memory, and processor time. And, it also lets you get your projects working sooner, since you do not have to code and debug software to drive the display on top of the rest of your project.
B. Backpacks that reduce the pin-out burden on your MCU. With this type of backpack, your MCU still initializes and drives the LCD, but through an interface with fewer wires.
Most displays work with the standard 128 ASCII characters. Often times, the displays are also able to display other characters, these include Asian characters and other special symbols and icons.
Your micro-controller measures a sensor and returns the value of five. You send the value to the display and you either get nothing or a strange looking character.
Hi! This tutorial is going to be somewhat special - it will be the last one in this series. It’s been a long time since the very first tutorial and you’ve discovered a lot in the journey. And in conclusion, I want to show you how to work with the very popular character LCD with 2 lines, 16 characters each (usually just called the “1602 LCD”). This LCD comes with the in-built HD44780 driver (you can read more detail about it here). I will provide you brief information about it, the minimal amount required to initialize the display and show some text on it.
You can invent a lot of applications with these shift registers but now we will use this chip just as a tool to control the 1602 LCD. Let’s now consider it in more detail.
There are several displays with the HD44780 driver, they can have different line numbers and position numbers (1x8, 2x8, 1x16, 2x16, 2x20, 4x20 etc.), also they can have different backlight colors (green, yellow, blue, etc.) or don’t have a backlight at all. The character’s color can be black or white. So, as you see, there is a diversity but all of them have the same interface and are controlled using the same commands. I have the display shown in fig. 2 which I bought a long time ago on Aliexpress.
This LCD has the built-in character generator, so you don’t need to design your own characters (like we used to do with the 7-segment indicator). We can just send the ‘A’ letter to the display, and it will be shown - fascinating, isn’t it? Also, the display has 16 empty cells in which you can load your own characters and then use them but we won’t do this in this tutorial. The character generator of the LCDs from Aliexpress usually have a Chinese code page, so you can use the first 128 ASCII characters, which includes capital and small English letters, numbers, and the punctuation signs which is quite good!
RS is the data/command input. When this pin is low, the incoming data is considered as a command, and when it’s high, it is considered a character to display.
RW is the read/write input. When it is low, the data goes from the microcontroller to the LCD, and when it is high, the data goes the reverse direction. As we don’t expect any data from the LCD, we can connect this pin to ground.
As for the commands that HD44780 uses, I will not describe them here. You can refer to the data sheet for full information. I will provide you with the information on how to initialize the display which you can use. Also, I’ll show you how to set the cursor position and display some data on the LCD.
The 1602 LCD (X2) is connected as described above. The Vo pin is connected to the 10-47 kOhm potentiometer R1. When you power up the device, you should rotate the handle of the potentiometer to make the rectangles of the LCD barely visible. Then the contrast level is set correctly. The LED+ pin is connected to VCC through the 22-47 Ohm resistor R2. The RS, E, D4, D5, D6, and D7 pins are connected to the shift register. Please pay attention that the data pins D4-D7 are connected to the lower four outputs of the shift register Q0-Q3, respectively. The RS input is connected to Q4, and E input is connected to Q5. Thus Q6 and Q7 pins remain unused, and you can expand your device with something else. The RW input of the LCD is connected to the GND, as we will just write to the LCD. The D0-D3 inputs remain unused in the 4-bit interface.
Now let’s consider the program that will initialize the LCD and write the “HELLO WORLD” message, where words will be located in the center of both lines of the LCD.
‘data_com’ is the auxiliary register, which has two values: 0 if we send command to the LCD, or 0x10 (‘1’ in the RS position, bit 4, see figure 4) if we send the data.
Finally, we define the control bits of the 1602 LCD (lines 16, 17) RS (bit 4) and E (bit 5), as these LCD pins are connected to the Q4 and Q5 of the shift register, correspondingly.
In lines 36-55 there is the LCD initialization part. As I said, just use it as is. There are different initialization sequences I’ve seen in the different sources, and this one is the minimum required that works. Let’s briefly consider this sequence.
First, we send the command 0x33 which prepares the LCD to work (lines 36, 37) by calling the ‘LCD_SEND’ subroutine which we will consider later. Then we perform the delay of 200 ms (lines 38, 39). Actually, the required delay is 1640 us but I decided not to add another delay subroutine, as we’re not in a rush.
Then we send the 0x32 command (lines 40, 41) to set the 4-line interface. The 0x28 command (lines 42,43) sets the 2-lines display type. Then we turn off the display by calling the 0x08 command (lines 44, 45), clear the display if there was some data previously with the 0x01 command (lines 46, 47), and perform another delay to execute this command (lines 48, 49). With the next command 0x06 (lines 50, 51) we tell the display that after each next character we want the cursor to shift right.
First, we need to set the cursor position where we want to put the first character. As we agreed, we will write “HELLO” in the center of the first line, and “WORLD” in the center of the second line. As each line has 16 positions, then the position of the first character should be (16 - 5) / 2 = 5. To set the cursor position we need to send command 0xXY, where X is the line number code (8 - first line, C - second line), and Y is the position number (0 - F).
As now we will transmit data, not a command, we need to set the ‘RS’ bit of the ‘data_com’ register to ‘1’ (line 60). And then we just consecutively send five characters: H, E, L, L, O (lines 62-71), and they will be displayed on the LCD, nothing else is required.
Then we need to set the cursor position again, so we clear the ‘data_com’ register (line 73) to transmit the command 0xC5 (lines 74, 75) which sets the fifth position in the second line. And then we set the ‘RS’ bit in the ‘data_com’ register again (line 76) and transmit another 5 characters: W, O, R, L, D (lines 78-87).
Now let’s see how to send data to the LCD. As I mentioned before, the data byte is split into two nibbles as we use the 4-bit interface. Also, we will need to send each nibble twice: first time with the E = 1 to start the pulse on the E input, and the second time the same nibble but with E = 0 to finish the pulse. So in total, we need to send 4 bytes to the shift register to transmit a single byte to the LCD. And now let’s return to the program code.
First, we copy the byte which we need to send from the W register into the ‘lcd_data’ register (line 113) and into the ‘data_byte’ register (line 114). Then we swap the ‘data_byte’ register to have the upper nibble in the lower four bits (line 115) as we have to send the upper nibble first. Then we perform the AND operation between the ‘data_byte’ and the 0x0F to clear the upper nibble (lines 116, 117).
Now we have the upper nibble of the ‘lcd_data’ in the lower four bits of the ‘data_byte’ and after coming through the shift register it will appear on the Q3-Q0 outputs and get to the D7-D4 inputs of the display, respectively. We need to take care of the RS and E signals now.
Then we send the lower nibble of the ‘lcd_data’ (lines 129-144) which is almost the same as sending the upper nibble except for not swapping the nibbles in the beginning.
So assemble the device according to the schematics diagram (figure 4), compile the program, and connect your PICkit to the PC. disconnect the DS and CTCP pins of the shift register from the MCU and flash it. Then disconnect the programming wires and connect the DS and CTCP wires again. If you did it within 2 seconds, you will see the text “HELLO WORLD” on your LCD, otherwise power off then power on your device and enjoy its greeting to you. If you don’t see the text even now, rotate the potentiometer handle to set the contrast, this should help. If you still don’t see anything then check the connections: there are a lot of wires in this device and it’s easy to mess up.
Now, some traditional statistics. We’ve learnt how to work with the shift register 74HC595, also we’ve discovered how to use the 1602 LCD with the HD44780 driver. As for the PIC10F200 commands, we haven’t learnt any new one this time. The code length is just 118 words so there is a lot of free space to add some more functionality.