PR3 PR3 LCD Display Version 1.1 May 2010 Cytron Technologies Sdn. Bhd. Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. No representation or warranty is given and no liability is assumed by Cytron Technologies Incorporated with respect to the accuracy or use of such information or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Cytron Technologies products as critical components in life support systems is not authorized except with express written approval by Cytron Technologies. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. OVERVIEW This document describes Cytron Technologies DIY (Do It Yourself) Project PR3. 2x16 characters parallel LCD will be used in PR3 to display character and numeric alphabet. Schematic and sample source code is provided. FEATURES PIC16F877A - 8 bit microcontroller with 33 I/O - Operate with 5V supply. - Operating speed: 20MHz 2x16 Characters LCD - 2x16 character LCD - Backlight
SYSTEM OVERVIEW SK40C + PIC 16F877A GENERAL DESCRIPTION 2x16 character LCD is the most common message display device used to display ASCII character. By using the SK40C, user is able to complete the circuit for this project easily. Information which includes sample source code, schematic and detail description (this document) can be downloaded from www.cytron.com.my SK40C PIC Start-Up Kit SK40C is enhanced version of SK40B. It is designed to offer an easy to start board for PIC MCU user. This board comes with basic components for user to begin project development. It offer plug and use features. Users are able to utilize the function of PIC by directly plug-in the external components in whatever way that is convenient. This kit comes WITHOUT PIC microcontroller to provide the freedom for user to choose PIC type. It can support 40-pin PIC16F and PIC18F. http://www.cytron.com.my/usr_attachment/sk40c_us ers_manual.pdf PIC16F877A This powerful (200 nanosecond instruction execution) yet easy-to-program (only 35 single word instructions) CMOS FLASH-based 8-bit microcontroller packs Microchip's powerful PIC architecture into an 40- or 44-pin package and is upwards compatible with the PIC16C5X, PIC12CXXX and PIC16C7X devices. Features of the device: 8 Kbytes of Flash Program Memory 368 bytes of Data Memory (RAM) 256 bytes of EEPROM data memory 8 channels of 10-bit Analog-to-Digital (A/D) converter 2 capture/compare/pwm functions MSSP (Master Synchronous Serial Port) can be configured as either 3-wire Serial Peripheral Interface(SPI ) or the 2-wire Inter-Integrated Circuit (I²C ) bus Universal Asynchronous Receiver Transmitter (USART) All of these features make it ideal for advanced applications in automotive, industrial, appliances and consumer product. Figure 2 shows the pin diagram for PIC16F877A. For more information about the PIC microcontroller, please refer to the datasheet. The datasheet can be obtained from microchip website at: http://www.microchip.com Figure 1
which is much easier for software development. Pin 15 and 16 of LCD are for backlight which is optional by connect or disconnect JP8.Switching on LCD backlight will consume more energy and further dry up the battery faster. The 3rd pin (VEE) needs to be connected to a variable resistor to control the LCD contrast, while the R/W (read or write) pin is connected to the ground which indicates the LCD is in write mode. R/S and E are connected to RB4 and RB5 of PIC respectively. For data communication pins, DB0-DB7 (8-bit) is connected directly to RD0-RD7 of PIC. For more detail about the LCD, please refer to the datasheet. It may be downloaded from Cytron website www.cytron.com.my Figure 2 Figure 2 shows the pin diagram for PIC16F877A. For more information about the PIC microcontroller, please refer to the datasheet. The datasheet can be obtained from microchip website at: http://www.microchip.com. Before display any ASCII character, LCD needs to be initialized. Table 1 is LCD protocol/functions and table 2 is LCD command bit function and the value. Users need both tables to initiate LCD display. Parallel LCD Protocol 2x16 Characters LCD In this project, a JHD162A (with backlight) 2x16 characters LCD will be used. It has the same pin configuration with Hitachi HD44780. LCD breakout pin and its function are shown below: Pin Name Pin Function Connection 1 VSS Ground GND 2 VCC Positive supply for LCD 5V 3 VEE Contrast adjust 4 RS 5 R/W 6 E Select register, select instruction or data register. Select read or write Start data read or Connected to a preset to adjust contrast RB4 GND (always write) RB5 write 7 DB0 Data bus pin RD0 8 DB1 Data bus pin RD1 9 DB2 Data bus pin RD2 10 DB3 Data bus pin RD3 11 DB4 Data bus pin RD4 12 DB5 Data bus pin RD5 13 DB6 Data bus pin RD6 14 DB7 Data bus pin RD7 15 LED+ 16 LED- Backlight positive input Backlight negative input 5V Connect to JP8 This LCD may be interfaced in either 8 pins (8-bit interface) or 4 pins (4-bit interface), depend on the I/O pins available. For 16F877A which has 33 I/O pins, there should be no problem using the 8-bit interface Table 1 LCD Command Bit function and value Table 2 To initiate LCD, R/S must be set to logic 0 (Low) to indicate the data send through data pin (8-bit) is command. R/S is set to logic 1 (High) to write an ASCII character to LCD. LCD will need to be initialized in PIC program according to Table 1 and Table 2. A character is not necessarily start at home position (top left corner). User may start it at the second line, centre of line or any location on LCD. Refer to Appendix A, Table 3 is DDRAM address for LCD. User may use the address to display character any location on LCD.
HARDWARE Connector for UIC00A/B Programmer This project will require following hardware: a. 1 x SK40C PIC Start-Up Kit b. PIC16F877A c. 2x16 Characters LCD d. Other necessary components Please refer to Component list to see related electronic components. Figure 4 Power Supply for Circuit Figure 3 There is DC power adapter for user to plug in DC adapter. The power supply must be in range from 7V to 15V. Power supply out of the range will spoil the circuit or return insufficient output voltage. Refer to Figure 3, the D2 is use to protect the circuit from wrong polarity supply. C2 is use to stabilize the voltage at the input side of the LM2940 voltage regulator, while the C1 and C3 is use to stabilize the voltage at the output side of the LM2940 voltage supply. Loading Program This project use UIC00A/B to load program into PIC. Connector for UIC00A/B provides simple and fast method to load program. Please refer SK40C User s Manual on method to load program into PIC using UIC00A/B programmer. Figure 5 Figure 4 shows the connector for UIC00A/B programmer which is ready on SK40C. Figure 5 shows the way of connection to program the PIC microcontroller. SK40C should be powered from DC adaptor when load program to the PIC microcontroller. The programmer (UIC00A/B) is not included in DIY project set since it can be used for different project set. User can also choose other type of PIC programmer to load the program; however, the interface and method to load program might differ from UIC00A/B. Please consult the manufacturer of that particular PIC programmer. For the instruction of using UIC00A/B, please refer to its user s manual at: www.cytron.com.my
SOFTWARE Flow Chart for LCD Initialization Flow Chart to Display ASCII Character Flow Chart 2 is showing whole program in PR3. After initiate I/O and LCD, user may send any numeric or alphabet in ASCII format to LCD. For example, if character A is wanted to be displayed, the data send from PORTD should be 01000001 (binary) and also can use 41 (hexadecimal), 65 (decimal) or 101 octet. Please refer to Appendix A for ASCII table. Flow Chart 1 Flow Chart 2 Listing 1 Flow chart 1 shows the steps to initiate 2x16 LCD. Listing 1 is the example source code to initiate LCD using Assembly code. From Listing 1, data is send from PORTD to LCD. On each pulse from E pin, LCD will read the data. Depend on RS pin, if it is logic 0 (low), LCD will interpret the data received into command and execute it. For example; when the data send from PORTD is 00111000, LCD will check the first bit that being set (1) from left. In this case, it is DB5 (bit 5), and referring to Table 1, this command is to configure Interface Length. DB4 will represent DL, and so forth. Please refer to table 2 for the value and function of DL, N, F. After initialization of LCD is done, user should see LCD display blinking cursor at home position. In this project, program will jump to 2 nd line of LCD to display next character. Send logic 0 to RS pin. The address for jump to 2 nd line is 0x40. Using move cursor to DDRAM function (refer Table 1), DB6-DB0 is address for second line (0x40-0x4F). DB7 is a command to jump to the address. By sending binary value of 10000111 or hexadecimal value of 87 to LCD, the cursor will move to 7 th column on the 1 st row of LCD. For more information about the sample code, please refer to the source code provided. The details explanation has been provided as the comment. The source code is provided free and Cytron Technologies will not be responsible for any further modification or improvement.
ii. To use the LCD, solder the LCD display at the reserve place as shown in figure 7. Caution: User is advice to check the connections using multi-meter to ensure all pin of LCD are connected to header pins. 2. Please download the necessary files and documents from Cytron Technologies website. These included documentation, sample source code, schematic, component list and necessary software. 3. Next step is to install MPLAB IDE. Please refer MPLAB installation step document to install the software. Figure 6 Every LCD data either 4 bits or 8 bits interface must be triggered by sending a Clock E. From figure 6, LCD will read data when pin E is at fall edge. Delay is needed for LCD to process and execute the data. The delay or clock E period is must be greater than 500ns. Usually the clock E period is in milliseconds (ms). 4. After the installation is complete, open the MPLAB program. Open the sample code PR3.asm file that user download from Cytron website. To open the file, click file>open>browse to sample code PR3.asm file. GETTING STARTED User may obtain the hardware set for this project (PR3) either by online purchase (www.cytron.com.my) or get it from Cytron Technologies Shop. 1. Once user has the hardware set, soldering process can begin. For PR3, user just need solder LCD to SK40C. It is optional for user to connect header pin at JP8 or not. Please refer Step to get LCD backlight. Steps to solder LCD to SK40C: 5. From MPLAB menu bar, click Configure> Select device> Select PIC16F877A>OK. Figure 7 i. Solder the 16 header pin provided to LCD as shown in figure 7.
6. Click Project>Quickbuild sample code P3.asm if user want to compile the program. 10. User may modify the program. After modified the program repeat steps 6-9 to compile and load the hex code into PIC. AC to DC adaptor: User may use the AC to DC adaptor as the power source to the circuit. Figure 9 (Not included in DIY project set) 7. If no error occurred, MPLAB will auto generate a hex file at the location where the asm file is located. Hex file is the file that needed for programmer to load into PIC. 8. Use UIC00A/B to load program into PIC. UIC00A/B programmer provides simple and fast method to load program. Please refer to the User s Manual of UIC00A/B for the correct steps to load program. 9. Figure 8 shows hardware connection of UIC00A/B to SK40C. Please refer UIC00A/B User s Manual for the method to load hex file into PIC. Step to get LCD backlight: 1. To get LCD backlight, user need to get header pin and mini jumper which are not provide in packaging. Figure 10 2. Solder the header pin to JP8 as shown in Figure 11. Figure 11 3. Put the mini jumper as shown in Figure 12 to get LCD backlight. User can choose to disable the LCD backlight by take off the mini jumper. Figure 8 Figure 12
Control LCD backlight contrast: The contrast of LCD display can be adjusted by tuning the potential meter as shown in Figure 13. WARRANTY Figure 13 No warranty will be provided as this is DIY project. Thus, user is advice to check the polarity of each electronic component before solder it into board.
Appendix A LCD Power supply SK40C UIC00A/B Figure 14: Complete connection Table 3: ASCII table
Table 4: DDRAM Address (in Hex value) * Cytron Technologies reserved the right to replace the component in the list with component of the same functionality without prior notice. Prepared by Cytron Technologies Sdn. Bhd. 19, Jalan Kebudayaan 1A, Taman Universiti, 81300 Skudai, Johor, Malaysia. Tel: +607-521 3178 Fax: +607-521 1861 URL: www.cytron.com.my Email: support@cytron.com.my sales@cytron.com.my