Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
learn:courses:unit-3:start [2017/05/12 18:39] – [Unit 3: Parallel I/O and Handshaking for LCD Control] Talesa Bleythinglearn:courses:unit-3:start [2022/10/04 11:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Unit 3: Parallel I/O and Handshaking for LCD Control ====== ====== Unit 3: Parallel I/O and Handshaking for LCD Control ======
-[[{}/learn/courses/unit-2/start|Back to Unit 2]]+[[:learn:courses:unit-2:start|Back to Unit 2]]
 === Unit 3 Labs === === Unit 3 Labs ===
-  * [[https://reference.digilentinc.com/learn/courses/unit-3-lab3a/start|Lab 3a]] +  * [[/learn/courses/unit-3-lab3a/start|Lab 3a]] 
-  * [[https://reference.digilentinc.com/learn/courses/unit-3-lab3b/start|Lab 3b]]+  * [[/learn/courses/unit-3-lab3b/start|Lab 3b]]
  
 === Download This Document === === Download This Document ===
Line 10: Line 10:
  
 ===== 1. Introduction ===== ===== 1. Introduction =====
-Throughout Unit 3 and Labs [[https://reference.digilentinc.com/learn/courses/unit-3-lab3a/start|3a]] and [[https://reference.digilentinc.com/learn/courses/unit-3-lab3b/start|3b]], you will learn how to interface a PIC32 processor to a character liquid crystal display (LCD) using 8-bit parallel data lines and handshaking using bit-banging techniques. You will learn to translate timing diagrams provided by target equipment data sheets into timed sequences of program instructions. You will also learn how to use ASCII encoded data and control to generate a stable and easily readable display of real-time data.+Throughout Unit 3 and Labs [[/learn/courses/unit-3-lab3a/start|3a]] and [[/learn/courses/unit-3-lab3b/start|3b]], you will learn how to interface a PIC32 processor to a character liquid crystal display (LCD) using 8-bit parallel data lines and handshaking using bit-banging techniques. You will learn to translate timing diagrams provided by target equipment data sheets into timed sequences of program instructions. You will also learn how to use ASCII encoded data and control to generate a stable and easily readable display of real-time data.
  
 You will experiment with the mechanisms required to synchronize asynchronous systems using hardware and software handshaking, as well as explicit and implicit handshaking. You will build a project that consists of multiple C files. We will also look into using variables in software macros. You will experiment with the mechanisms required to synchronize asynchronous systems using hardware and software handshaking, as well as explicit and implicit handshaking. You will build a project that consists of multiple C files. We will also look into using variables in software macros.
Line 20: Line 20:
   - Identify the PIC32 processor pins used for the LCD interface.   - Identify the PIC32 processor pins used for the LCD interface.
   - Write a library of functions, providing the general capability to display strings of text, characters, and numbers at specified positions on the LCD display. All of these functions have strict timing requirements.   - Write a library of functions, providing the general capability to display strings of text, characters, and numbers at specified positions on the LCD display. All of these functions have strict timing requirements.
-    - Initialize the LCD using the recommended sequence of instructions to write specific codes to the LCD at specified intervals. +    * Initialize the LCD using the recommended sequence of instructions to write specific codes to the LCD at specified intervals. 
-    - Write function(s) that write ASCII control data to the Display Data Ram (DDRAM). +    * Write function(s) that write ASCII control data to the Display Data Ram (DDRAM). 
-      - Translate the ASCII carriage return (CR) and line feed (LF) control characters into a sequence of instructions for LCD control. +      * Translate the ASCII carriage return (CR) and line feed (LF) control characters into a sequence of instructions for LCD control. 
-      - Position the cursor where the next character is to be displayed. +      * Position the cursor where the next character is to be displayed. 
-    - Write function(s) that write ASCII character data to the Display Data Ram (DDRAM). +    * Write function(s) 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 single ASCII encoded character to the display. 
-      - Write a function that will write a string (array) of ASCII encoded characters to the display.+      * Write a function that will write a string (array) of ASCII encoded characters to the display.
   - Display static and dynamic text on the LCD.   - Display static and dynamic text on the LCD.
   - Verify that the timing of the handshaking meets the specified minimums.   - Verify that the timing of the handshaking meets the specified minimums.
Line 44: Line 44:
 ===== 4. Unit Equipment List ===== ===== 4. Unit Equipment List =====
 ==== 4.1. Hardware ==== ==== 4.1. Hardware ====
-  * [[http://store.digilentinc.com/basys-mx3-pic32mx-trainer-board-recommended-for-embedded-systems-courses/|Basys MX3 trainer board]]+  - [[https://digilent.com/shop/basys-mx3-pic32mx-trainer-board-for-embedded-systems-courses/|Basys MX3 trainer board]]
     * The 2X16 LCD included on the Basys MX3 processor board can display 16 characters on each of its two lines. The display can be more easily viewed if the LCD backlight is switched on using the slide switch SW9.     * The 2X16 LCD included on the Basys MX3 processor board can display 16 characters on each of its two lines. The display can be more easily viewed if the LCD backlight is switched on using the slide switch SW9.
-  * [[http://store.digilentinc.com/usb-a-to-micro-b-cable/|Micro USB cable]] +  - [[https://digilent.com/shop/usb-a-to-micro-b-cable/|Micro USB cable]] 
-  * Workstation computer running Windows 10 or higher, MAC OS, or Linux+  - Workstation computer running Windows 10 or higher, MAC OS, or Linux
  
 In addition, we suggest the following instruments: In addition, we suggest the following instruments:
-  * [[http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/|Analog Discovery 2 Logic Analyzer]]+  - [[https://digilent.com/shop/analog-discovery-2-100ms-s-usb-oscilloscope-logic-analyzer-and-variable-power-supply/|Analog Discovery 2 Logic Analyzer]]
     * Note: Fig. B.1 through Fig. B.4 in Appendix B shows an Analog discovery 2 connected directly to the LCD data pins and the three handshaking and control pins: RS, R/W, and EN. This custom modification was made to enable testing during software development. It is not required to make this modification in order to complete Lab 3a and Lab 3b. This is further explained in Appendix B.      * Note: Fig. B.1 through Fig. B.4 in Appendix B shows an Analog discovery 2 connected directly to the LCD data pins and the three handshaking and control pins: RS, R/W, and EN. This custom modification was made to enable testing during software development. It is not required to make this modification in order to complete Lab 3a and Lab 3b. This is further explained in Appendix B. 
  
Line 57: Line 57:
 ==== 4.2. Software ==== ==== 4.2. Software ====
 The following programs must be installed on your development work station: The following programs must be installed on your development work station:
-  * [[http://www.microchip.com/mplab/mplab-x-ide|Microchip MPLAB X® v3.35 or higher]] +  - [[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/SWLibraryWeb/product.aspx?product=PIC32%20Peripheral%20Library|PLIB Peripheral Library]] 
-  * [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]] +  - [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]] 
-  * [[http://store.digilentinc.com/waveforms-2015-download-only/|WaveForms 2015]] (if using the Analog Discovery 2)+  - [[https://digilent.com/shop/software/digilent-waveforms/|WaveForms]] (if using the Analog Discovery 2)
  
  
Line 308: Line 308:
 //Figure 7.17. The PMP timing diagram for the beginning, middle, and end wait periods.// //Figure 7.17. The PMP timing diagram for the beginning, middle, and end wait periods.//
  
-The minimum settings for the three PMP WAIT intervals can be determined by dividing the value for t<sub>SU</sub> on the LCD datasheet by T<sub>PB</sub>. For example, assume that the peripheral bus clock is configured for 10 MHz. The t<sub>SU</sub> specified in the KU0066U data sheet is 60 ns, resulting in interval B being equal to 0.6 T<sub>PB</sub> periods. Of course, this should be rounded up, so a proper setting is PMP_WAIT_BEG_1. The value for the interval M is computed using the value specified for t<sub>W</sub>. In this case, M+1 is equal to 2.5, and after rounding up and subtracting one, M equals 2. Thus, PMP_WAIT_MID_2 can be used. The value for interval E is 0.1, resulting in PMP_WAIT_END_1. Since [(B+[M+1]+E) * T<sub>PB</sub> ] represents the minimum time to complete an LCD read or write operation, this minimum time must be greater than the LCD enable cycle time, t<sub>C</sub>, which is specified as 450 ns. For the configuration described above, [(B+[M+1]+E) * TPB] = [(5) * 100 ns] = 500 ns, thereby satisfying the LCD timing specifications. If the cycle time is too short, wait periods can be added to any segment within the allowable ranges.+The minimum settings for the three PMP WAIT intervals can be determined by dividing the value for t<sub>SU</sub> on the LCD datasheet by T<sub>PB</sub>. For example, assume that the peripheral bus clock is configured for 10 MHz. The t<sub>SU</sub> specified in the KU0066U data sheet is 60 ns, resulting in interval B being equal to 0.6 T<sub>PB</sub> periods. Of course, this should be rounded up, so a proper setting is PMP_WAIT_BEG_1. The value for the interval M is computed using the value specified for t<sub>W</sub>. In this case, M+1 is equal to 2.5, and after rounding up and subtracting one, M equals 2. Thus, PMP_WAIT_MID_2 can be used. The value for interval E is 0.1, resulting in PMP_WAIT_END_1. Since  formula (1), below, represents the minimum time to complete an LCD read or write operation, this minimum time must be greater than the LCD enable cycle time, t<sub>C</sub>, which is specified as 450 ns. For the configuration described above, formula (2), below, follows thereby satisfying the LCD timing specifications. If the cycle time is too short, wait periods can be added to any segment within the allowable ranges. 
 + 
 +<html><center></html> 
 +(1) $[B+(M+1)+E] * T_PB$    
 + 
 +(2) $[B+(M+1)+E] * T_PB = (5) * 100 ns = 500 ns$ 
 +<html></center></html>
  
 Since the PMP is clocked from the peripheral bus clock, it is likely that the PMP cycle is slower than the core CPU, which means that the PMP also has a busy flag that must be polled before writing or reading the next byte. With the PMP interrupt disabled, the only way to determine if the PMP is ready for the next read or write cycle is to poll the PMP flag. The //PMPMasterWrite// function provided in the PIC32 Peripheral Library polls the PMP flag to ensure it has been cleared prior to writing. The code for writing to the LCD using the PMP is shown in Listing 7.3. Since the PMP is clocked from the peripheral bus clock, it is likely that the PMP cycle is slower than the core CPU, which means that the PMP also has a busy flag that must be polled before writing or reading the next byte. With the PMP interrupt disabled, the only way to determine if the PMP is ready for the next read or write cycle is to poll the PMP flag. The //PMPMasterWrite// function provided in the PIC32 Peripheral Library polls the PMP flag to ensure it has been cleared prior to writing. The code for writing to the LCD using the PMP is shown in Listing 7.3.
 +
  
  
Line 409: Line 416:
  
 ==== Listing C.1. Steps to Program Graphical Characters ===== ==== Listing C.1. Steps to Program Graphical Characters =====
-  * Reset RS and R/W pins of the LCD to prepare the LCD to accept instructions.  +  - Reset RS and R/W pins of the LCD to prepare the LCD to accept instructions.  
-  * Set the CG RAM address by sending an instruction byte from 64 to 127 (locations 0-63 in CGRAM). +  - Set the CG RAM address by sending an instruction byte from 64 to 127 (locations 0-63 in CGRAM). 
-  * Switch to DATA MODE by changing the RS pin to one.  +  - Switch to DATA MODE by changing the RS pin to one.  
-  * Send bytes with the bit patterns for your symbol(s). The LCD controller automatically increments CGRAM addresses, just as it does cursor positions on the display.  +  - Send bytes with the bit patterns for your symbol(s). The LCD controller automatically increments CGRAM addresses, just as it does cursor positions on the display.  
-  * To leave CGRAM, switch to COMMAND MODE to set the address counter to a valid display address (e.g., 128, 1st character of 1st line); the clear-screen instruction (byte 1); or the home instruction (byte 2). Now bytes are once again being written to the visible portion of the display. +  - To leave CGRAM, switch to COMMAND MODE to set the address counter to a valid display address (e.g., 128, 1st character of 1st line); the clear-screen instruction (byte 1); or the home instruction (byte 2). Now bytes are once again being written to the visible portion of the display. 
-  * To see the custom character(s) you have defined, print ASCII codes 0 through 7.+  - To see the custom character(s) you have defined, print ASCII codes 0 through 7.
  
 ---- ----
  
-[[{}/learn/courses/unit-2/start|Back to Unit 2]] +  * [[:learn:courses:unit-2:start|Back to Unit 2]] 
-[[{}/learn/courses/unit-3-lab3a/start|Go to Lab 3a]] +  * [[:learn:courses:unit-3-lab3a:start|Go to Lab 3a]] 
-[[{}/learn/courses/unit-3-lab3b/start|Go to Lab 3b]] +  * [[:learn:courses:unit-3-lab3b:start|Go to Lab 3b]] 
-[[{}/learn/courses/unit-4-1/start|Go to Unit 4 Part 1]]+  * [[:learn:courses:unit-4-1:start|Go to Unit 4 Part 1]]
  
 {{tag>reference learn microprocessor courses basys-mx3}} {{tag>reference learn microprocessor courses basys-mx3}}