Pic 18 Clang u Gage Tutorial
-
Upload
patrick-kane -
Category
Documents
-
view
240 -
download
0
Transcript of Pic 18 Clang u Gage Tutorial
-
7/31/2019 Pic 18 Clang u Gage Tutorial
1/11
A Tutorial on PIC18F Based Hardwar Design Using C Programming Language+
Shant Dilanian, Yumin L and Rajan Chandra
The objective of this tutorial is to use the PIC18F2221 Microcontroller and Microchip
development tools to design and implement a simple project. Specifically we develop C-code
in order to flash the LED is connected to the least significant bits of PORT B, RB0 (See Figure
1)U1
PIC18F4221
MCLR/Vpp/RE31
RA0/AN02
RA1/AN13
RA2/AN2/Vref-/Cap1/Indx4
RA3/AN3/Vref+/Cap2/QEA5
RA4/AN4/Cap3/QEB6
RA5/AN5/LVDIN7
RE0/AN68
RE1/AN79
RE2/AN810
AVdd11
AVss12
OSC1/CLKI/RA713
OSC2/CLKO/RA6
14
RC0/T1OSO/T1CKI15
RC1/T1OSI/CCP2/FLTA16
RC2/CCP1/FLTB17
RC3/T0CKI/T5CKI/INT018
RD0/T0CKI/T5CKI19
RD1/SDO20
RB7/KBI3/PGD40
RB6/KBI2/PGC39
RB5/KBI1/PWM4/PGM38
PB4/KBIO/PWM537
RB3/PWM336
RB2/PWM235
RB1/PWM134
RB0/PWM033
Vdd32
Vss31
RD7/PWM730
RD6/PWM629
RD5/PWM528
RD4/FLTA
27
RC7/RX/DT/SDO26
RC6/TX/CK/SS25
RC5/INT2/SCK/SCL24
RC4/INT1/SDI/SDA23
RD3/SCK/SCL22
RD2/SDI/SDA21
D1
LED
R1
1k
0
C2
.16uF
V1
5Vdc
0
C3
.16uF
V25Vdc
0
Figure 1
The development tools used in this tutorial are
MPLAB-C18-Academic-v3_30.exe and PICKIt2 Programmer
+ This hand out is a modified version of the original version that was first created by Dr. Sacco.
-
7/31/2019 Pic 18 Clang u Gage Tutorial
2/11
Start Microchips MPLAB IDE
From File Select New
Enter your C source program and save it
in the project directory
-
7/31/2019 Pic 18 Clang u Gage Tutorial
3/11
//LED Flashing Program to be saved as ADC.C
#include
#pragma config OSC = INTIO2
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOR = OFF
void delay();
void main (void)
{TRISB=0x00;
while(1)
{
unsigned char i;
unsigned char j;
PORTB=0x00;
delay();
PORTB=0x01;
delay();
}
}
void delay(){
unsigned char i, j;
for(i=0; i
-
7/31/2019 Pic 18 Clang u Gage Tutorial
4/11
From Projectselect ProjectWizard
Click Next
Select the device(Please Select 18F4221
instead)
Click Next
Select Microchips C18 Toolsuite
Click Next
-
7/31/2019 Pic 18 Clang u Gage Tutorial
5/11
Click Browse
Browse to the folder where you want your
project to be saved and give it a name
(Here it is called C1)
Click Save
Click Next
-
7/31/2019 Pic 18 Clang u Gage Tutorial
6/11
Add the header, library, linker,
and source files to the project .
Click Next (Please select
p18F4221.h, p18f4221.lib and
p18f4221.lkr files instead)
Click Finish
-
7/31/2019 Pic 18 Clang u Gage Tutorial
7/11
From Projectselect Build Options /
Project (In your work, you will see
p18f4221 files)
Select Include Search Path
Click Newand browse to:
Header directory
Within MCC18 directory
-
7/31/2019 Pic 18 Clang u Gage Tutorial
8/11
Select Library Search Path
Click Newand browse to:
Library directory
Within MCC18 directory
Select Linker Script Search Path
Click Newand browse to:
Linker directory
Within MCC18 directory
Click OK
-
7/31/2019 Pic 18 Clang u Gage Tutorial
9/11
FromProgrammer
/Select Programmer
selectPICKit2
Click Build Allicon
Click Program the target
device icon
-
7/31/2019 Pic 18 Clang u Gage Tutorial
10/11
click Bring target MCLR to
Vdd
The picture shown below shows the flashing LED:
PS: In the next page please see the connection details between the PICKIT2 and the
breadboard.
-
7/31/2019 Pic 18 Clang u Gage Tutorial
11/11
PS: Shown below are the connection details between the PICKIT2 and the breadboard.