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/03/21 17:00] – [Listing C.1. Steps to Program Graphical Characters] Marthalearn: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]]
 === 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 ===
-  * {{ :learn:courses:unit-3:unit_3.pdf |Unit 3 PDF}}+{{ :learn:courses:unit-3:unit_3.pdf |Unit 3 PDF}}
  
  
 ===== 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 19: 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 43: 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 56: 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 307: 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 358: Line 366:
  
 ===== Appendix A: Unit 3 Parts Configuration ===== ===== Appendix A: Unit 3 Parts Configuration =====
-{{ :learn:courses:unit-3:figure-a-1.png?nolink |Figure A.1. LCD connection schematic diagram for Labs 3a and 3b.}}+{{ :learn:courses:unit-3:unit_3_fig_a_1.jpg?nolink&500 |Figure A.1. LCD connection schematic diagram for Labs 3a and 3b.}}
 //Figure A.1. LCD connection schematic diagram for Labs 3a and 3b.// //Figure A.1. LCD connection schematic diagram for Labs 3a and 3b.//
- 
  
 ---- ----
Line 368: Line 375:
  
 Note the Analog Discovery 2 is not connected directly to the on-board 30-pin Analog Discovery 2 connector, J4, in this case because the LCD data pins are not broken out to the Analog Discovery Interface connector.  Note the Analog Discovery 2 is not connected directly to the on-board 30-pin Analog Discovery 2 connector, J4, in this case because the LCD data pins are not broken out to the Analog Discovery Interface connector. 
- 
  
 {{ :learn:courses:unit-3:unit_2_-_photo_1.jpg?nolink&400 |Figure B.1. Equipment configuration used in Lab 3a and 3b for Unit 3.}} {{ :learn:courses:unit-3:unit_2_-_photo_1.jpg?nolink&400 |Figure B.1. Equipment configuration used in Lab 3a and 3b for Unit 3.}}
Line 375: Line 381:
 The alternate method to implementing fixed delays, as was discussed in the main body of this text, when writing control or display data bytes is to continuously read the LCD Busy Flag and wait for the Busy Flag to be reset before completing any read or write operation. Therefore, there is no waiting to read the Busy Flag. Figure B.2 is a screen capture of this operation. The Busy Flag and DDRAM address is initially read as 0x4c, meaning that the cursor is located at the 12th character position on the second line and the Busy Flag is off. Following that, a new cursor position, 0x48, is written to the LCD. The value shown in Fig. B.2 is 0xC8 because the 8th bit is set to instruct the LCD to move the cursor to a new position using the “Set DDRAM Address” instruction. The Busy Flag and DDRAM address is read six consecutive times. The busy flag is set high the first five times. The sixth time the busy flag is set low (not busy) and the address shows 0x48, meaning the cursor position is now located for the eighth character position of the second row. The period the Busy Flag reads high for is 33.6 μs. This is consistent with the 39 μs listed in Table 7.3. Again, the execution times shown in Table 7.3 are worst case and dependent on operating temperature and supply voltage. The alternate method to implementing fixed delays, as was discussed in the main body of this text, when writing control or display data bytes is to continuously read the LCD Busy Flag and wait for the Busy Flag to be reset before completing any read or write operation. Therefore, there is no waiting to read the Busy Flag. Figure B.2 is a screen capture of this operation. The Busy Flag and DDRAM address is initially read as 0x4c, meaning that the cursor is located at the 12th character position on the second line and the Busy Flag is off. Following that, a new cursor position, 0x48, is written to the LCD. The value shown in Fig. B.2 is 0xC8 because the 8th bit is set to instruct the LCD to move the cursor to a new position using the “Set DDRAM Address” instruction. The Busy Flag and DDRAM address is read six consecutive times. The busy flag is set high the first five times. The sixth time the busy flag is set low (not busy) and the address shows 0x48, meaning the cursor position is now located for the eighth character position of the second row. The period the Busy Flag reads high for is 33.6 μs. This is consistent with the 39 μs listed in Table 7.3. Again, the execution times shown in Table 7.3 are worst case and dependent on operating temperature and supply voltage.
  
-{{ :learn:courses:unit-3:figure-b-2.png?nolink |Figure B.2. LCD timing diagram for a Set Cursor Position instruction using 1 s setup and EN extension delays.}} +{{ :learn:courses:unit-3:unit_3_fig_b_2.jpg?nolink&1000 |Figure B.2. LCD timing diagram for a Set Cursor Position instruction using 1 μs setup and EN extension delays.}} 
-//Figure B.2. LCD timing diagram for a Set Cursor Position instruction using 1 s setup and EN extension delays.//+//Figure B.2. LCD timing diagram for a Set Cursor Position instruction using 1 μs setup and EN extension delays.//
  
 Figure B.3 shows the timing for the Set Cursor Position instruction where the read cycle speed is increased by a factor of 10. Note that the period waiting for the instruction execution to complete is still 33.6 μs, thus showing the LCD processing time is independent of the processor to LCD interface speed.  Figure B.3 shows the timing for the Set Cursor Position instruction where the read cycle speed is increased by a factor of 10. Note that the period waiting for the instruction execution to complete is still 33.6 μs, thus showing the LCD processing time is independent of the processor to LCD interface speed. 
  
-{{ :learn:courses:unit-3:figure-b-3.png?nolink |Figure B.3. LCD timing diagram for a Set Cursor Position instruction using 0.1 s setup and EN extension delays.}} +{{ :learn:courses:unit-3:unit_3_fig_b_3.jpg?nolink&1000  |Figure B.3. LCD timing diagram for a Set Cursor Position instruction using 0.1 μs setup and EN extension delays.}} 
-//Figure B.3. LCD timing diagram for a Set Cursor Position instruction using 0.1 s setup and EN extension delays.//+//Figure B.3. LCD timing diagram for a Set Cursor Position instruction using 0.1 μs setup and EN extension delays.//
  
 Figure B.4 shows the similar timing of the Set Cursor Position when the PMP interface to the LCD is used in place of the Bit-Banging type of parallel bus control. As one can readily see, the LCD response in Fig. B.3 is very similar to Fig. B.4; however, as discussed in Section 7.5, the PMP interface requires far fewer lines of instruction code. Figure B.4 shows the similar timing of the Set Cursor Position when the PMP interface to the LCD is used in place of the Bit-Banging type of parallel bus control. As one can readily see, the LCD response in Fig. B.3 is very similar to Fig. B.4; however, as discussed in Section 7.5, the PMP interface requires far fewer lines of instruction code.
  
-{{ :learn:courses:unit-3:figure-b-4.png?nolink |Figure B.4. LCD timing diagram for a Set Cursor Position instruction using the PIC32 PMP interface.}}+{{ :learn:courses:unit-3:unit_3_fig_b_4.jpg?nolink&1000  |Figure B.4. LCD timing diagram for a Set Cursor Position instruction using the PIC32 PMP interface.}}
 //Figure B.4. LCD timing diagram for a Set Cursor Position instruction using the PIC32 PMP interface.// //Figure B.4. LCD timing diagram for a Set Cursor Position instruction using the PIC32 PMP interface.//
  
Line 410: 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-3-lab3a:start|Go to Lab 3a]]
 +  * [[:learn:courses:unit-3-lab3b:start|Go to Lab 3b]]
 +  * [[: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}}