DOC PREVIEW
MSU ECE 480 - Introduction to the PIC18F4520

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lab III: Introduction to the PIC18F4520 By Kyle Thomson Revised 1/26/2010 blw You will need the PIC datasheet (DO NOT PRINT), available here: http://ww1.microchip.com/downloads/en/DeviceDoc/39631a.pdf Any use of figures or text from this document for lab reports will result in immediate failure of the lab. A. Getting started A-1 On the protoboard, connect the left side Vdd to the Right side Vdd with red wire. Connect the left side ground to the right side ground with black wire. A-2 Place the microcontroller in the proto-board. Pin 1 of the microcontroller should be at hole 11 of the protoboard. Connect pins 11 and 32 to Vdd, and connect pins 12 and 31 to ground. A-3 Connect a 10K resistor between pin 1 of the microcontroller and Vdd. (Hint for final projects: This is a pull-up resistor, grounding this pin acts as a reset button for the microcontroller.) A-4 Put the clock in the protoboard, the silver dot should be in the lower right hand corner. The top should be located at hole 33 of the protoboard. Connect the power to the clock as shown in the figure to the right. A-5 Connect the pin shown to pin 13 of the microcontroller. A-6 Put the RJ45 header, from your parts kit, in the top of the protoboard, starting pin 1 of the header in hole 1. Connect the pins shown in the figure on the left. Connect pin 2 of the header to Vdd. Connect pin 3 of the header to ground.A-7 Start MPLAB. It is located in Start > All Programs > Microchip > MPLAB IDE v8.43 > MPLAB IDE A-8 Under Projects, start the Project Wizard. Select Next. A-9 In this lab, we are using the PIC18F4520. Make sure this device is selected, and hit Next. A-10 Make sure the Active Toolsuite is set to Microchip C18 Toolsuite. Select Next. A-11 Select “Create New Project File” and browse to the location where you want to save your project. Ex. M:/ece480/Lab3. Select Save and select Next A-12 The window will prompt you to add an existing file. You need to select the file located in C:\ >Program Files > Microchip > MCC18 > Bin > LKR > 18f4520_g.lkr. Select Add. Your screen should look like the figure to the right. Select Next and select Finish A-13 Go to File > New. Copy and paste this block of code into the new window #include <p18cxxx.h> #pragma config WDT=OFF long int count; void main() { TRISD = 0x00; //Set all pins of D to outputs // TRISD = 0xFF sets all pins of D to inputs PORTD = 0; while(1) { PORTD = 0x01; //Set pin 0 of PORTD to 1 for(count = 1; count < 200000; count++); PORTD = 0x02; //Set Pin 1 of PORTD to 1 for(count = 1; count < 200000; count++); PORTD = 0x03; //Set Pins 0 and 1 of PORTD to 1 for(count = 1; count < 200000; count++); } }A-14 Go to File > Save. Type the file name as M:\ece480\LAB3.c. Select the check box at the bottom labeled Add File To Project. Select Save. It should look like the figure to the right A14-1. Verify Library search path. Go to Project > Build Options > Select Project under the directories tab change to view the “Library Search Path” the path should be c:\Program Files\ Microchip\MCC18\lib if it is not browse to the directory and update the path otherwise select Apply and OK A-15 We now need to hook up LEDs to our Port D. Pins 0 and 1 of Port D are located on pins 19 and 20 of the microcontroller. Hook up the LEDs as shown in the figure to the left. The Resistors can be anywhere from 200-500 Ohms. A-16 Turn on the Hewlett Packard DC Power Supply. Press the +6V button under METER. Set this to 5V using the +6V dial. Turn the power supply back off. Connect a black banana-to-banana connector from COM to the Green Ground. Plug a black banana-to-hook from the COM to your protoboard’s ground. Plug a red banana-to-hook from the +6V to your protoboard’s Vdd. It is now time to turn on the power supply. WARNING! If a yellow light comes on under OVERLOAD, or your amps go past 0.10, turn off the power supply IMMEDIATELY and ask your TA for help. You can burn out your microcontroller very easily, and it will not be replaced! WARNING!A-17 Now plug the Microchip MPLAB ICD 2 into the adaptor on the protoboard. In MPLAB, select under Debugger > Select Tool > MPLAB ICD 2. If you get a warning about downloading a new OS select OK otherwise your output should look like the figure to the right. If that does not happen, there must be a problem in your wiring. Turn off the power supply and locate the problem. A-18 Go to Project > Build All. You should not get any red errors. If you do, then there is a coding error that needs to be corrected. Go back to 13 and check your code. A-19 Go to Debugger > Program. This will upload the program to the microcontroller. This can also be achieved by pressing button 1 highlighted below. A-20 Run the program by going to Debugger > Run. This can also be achieved by pressing button 2 highlighted below. The Red and Green LEDs should now be flashing in pattern. Have your TA sign off on your lab. A-21 Stop the program by pressing button 3 highlighted below. NOTE: You must always follow this pattern when trying new code: STOP > SAVE > BUILD ALL > PROGRAM > RUN A-22 Modify the code so that all for statements look like this. for(count = 1; count < 500000; count++); STOP > SAVE > BUILD ALL > PROGRAM > RUN A-23 Explain in your own words what is happening.B. Accepting Inputs B-1 Add the circuit shown to the right. Remember to always turn the power supply off before making changes to your circuit. Follow the WWAARRNNIINNGG!! Box. Note that the push button only fits in the board in one direction. If you improperly install the pins, the push button will not work. B-2 You will now modify your code to accept inputs. #include <p18cxxx.h> #pragma config WDT=OFF long int count; void main() { TRISD = 0b00000100; //Set Pin 2 of Port D to be an input //the rest are set to be outputs //TRISD = 0x04; this would also work while(1) { if (PORTDbits.RD2) //if Pin2 is high (switch open) { PORTDbits.RD0 = 1; } else //if Pin2 is low (switch closed) { PORTDbits.RD1 = 1; } for(count = 1; count < 40000; count++); PORTDbits.RD1 = 0; //turn off LED1 PORTDbits.RD0 = 0; //turn off LED2 for(count = 1;


View Full Document

MSU ECE 480 - Introduction to the PIC18F4520

Documents in this Course
ganttv1

ganttv1

6 pages

sd97

sd97

17 pages

ap_EO

ap_EO

14 pages

Load more
Download Introduction to the PIC18F4520
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to the PIC18F4520 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Introduction to the PIC18F4520 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?