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:microprocessor-io-unit-1:start [2017/05/02 22:26] – [8.2. General Notes of Interest] Marthalearn:courses:microprocessor-io-unit-1:start [2021/10/13 22:24] (current) Arthur Brown
Line 2: Line 2:
 [[{}/learn/courses/start|Back to Course List]] [[{}/learn/courses/start|Back to Course List]]
 ==Unit 1 Labs== ==Unit 1 Labs==
-  * [[https://reference.digilentinc.com/learn/courses/microprocessor-io-lab-1a/start|Lab 1a]] +  * [[/learn/courses/microprocessor-io-lab-1a/start|Lab 1a]] 
-  * [[https://reference.digilentinc.com/learn/courses/microprocessor-io-lab-1b/start|Lab 1b]]+  * [[/learn/courses/microprocessor-io-lab-1b/start|Lab 1b]]
  
  
 == Download This Document == == Download This Document ==
-  * {{ :learn:courses:microprocessor-io-unit-1:unit_1.pdf |Unit 1 PDF}}+{{ :learn:courses:microprocessor-io-unit-1:unit_1.pdf |Unit 1 PDF}}
  
  
Line 16: Line 16:
  
 ===== 2. Objectives ===== ===== 2. Objectives =====
-  How to develop a plan for a software-based microprocessor design. +  How to develop a plan for a software-based microprocessor design. 
-  Understand the management of basic microprocessor digital inputs and outputs. +  Understand the management of basic microprocessor digital inputs and outputs. 
-  Write an application that utilizes the Basys MX3 processor platform to perform basic calculator functions and display the results on a 4-digit 7-segment LED display.  +  Write an application that utilizes the Basys MX3 processor platform to perform basic calculator functions and display the results on a 4-digit 7-segment LED display.  
-  Become familiar with the circuits included on the Basys MX3 PCB. +  Become familiar with the circuits included on the Basys MX3 PCB. 
  
  
Line 25: Line 25:
  
 ===== 3. Basic Knowledge ===== ===== 3. Basic Knowledge =====
-  Fundamentals of digital [[https://en.wikipedia.org/wiki/Combinational_logic|combinational]] and [[https://en.wikipedia.org/wiki/Sequential_logic|sequential]] logic. +  Fundamentals of digital [[https://en.wikipedia.org/wiki/Combinational_logic|combinational]] and [[https://en.wikipedia.org/wiki/Sequential_logic|sequential]] logic. 
-  How to interpret a schematic diagram and electric circuits. +  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 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.+  How to launch a [[http://microchip.wikidot.com/tls0101:design-environment|Microchip MPLAB X]] project.
  
  
Line 35: Line 35:
 ===== 4. Equipment List ===== ===== 4. 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]] +  [[microprocessor/basys-mx3/start|Basys MX3 trainer board]] 
-  [[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://www.digilentinc.com/Products/Detail.cfm?NavPath=2,842,1018&Prod=ANALOG-DISCOVERY|Digilent Analog Discovery 2]]+  [[http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,842,1018&Prod=ANALOG-DISCOVERY|Digilent Analog Discovery 2]]
  
 ==== 4.2. Software ==== ==== 4.2. Software ====
 The following programs must be installed on your development workstation: The following programs must be installed on your development workstation:
-  [[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://microchip.wikidot.com/mplabx:installation|Installation help]]     * [[http://microchip.wikidot.com/mplabx:installation|Installation help]]
     * [[http://microchip.wikidot.com/tls0101:start|Getting started]]     * [[http://microchip.wikidot.com/tls0101:start|Getting started]]
-  [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]] +  [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler]] 
-  [[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]]
  
  
Line 55: Line 55:
  
 ===== 5. Project Takeaways ===== ===== 5. Project Takeaways =====
-  Understand best practices for creating dependable and sustainable software. +  Understand best practices for creating dependable and sustainable software. 
-  Know how to generate a microprocessor development project using MPLAB X. +  Know how to generate a microprocessor development project using MPLAB X. 
-  Know how to generate a config_bits file for the PIC32MX370 processor.  +  Know how to generate a config_bits file for the PIC32MX370 processor.  
-  Know how to configure the Microchip PIC32 processor pins as either digital inputs or outputs. +  Know how to configure the Microchip PIC32 processor pins as either digital inputs or outputs. 
-  Understand the drive capability of a processor digital output.  +  Understand the drive capability of a processor digital output.  
-  Know how to write a C program for a specific application using an embedded system. +  Know how to write a C program for a specific application using an embedded system. 
-  Know how to make speed performance measure on a processor-based system. +  Know how to make speed performance measure on a processor-based system. 
  
  
Line 126: Line 126:
 //Figure 8.1. Integrated Development Hardware Diagram.// //Figure 8.1. Integrated Development Hardware Diagram.//
  
-The diagram in Fig. 8.1 shows the Basys MX3 unit. The Basys MX3 has a built-in programmer/debugger that allows a direct connection from the development workstation computer to the Basys MX3 board. If the programmer/debugger is not built into the hardware platform, a separate programmer is required, such as the [[http://store.digilentinc.com/pickit-3-in-circuit-debugger/|PICkit 3]] or a [[http://store.digilentinc.com/chipkit-pgm-programmer-debugger-for-use-with-digilent-chipkit-platforms/|chipKIT Programmer]].  +The diagram in Fig. 8.1 shows the Basys MX3 unit. The Basys MX3 has a built-in programmer/debugger that allows a direct connection from the development workstation computer to the Basys MX3 board. If the programmer/debugger is not built into the hardware platform, a separate programmer is required, such as the PICkit 3 or a chipKIT Programmer.  
  
 ==== 8.2. General Notes of Interest ==== ==== 8.2. General Notes of Interest ====
Line 138: Line 138:
     #define _SUPPRESS_PLIB_WARNING     #define _SUPPRESS_PLIB_WARNING
 #endif #endif
-    #ifndef _DISABLE_OPENADC10_CONFIGPORT_WARNING + 
-        #define  _DISABLE_OPENADC10_CONFIGPORT_WARNING +#ifndef _DISABLE_OPENADC10_CONFIGPORT_WARNING 
-    #endif+    #define  _DISABLE_OPENADC10_CONFIGPORT_WARNING 
 +#endif
 </code> </code>
 <html> <html>
   <ol start="4">   <ol start="4">
-<li>Table 8.1 below, reproduced from the [[http://ww1.microchip.com/downloads/en/DeviceDoc/51686F.pdf|MPLAB XC32 C/C++ Compilers User’s Guide]], notes that the legacy library option is automatically selected for new projects. If using MPLABX 3.40 or later, when starting a new project, this option must **not** be checked, as shown in Fig. 8.2.</li></ol></html>+<li>Table 8.1 below, reproduced from the </html>[[http://ww1.microchip.com/downloads/en/DeviceDoc/51686F.pdf|MPLAB XC32 C/C++ Compilers User’s Guide]], notes that the legacy library option is automatically selected for new projects. If using MPLABX 3.40 or later, when starting a new project, this option must **not** be checked, as shown in Fig. 8.2.
  
 **Table 8.1. XC32 (Global Options) all Options Category.** **Table 8.1. XC32 (Global Options) all Options Category.**
Line 190: Line 191:
     - Right-click on the Header Files and select “New” -> “XC32 Header.h”. Name this file “config_bits.h”.     - Right-click on the Header Files and select “New” -> “XC32 Header.h”. Name this file “config_bits.h”.
     - Click on “Windows” -> “PIC Memory Views” -> “Configuration Bits”.     - Click on “Windows” -> “PIC Memory Views” -> “Configuration Bits”.
-    - Set the options as shown in Listing C.in the Appendix.+    - Set the options as shown in Listing B.in the Appendix.
     - Click on “Generate Source Code to Output”.     - Click on “Generate Source Code to Output”.
     - Enter “CTRL A” to highlight the text in the output window and “CTRL C” to copy the text.      - Enter “CTRL A” to highlight the text in the output window and “CTRL C” to copy the text. 
Line 210: Line 211:
 ==== Listing A.1. Format of a Typical Main Function ==== ==== Listing A.1. Format of a Typical Main Function ====
 <code> <code>
-     int main(int argc, char** argv) + int main(int argc, char** argv) 
  {  {
  // Initialization code goes here  // Initialization code goes here
Line 529: Line 530:
  
   @File Name   @File Name
-   PICmx370.c+   hardware.c
  
  @Summary  @Summary
Line 548: Line 549:
  
 #include "hardware.h" #include "hardware.h"
-#include "switches.h" 
 #include <plib.h> #include <plib.h>
  
Line 595: Line 595:
        
    Set_All_LEDs_Output(); /* Configure all Basys MX3 LED0 – LED7 as outputs */    Set_All_LEDs_Output(); /* Configure all Basys MX3 LED0 – LED7 as outputs */
-   Set_All_LEDs_Off(); /* Set all Basys MX3 LED0 – LED7 off */+   Set_All_LEDs_Off();         /* Set all Basys MX3 LED0 – LED7 off */
    Set_All_Switches_Input(); /* Configure all Basys MX3 slide switches as inputs */    Set_All_Switches_Input(); /* Configure all Basys MX3 slide switches as inputs */
-   Set_All_PBs_Input(); /* Configure all Basys MX3 push buttons as inputs */+   Set_All_PBs_Input();         /* Configure all Basys MX3 push buttons as inputs */
        
 } /* End of hardware_setup */ } /* End of hardware_setup */
Line 643: Line 643:
 If the bit in the TRIS register is set low to make the I/O pin to function as an output, the voltage pin can be set high by writing a 1 to the appropriate bit in the LAT register. Setting the LAT register bit to a zero sets the output pin low (0V). The actual voltage at the output pin depends on the setting in the ODC register. The default configuration has all bits in the ODC register set to zero, which means the output can both source (supply output current) and sink (pull outputs low) current. If the bit in the ODC register is set high, then the output pin functions as open drain, which can sink current but not source current.  If the bit in the TRIS register is set low to make the I/O pin to function as an output, the voltage pin can be set high by writing a 1 to the appropriate bit in the LAT register. Setting the LAT register bit to a zero sets the output pin low (0V). The actual voltage at the output pin depends on the setting in the ODC register. The default configuration has all bits in the ODC register set to zero, which means the output can both source (supply output current) and sink (pull outputs low) current. If the bit in the ODC register is set high, then the output pin functions as open drain, which can sink current but not source current. 
  
-The maximum current capability of each conventional I/O pin is 15mA (sink or source), while the combined current of all I/O pins is 200mA subject to total power constraints. I/O pins have both open drain and active source output capability. The open drain capability provided by the ODC register is useful when interfacing with switch array keypads (see [[http://store.digilentinc.com/pmodkypd-16-button-keypad/|Pmod KYPD]] for an example keypad device). The outputs that drive the four LEDs on the Basys MX3 board are limited to approximately 5mA. +The maximum current capability of each conventional I/O pin is 15mA (sink or source), while the combined current of all I/O pins is 200mA subject to total power constraints. I/O pins have both open drain and active source output capability. The open drain capability provided by the ODC register is useful when interfacing with switch array keypads (see [[https://digilent.com/shop/pmod-kypd-16-button-keypad/|Pmod KYPD]] for an example keypad device). The outputs that drive the four LEDs on the Basys MX3 board are limited to approximately 5mA. 
  
 The PORT register allows the state of pin to be read regardless if the pin is configured in the TRIS register to be an input or an output. If the voltage on the pin is above the high input threshold, the PORT bit is read as a logic one. Various processor pins have different thresholds.  The PORT register allows the state of pin to be read regardless if the pin is configured in the TRIS register to be an input or an output. If the voltage on the pin is above the high input threshold, the PORT bit is read as a logic one. Various processor pins have different thresholds. 
Line 657: Line 657:
 { {
 // Initialization // Initialization
-    ANSELDbits.ANSD1 = 0;     // RD1 set to digital I/O +    ANSELDbits.ANSD1 = 0;             // RD1 set to digital I/O 
-    TRISDbits.TRISD1 = 0;     // RD1 set to output  +    TRISDbits.TRISD1 = 0;             // RD1 set to output  
-    TRISDbits.TRISD0 = 1;     // RD2 set to input +    TRISDbits.TRISD0 = 1;             // RD0 set to input 
  
 // loop // loop
Line 665: Line 665:
     {     {
         LATDbits.LATD1 = PORTDbits.RD0; //Copy state of RD0 to RD1         LATDbits.LATD1 = PORTDbits.RD0; //Copy state of RD0 to RD1
-    {+    }
 } }
 </code> </code>
Line 676: Line 676:
 // Initialization // Initialization
     ANSELDCLR = 0x02;    // RD1 set to digital I/O     ANSELDCLR = 0x02;    // RD1 set to digital I/O
-    TRISDCLR = 0x02;   // RD1 set to output +    TRISDCLR = 0x02;           // RD1 set to output 
     TRISDSET = 0x01;    // RD0 set to input      TRISDSET = 0x01;    // RD0 set to input 
  
Line 683: Line 683:
     {     {
         if(PORTD & 0x01) // Read RD0 pin         if(PORTD & 0x01) // Read RD0 pin
-      LATDSET = 0x02; // Set RD1 pin high+      LATDSET = 0x02;         // Set RD1 pin high
         else         else
-      LATDCLR = 0x02; // Set RD1 pin low +      LATDCLR = 0x02;         // Set RD1 pin low 
-    {+    }
 } }
 </code> </code>
Line 718: Line 718:
 | 84       | RD7   | RPD7/PMD15/RD7                         | CF            | "                        | | 84       | RD7   | RPD7/PMD15/RD7                         | CF            | "                        |
 | 80       | RD13  | RPD13/RD13                             | CG            | "                        | | 80       | RD13  | RPD13/RD13                             | CG            | "                        |
-| 95       RD14  | TRD2/RD14                              | CP            | "                        |+| 95       RG14  | TRD2/RG14                              | CP            | "                        |
 | 93       | RE0   | PMD0/RE0                               | DB0           | Character LCD data       | | 93       | RE0   | PMD0/RE0                               | DB0           | Character LCD data       |
 | 94       | RE1   | PMD1/RE1                               | DB1           | "                        | | 94       | RE1   | PMD1/RE1                               | DB1           | "                        |