Read Aloud the Text Content
This audio was created by Woord's Text to Speech service by content creators from all around the world.
Text Content or SSML code:
In this tutorial the 8 pin, "PIC"12, "F15""72" will be programmed to switch ON an "LED" connected to pin 5, setup as a General purpose I O or "GPIO" on "RA2", using both the PIC Kit 4 and Snap programmers. The tutorial is done using Assembly first and then C, in two parts. The C coding is done in Bare Metal, also known as "register programming" and then using the MP LAB "MCC" generated code format. First some basic info for beginners. Breadboard connection points are internally connected in the following way. The transparent green line indicates the internally connected points for column 1,row a to e. The lower row f to j indicated by the second transparent line, are also internally connected but are separated from a to e by the center division of the breadboard. If a "PIC"12, "F15""72" device is installed in the following position, the red pin is connected to all connections a to e and so to is the orange pin connected to all the connections f to j of column 1. For the rest of the device pins and any electronic components added to the breadboard, the same applies as indicated by the transparent vertical lines here. The Power rails are connected horizontally as indicated by the transparent lines, but the top and bottom rows are not internally connected. The upper and lower positive power rails can be connected to share the same voltage levels, but can be left separate for different voltages if required. The Negative power rail is connected in the same way as the positive rail. An "LED" has a longer leg called the Cathode and is the positive connection. The shorter leg, called the Anode is negative. This is the symbol used in these tutorials, with colors, related to polarity indicated. Another feature, is the flat edge on the side of the Anode. For this first part of this tutorial, the LED will be connected with the negative Anode leg to Pin 5 or RA2, this can be done using available positions on the green transparent line below RA2, as seen on 4,h and the positive leg can be connected to any point of the green transparent line, here on 5,h. There is also a current limiting resistor of 1 kilo ohm connected from 5,j in series with the positive power rail. With the LED connected in this way, the PIC device can turn On the LED by completing the connection from resistor through LED to ground via the internal device connections. This is known as Sinking". So if pin RA2 is High or a "1" then the LED will remain Off and only if the device pin RA2 switches to ground or 0, will the LED be turned On. The PIC device pins, colour coded and Programmer connections can now be completed, including the required 10 to 50 kilo ohm resistor before the device is powered up. The PICkit4 can be configured to power the device for programming and debugging or used with an external power supply to breadboard. In this case, the PICKit4 is then setup to detect the external supply. Both PICkit4 programmer setups, externally powered and powering the circuit will be covered. The Snap programmer requires external power to breadboard and this setup is covered too. We will now look at creating a new project using the MPLAB X IDE and we will start by using IDE version 5.05 allowing us to begin with an Assembly project. If your installation version of MPLAB X IDE has the MPASM Assembler installed, then proceed, if not sure, check out the MPLAB X IDE Installation tutorial. Ensure the PICKit4 or Snap programmer is connected via an available USB port, then run MPLAB X IDE version 5.05 The Programmer is found message should be displayed if the drivers are installed correctly.To start, a new project must be created. Select "File", "New project" from menu or select the New Project icon, then select Microchip Embedded and Standalone Project, then next. Now type in part of the device name, in this case 1572 will bring up the option to select the PIC12F1572 and then click next. Select the tool from the Hardware Tools window, if your "Programmer is found message" was displayed when opening MPLAB X IDE then the Hardware Tool window will display your device to select now. Then click next. From the Compiler Tool chains window select "mp" "asm", version 5.81 if using "MP" "LAB" X "IDE" version 5.05, for other "IDE" versions select the "MP" "ASM" version but be aware that there may be issues to resolve or use v5.05 Then click next. Give the Project Name, here we can use "PIC"12, "F15""72" underscore "LED" underscore ON underscore SINK. A project location can be selected on the hard drive if the default location is not suitable. Then click Finish. The new project is now created, the "Projects" window has a Folder, with the name given to the project and some default sub folders are created. In the lower window, the project's Dashboard has additional information such as the programmer assigned to this project. A source file needs to be created. From the Projects window, select the Source Files folder, right click and from New scroll to the Assembly File . "asm" option, click to create the first file. Give a name for the new Assembly file, name it LED underscore ON underscore SINK for this tutorial. Then click finish. This file is now added under the Source files folder in the projects window. If double clicked on, this new file will open up in the editors window on the right as displayed here. Each "PIC" device has configuration Words which need to be setup as required for each application. For the breadboard tutorials, no external oscillator is required, as the use of the devices internal oscillator will be used. An Oscillator allows a "PIC" device to function, without it, no code can be "clocked" to process code. Use the Window Menu Tab and scroll down to Target Memory views then to Configuration Bits. The Configuration Bits Window has an Option column for each of the Fields of the Configuration Words. CONFIG1 is found at Address 8007 and CONFIG2 at Address 8008, by default all bits are 1 therefore the Address register's Value is" F F F F" hexadecimal. These Fields are comprised of various numbers of bits of each configuration word. When referring to the DEVICE CONFIGURATION, section 4 of the PIC12 F1572 datasheet, the Register Definitions for the Configuration Words has details needed to select, to suit a specific application. To select the internal Oscillator for our breadboard tutorial, the "FOSC"Field Option, will need to be changed from the default "ECH",, to "INTOSC". The default bit values of CONFIG1, are indicated by all the set bits "1", in the top row here. The R, P, and U letters are for Readable, Programmable and Unimplemented bits. When the "FOSC" Field Option is changed to "INTOSC", the value of CONFIG1 register changes from "F F F F" to "F F F C", which confirms bits 0 and 1 are now read as 0, which matches the value of "FOSC" field when selected for "INTOCS" and the rest of the bits are default values of 1. This is the only change to the default Configuration bits required for this tutorial, Below the Configuration Bits window is a Generate Source Code button. Click on to generate the code for the Configuration Bits modification made above. The Output Config Bits Source window has the generated source code. Which can be selected and copied, then pasted into the created Assembly source file. Control C copies text once selected with use, ensure all the highlighted text is selected correctly, including the colons. Note if this symbol is used it's referred to as an underscore and there is also a double underscore used. Click inside the "LED" underscore ON underscore SINK assembly file window, then use Control V for pasting the copied source code. Now let us discuss some details of pasted source Code. Comments are ignored by compiler and start with a semicolon. The editor turns them green. These comments can be added for information purposes explaining parts of the lines of code to assist later on when code is being debugged. The two default comments above can be left for now being purely information. The directive, pound include, adds code from another file, during compilation before being processed into machine code and loaded into a PIC device. In this case a device file that defines the registers, also known as register files, and details of the PIC micro controller we are using, in this case "p12" "f15" "72" . inc Note that these include file names vary between compilers used by different versions of "MP" "LAB" X IDE's. These files are located on your computer, a search for "p12" "f15" "72" will allow the file to be opened by a text program for review but that will come later. The next two comments are related to CONFIG1 and the value of the word as generated, being a hexadecimal value of "F F F C", which is the equivalent of quadruple 1, quadruple 1, quadruple 1, double 1, double 0 binary, the bits 0 and 1 being double zero, matching the option of "INTOCS" for Field "FOCS". The double underscore "CONFIG" instruction defines Configuration words 1 & 2 for the "PIC", which control "PIC" operation. We have only modified the "FOSC" field option for use with the breadboard tutorials, the rest will be used later and covered in detail then, but for now, the individual Field options we saw in the Configuration Bits windows can be seen to match there default states, being On or OFF or the modified option to "FOSC_INTOSC". Each option is separated by an & symbol. These options can be altered within this assembly file, but be aware any mistake in syntax will create errors during a build.