You are on page 1of 39

INTRODUCTION TO

PIC16F877

Where is the first leg?

Electrical device

A pull-up resistor is a resistor


- connected between a signal conductor and a positive power
supply voltage to ensure that the signal will be a valid logic
level if external devices are disconnected or high-impedance is
introduced

Pull-down resistors work in the same manner as pull-up resistors,


except that they pull the pin to a logical low value. They are
connected between ground and the appropriate pin on a device

Pull up and Pull down Resistor

5V (1.5 2)V
Idng in=
<maximum 20mA
R

Example

Port B is an 8-bit wide, bidirectional port. Bits of the TRISB register determine the
function of its pins

The ANSEL and ANSELH registers are used to configure the input
mode of an I/O pin to analog or digital.

JDM/PG2 Board

USB board

Basic elements that make a PIC works


VCC
J1
VCC5V

1
2

R1
1k

CON2

SW1
PVN1
1
2
3
4
5
6
7

SW_PB_SPST

15
16
17
18
23
24
25
26

C1

13
33p
C2

20Mhz
CRY STAL

14
12
31

33p

MCLR*/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS*/C2OUT
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT

RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7

OSC1/CLKIN
RE0/RD*/AN5
RE1/WR*/AN6
RE2/CS*/AN7

33
34
35
36
37
38
39
40
19
20
21
22
27
28
29
30
8
9
10
VCC5V

OSC2/CLKOUT
VSS
VSS

VDD
VDD
PIC16F877A

11
32

CCS Programing

Addition Operator

+=

Addition assignment operator, x+=y, is the same as x=x+y

&=

Bitwise and assignment operator, x&=y, is the same as x=x&y

&

Address operator

&

Bitwise and operator

^=

Bitwise exclusive or assignment operator, x^=y, is the same as x=x^y

Bitwise exclusive or operator

l=

Bitwise inclusive or assignment operator, xl=y, is the same as x=xly

Bitwise inclusive or operator

?:

Conditional Expression operator

--

Decrement

/=

Division assignment operator, x/=y, is the same as x=x/y

Division operator

==

Equality

>

Greater than operator

>=

Greater than or equal to operator

++

Increment

Indirection operator

!=

Inequality

<<=

Left shift assignment operator, x<<=y, is the same as x=x<<y

<

Less than operator

<<

Left Shift operator

<=

Less than or equal to operator

&&

Logical AND operator

Logical negation operator

ll

Logical OR operator

%=

Modules assignment operator x%=y, is the same as x=x%y

Modules operator

*=

Multiplication assignment operator, x*=y, is the same as x=x*y

Multiplication operator

One's complement operator

>>=

Right shift assignment, x>>=y, is the same as x=x>>y

>>

Right shift operator

->

Structure Pointer operation

-=

Subtraction assignment operator

Subtraction operator

sizeof

Determines size in bytes of operand

PIC16F877 I/O Example

VCC

VCC
D2
LED

D1
LED

R2
470
R1
470
SW1

SW_PB_SPST

PVN1
1
2
3
4
5
6
7
15
16
17
18
23
24
25
26

MCLR*/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS*/C2OUT
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT

RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RD4/PSP4
RD5/PSP5
RD6/PSP6
RD7/PSP7

33
34
35
36
37
38
39
40
19
20
21
22
27
28
29
30