====== Lab 3a: LCD Parallel Interface - Direct IO Control ====== [[{}/learn/courses/unit-3/start|Back to Unit 3]] == Download This Document == * {{ :learn:courses:unit-3-lab3a:lab_3a.pdf |Lab 3a PDF}} ===== 1. Objectives ===== - Identify the PIC32 processor pins used for the LCD interface. - Implement LCD control using bit-banging I/O techniques. - Understand handshaking requirements for interfacing two systems operating at differing clock speeds. ---- ===== 2. Basic Knowledge ===== - How to interpret [[https://en.wikipedia.org/wiki/Control_flow_diagram|control flow]] and [[https://en.wikipedia.org/wiki/Data_flow_diagram|data flow]] diagrams. - [[http://www.learn-c.com/schemat.htm|How to interpret a schematic diagram and electric circuits]]. - How to write a computer program using the [[http://www.tutorialspoint.com/cprogramming/index.htm|C language]]. - How to launch a [[http://microchip.wikidot.com/tls0101:design-environment|Microchip MPLAB X]] project. ---- ===== 3. Equipment List ===== ==== 3.1. Hardware ==== - [[https://digilent.com/shop/basys-mx3-pic32mx-trainer-board-for-embedded-systems-courses/|Basys MX3 trainer board]] - [[https://digilent.com/shop/usb-a-to-micro-b-cable/|Micro USB cable]] - Workstation computer running Windows 10 or higher, MAC OS, or Linux In addition, we suggest the following instruments: - [[http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,842,1018&Prod=ANALOG-DISCOVERY|Digilent Analog Discovery 2]] ==== 3.2. Software: ==== - [[http://www.microchip.com/mplab/mplab-x-ide|Microchip MPLAB X® v3.35 or higher]] - [[http://www.microchip.com/SWLibraryWeb/product.aspx?product=PIC32%20Peripheral%20Library|PLIB Peripheral Library]] - [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]] - [[https://digilent.com/shop/software/digilent-waveforms/|WaveForms]] ---- ===== 4. Project Takeaways ===== - How to implement a bi-directional parallel IO interface. - How to use delays to control signal timing. - How to manage ASCII text strings. ---- ===== 5. Fundamental Concepts ===== Microprocessors are the core element in an [[https://en.wikipedia.org/wiki/Embedded_system|embedded system]]. Most embedded applications need resources or capability not available in the microprocessor. The additional capability can be provided by specialty electronic devices. Computer communications is necessary to exchange data between the microprocessor and these devices. The communications interface is provided using serial or parallel inputs and outputs. Parallel I/O implies multiple input/output operations at the same time whereas serial I/O implies single bit data exchanges. Whether the communications interface is serial or parallel, handshaking is required to coordinate the data exchange activity. ---- ===== 6. Problem Statement ===== Develop and test a collection functions that allow text to be placed at any position on a parallel I/O character LCD following the DFD and CFD models presented in Unit 3. The //LCD_puts// function is required to process the [[http://www.asciitable.com/|ASCII control characters]], which are described in Table 8.1. ---- ===== 7. LCD Background Information ===== Character [[https://en.wikipedia.org/wiki/Liquid-crystal_display|Liquid Crystal Displays]] (LCD) are low-cost electronic devices that are capable of generating visual displays consisting of alphanumeric characters and graphical symbols commonly used for [[https://en.wikipedia.org/wiki/Embedded_system|embedded system human machine interfaces]] (HMI). Many suppliers of LCD devices are based on the [[https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller|Hitachi HD44780]] LCD controller, and hence have a common hardware and software interface. Some LCD devices have serial interfaces that use UART, I2C, and SPI communications((PmodCLS: Character LCD with Serial Interface, [[https://digilent.com/shop/pmod-cls-character-lcd-with-serial-interface/]])). These protocols are covered in Unit 4. Other LCD devices use interfaces consisting of four or eight data lines and three control lines((PmodCLP Character LCD with Parallel Interface, [[https://digilent.com/reference/pmod/pmodclp/start]])). Although the LCDs that use a serial interface require fewer processor I/O pins, the display controller IC is still based on the Hitachi HD44780, which uses 8 or 11 I/O pins. Hence, the serial LCD devices have an on-board microprocessor that translates the serial communications instructions to parallel I/O. The handshaking required to successfully communicate with the LCD on the Basys MX3 is representative of many common parallel interfaces. ---- ===== 8. Lab 3a ===== ==== 8.1. Requirements ==== - All LCD interface pin control will use //LATx//, //LATxSET//, or //LATxCLR// instructions for outputs and //PORTxBITS// for inputs. - Write a library of functions to provide general capability to display strings of text, characters, and numbers at specified positions on the LCD display. - All LCD control sequences must meet the strict timing requirements for the following operations: - Initialize the LCD using the recommended sequence of instructions shown in the control flow diagram FIg. B.2. to write specific codes to the LCD at specified intervals. - Position the cursor in the display space (Line 1 or Line 2) where the next character is to be displayed. - Write function(s) that write ASCII control and display data to the Display Data Ram (DDRAM). - Translate the ASCII control characters into one or more C instructions for the LCD, as detailed in Table 8.1. - Write functions that write ASCII character data to the Display Data Ram (DDRAM). - Write a function that will write a single ASCII encoded character to the display. - Write a function that will write a string (array) of ASCII encoded characters to the display. - Using the following program, develop a test project that will verify that the function //LCD_puts(byte *str);// correctly displays an array of ASCII text and control characters. char test_str[] = “ User generated test string”; int main(void) { hardware_setup(void); // Initialize the LCD IO pins LCD_init(); // Initialize LCD while(1) { LCD_puts(test_str); // Display the text string DelayMs(1000); // Delay 1 second LCDWrite(0x01); // Clear LCD } } - Write an application program for the Basys MX3 processor board that achieves the following: - Initializes a loop counter to a value of zero. - Displays your name on the first line. - Repositions the cursor to the beginning of the second line and displays the text “LAB 3.” - Repositions the cursor to the eighth character position of the second line. - Displays the value of the loop counter. - Increments the loop counter. - Delays one second before repeating steps d through g. **Table 8.1. LCD controls.** ^ ASCII Character ^ Hex\\ Code ^ LCD Code ^ Action ^ | LF | 0x0A | 0x01 | Line Feed: Clears the line where the cursor is positioned and places the cursor at left position on that line | | CR | 0x0F | 0x02 | Return: Places the cursor at left position on the line where the cursor is positioned without clearing display | | TAB | 0x09 | | Moves cursor position 4 places to the right. If this action places the cursor beyond the end of Line 1, the cursor will be placed at the start of Line 2. | | FF | 0x0C | 0x01 | Form Feed: Clears display and places the cursor at left position on top line | ==== 8.2. Design Phase ==== - Generate a project in MPLAB X. - Copy the config.bits file to the project directory. - Open three new C files: main.c, lcd.c, and swdelay.c. - Open two new header files: lcd.h and swdelay.h. - Generate the contents of the main.c file for the initialization code and the infinite loop. - In swdelay.c, generate a function prototype for the //msDelay(unsigned int dly);// function. - Copy the software delay function from Unit 2, Listing 3 to swdelay.c. - In lcd.h, generate function prototypes for the five LCD functions shown in Fig. B.1. - Generate the code for the five LCD functions in lcd.c. ==== 8.3. Construction Phase ==== - Write a problem statement that lists the requirements. - Determine what elements of the Basys MX3 board will be used. - List the processor hardware resources that you will be using in this design. - Generate a data flow diagram that identifies tasks (functions) and the information that needs to be passed between these tasks. - Using the DFD and the multiple CFDs shown in Appendix B, develop and test the functions that will initialize the LCD and display single characters and a string of characters. You should use the? software delay function used in Lab 1b. ==== 8.3. Construction Phase ==== - Write a problem statement that lists the requirements. - Determine what elements of the Basys MX3 board will be used. - List the processor hardware resources that you will be using in this design. - Generate a data flow diagram that identifies tasks (functions) and the information that needs to be passed between these tasks. - Using the DFD and the multiple CFDs shown in Appendix B, develop and test the functions that will initialize the LCD and display single characters and a string of characters. You should use the? software delay function used in Lab 1b. ==== 8.4. Testing ==== - Demonstrate that the test program developed for requirement 4 executes correctly using the test string “\0141234\0115678\0119ABC\r”. - Demonstrate that the test program developed for requirement 5 executes correctly. ---- ===== 9. Questions ===== - How would the LCD display be affected if the application described above is combined with an application that uses interrupts? - How can the blocking semaphore represented by the Busy Flag be eliminated? - What is the maximum rate at which characters can be written to the LCD? ---- ===== 10. References ===== - Basys MX3 Data sheet. - [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|PIC32MX330/350/370/430/450/470]] Family Data Sheet. - 2 Line 16 Character LCD Data Sheet, [[http://www.lcd-modules.com.tw/upload/web/SC/SC1602B.pdf|http://www.lcd-modules.com.tw/upload/web/SC/SC1602B.pdf]]. - LCD Data sheet, [[https://www.sparkfun.com/datasheets/LCD/ADM1602K-NSW-FBS-3.3v.pdf|https://www.sparkfun.com/datasheets/LCD/ADM1602K-NSW-FBS-3.3v.pdf]]. - ASCII Table, [[http://www.asciitable.com/|http://www.asciitable.com/]]. ---- ===== Appendix A: Basys MX3 Schematic Drawings ===== {{ :learn:courses:unit-3-lab3a:lab_3a_3_fig_a_1.jpg?nolink&550 |Figure A.1. LCD connection schematic diagram for Labs 3a and 3b.}} //Figure A.1. LCD connection schematic diagram for Labs 3a and 3b.// ---- ===== Appendix B: LCD Code Concept Maps ===== {{ :learn:courses:unit-3-lab3a:lab3a-figure-b-1.png?nolink |Figure B.1. Data flow diagram for the LCD control.}} //Figure B.1. Data flow diagram for the LCD control.// {{ :learn:courses:unit-3-lab3a:lab3a-figure-b-2.png?nolink |Figure B.2. Control flow diagram for the LCD initialization.}} //Figure B.2. Control flow diagram for the LCD initialization.// {{ :learn:courses:unit-3-lab3a:lab3a-figure-b-3.png?nolink |Figure B.3. Control flow diagram for LCD Write operation using bit-banging.}} //Figure B.3. Control flow diagram for LCD Write operation using bit-banging.// {{ :learn:courses:unit-3-lab3a:lab3a-figure-b-4.png?nolink |Figure B.3. Control flow diagram for LCD Write operation using bit-banging.}} //Figure B.4. Control flow diagram for LCD Write operation using bit-banging.// {{ :learn:courses:unit-3-lab3a:lab3a-figure-b-5.png?nolink |Figure B.5. LCD display character control flow diagram.}} //Figure B.5. LCD display character control flow diagram.// ---- [[{}/learn/courses/unit-3/start|Back to Unit 3]] [[{}/learn/courses/unit-3-lab3b/start|Go to Lab 3b]]