6.1 MPLAB® X with AVR64EA48 Curiosity Nano

Prerequisites

  • MPLAB X installed
  • The AVR64EA48 Curiosity Nano Board is connected to MPLAB X via the on-board USB connector connected to the embedded debugger. The USB powers the kit, and the embedded debugger will enable debugging and programming via the USB.

Workflow

  1. Launch MPLAB X.
  2. The page shown in Figure 6-1 will appear when AVR64EA48 Curiosity Nano is connected to MPLAB X.
    Figure 6-1. AVR64EA48 Curiosity Nano Page in MPLAB® X
  3. Start creating a new project by clicking File → New Project... or using the Ctrl+Shift+N shortcut, as shown in Figure 6-2.
    Figure 6-2. Create New Project in MPLAB® X
  4. Select the Categories → Microchip Embedded and Projects → Standalone Project template from Figure 6-7, and click Next.
    Figure 6-3. New Project Window
  5. Select AVR64EA48 (see Figure 6-4) and click Next.
    Figure 6-4. Device Selection Window
    Then select the board and the desired compiler, if there are any.
  6. Select an available compiler (e.g., XC8 (v.2.40)), and click Finish.
    Figure 6-5. Compiler Selection Window
  7. Type in the name of the project (e.g., LED_TOGGLE) and the project location (e.g., C:\microchip), and click Finish.
    Figure 6-6. Project Name and Location Selection Window
  8. Create a new main.c file by clicking File → New File... or using the Ctrl+N shortcut, as shown in Figure 6-7.
    Figure 6-7. Create a New File in MPLAB® X
  9. Select the Categories → C and File Types → C Main File template from Figure 6-8, and click Next.
    Figure 6-8. New File Window
  10. Type in the file name (e.g., main) and click Finish.
    Figure 6-9. File Name Window
  11. Replace the main.c file with the following code snippet:
    int main (void)
    {
     /* Configure SW0 as input */
     PORTB.DIRCLR = PIN2_bm;
     /* Configure LED0 pin as output */
     PORTB.DIRSET = PIN3_bm;
     /* Enable the internal pull-up for SW0 */
     PORTB.PIN2CTRL |= PORT_PULLUPEN_bm;
    
     while (1)
     {
     /* Check the status of SW0 */
     /* 0: Pressed */
     if (!(PORTB.IN & (PIN2_bm)))
     {
     /* LED0 on */
     PORTB.OUTCLR = PIN3_bm;
     }
     /* 1: Released */
     else
     {
     /* LED0 off */
     PORTB.OUTSET = PIN3_bm;
     }
     }
    }
    Add #inlude<avr/io.h> in main.c. In the code editor, the code will appear as shown in Figure 6-10.
    Figure 6-10. Code Editor Window
  12. Build the code by clicking on Production → Clean and Build Main Project or using the Shift + F11 shortcut.
  13. Program AVR64EA48 with the project code and start debugging by clicking Debug → Debugging Main Project.
  14. Verify that LED0 is lit when SW0 is pushed on the AVR64EA48 Curiosity Nano.