[[labs.beatcraft.com]]~ [[BC-USB-Kit]]~ [[BC-USB-Kit/Tutorials]]~ #contents *Tutorial1 [#d743abe6] **Overview [#tfa7e861] > This document is an introduction of PIC programming. To use BC-USB~Kit, this explains the basics of PIC programming. Please consider this to be kind of PIC Programming 101 or PIC for Dummy.~ **Lightning up an LED [#l404263b] > To follow the great tradition of programming on electronic works (electronic hobby), this article shows how to light up the LED.~ **Preparation [#ebc05fd9] > To read and follow [[this article:http://labs.beatcraft.com/en/index.php?BC-USB-Kit%2Fget%20started]],~ please install MPLAB X IDE.~ # In this article, MPLAB XIDE v2.35 is installed on Mac OS X (10.10.3).~ ~ - Download bc_usbkit_pic24f.zip, and expand the zip file in any directory you wish for.~ #ref(bc_usbkit_pic24f.zip)~ To write a program for BC-USB-Kit effortlessly, this file contains the information, which is specifically set up for BC-USB-Kit, including the clock frequency and other default settings and functions for setting the button and LED of BC-USB-Kit.~ **Creating a new project [#cab1af44] > Select "New Project" form "File" at the menu bar.~ Please select "Microchip Embedded" form "Categories" and “Standalone Project” from "Project."~ Then, click the Next button.~ &ref(TI_00.png,,60%);~ ~ Choose 16-bit MCUs (PIC24) from the pull down menu at Family, and select PIC24FJ128GB202 from the pull down menu at Device. Then, click the Next button.~ ~ &ref(TI_01.png,,60%);~ ~ Select "PICKit3."~ &ref(TI_02.png,,60%);~ ~ Choose "X16."~ &ref(TI_03.png,,60%);~ ~ Type in “LED_Test” at Project Name, and select “UTF-8” at Encoding. Then, click “Finish”~ &ref(TI_04.png,,60%);~ ~ If “LED_Test” appears on the left pane, the new project is created without any issues.~ &ref(TI_05.png,,60%);~ ~ To click the right-side button (for Mac OS X, click with the two-finger) on “Source File,” please select “New” from the pop-up menu. Then, choose “C Main File,,,” from the sub-menu.~ &ref(TI_06.png,,60%);~ ~ Type in “main” at File Name. Then, click the Finish button.~ &ref(TI_07.png,,60%);~ ~ Then, main.c is added into Source Files.~ &ref(TI_08.png,,70%);~ ~ Click the hammer (build) icon, Then, if “BUILD SUCCESSFUL,” which are written in green, appears in Output tab at the bottom pane, the build process is succeeded.~ &ref(TI_09.png,,60%);~ ~ Open “Project Properties” from File at the menu bar.~ Select "xc16-gcc" from the list of Categories in the left pane.~ At Option categories, select “Preprocessing and message” and add the path of "bc_usbkit_pic24f" to "C include dirs."~ &ref(TI_11.png,,60%);~ ~ To click the right-side button (for Mac OS X, click with the two-finger) on “Source File,” please select “Add Existing Items form Folders” from the pop-up menu. Then, add "bc_usbkit_pic24f."~ If "bc_usbkit_pic24f" is located under Source Files, it is successfully added.~ &ref(TI_10.png,,60%);~ ~ To include a header file, please add a line of code shown below to main.c.~ #include <system.h> > Then, click the icon of a broom on a hammer (Clean and build)~ If “BUILD SUCCESSFUL, which are written in green, appears in Output tab at the bottom pane, the build process is succeeded.~ **Lightning up the LED [#i71f18c4] > As shown in the picture below, please connect BC-USB-Kit with PICKit 3.~ # The power of BC-USB-Kit is supplied from the right-side USB port of the MacBook Air.~ &ref(MBA_and_BC-USB-Kit.jpg,,60%);~ > Please add two lines of code shown below to main.c.~ SYSTEM_Initialize(SYSTEM_STATE_START); LED_On(LED_D1); > The contents of main,c file are organized as such as shown below.~ &ref(TI_12.png,,90%);~ ~ Click the icon of a broom on a hammer (Clean and build).~ Then, click the icon of the right faced green triangle (Run Main Project), which is located next to click the icon of a broom on a hammer (Clean and build)~ ~ If the LED is lightened in orange, the main project runs successfully.~ ~ &ref(LED_off.jpg,,50%); SIZE(25){→} &ref(LED_on.jpg,,50%);~ &ref(LED_off.jpg,,40%); SIZE(25){→} &ref(LED_on.jpg,,40%);~ ** Revision History [#j2b77499] > - 2015-04-22 This article is initially published.~