of 25
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
1/25
Digital Outputs
Light Emitting Diodes (LEDs)
Updated 2007
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
2/25
CCS C Instructions for I/O Pins output_low (pin): Sets a given pin to the ground state. output_high (pin): Sets a given pin to the high state. output_toggle(pin): Toggles the high/low state of the specified pin. output_bit (pin, value): Outputs the specified value (0 or 1) to the specified
I/O pin.
output_X (value): Output an entire byte to a port. output_float (pin): Sets the specified pin to the input mode. output_drive(pin): Sets the specified pin to the output mode.
value = input (pin): Returns the state of the indicated pin. value = input_X(): Inputs an entire byte from a port.
port_b_pullups (value):Sets the port B input pullups.
value = get_tris_X(): Returns the value of the TRIS register of port X. set_tris_X (value): Allow the I/O port direction (TRI-State) registers to
be set.
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
3/25
LEDs in Real Life
Televisions
VCRs
Disk drives
Printers Alarm system control panels
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
4/25
On/Off Control withPIC16F877A
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
5/25
PIC
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
6/25
Cable Wiring
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
7/25
ElectronicSc
hema
R202
330
VCC
2.LEDB
LOCK
D201
D205
C102
20pF
1.P
ICBLOCK
R203
330
J20
1
9
1011
12
13
14
15
16
1
23
4
5
6
7
8
R208
330
R201
330
SW
7
D202
R205
330
D
207
R206
330
D203
R204
330
R101
100
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREFRA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
VDD
OSC1/CLKI
OSC2/CLKO
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK
RC7/RX/DT
VDD
RB0/INT
RB1
RB2RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
1
2
3
45
6
7
8
9
10
11
13
14
15
16
17
18
19
23
24
25
26
32
33
34
3536
37
38
39
40
D204
D206
R207
330
D208
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
8/25
Manual vs. Using a Microcontroller
There are two big differences between
changing the connection manually andhaving a microcontroller do it
First, the microcontroller doesnt have to cut
the power when it changes the LED circuitssupply from Vdd to Vss
Second, while a human can make that
change several times a minute, themicrocontroller can do it thousands of timesper second!
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
9/25
On/Off LED
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
10/25
Exercise
Make the LED blink on and off once every
three seconds, with the low time twice aslong as the high time
Move on the next slide to compare to what
you have done
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
11/25
Solution
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
12/25
Exercise
Make the LED blink 500 milliseconds on and
off 10 times
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
13/25
Solution
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
14/25
Example: 8 Bits Counting
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
15/25
Problem Description
Develop a program to count from 0 to 255
and light up 8 LEDs of the PIC developmentboard according to the binary equivalent ofthe counted decimal number
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
16/25
Electro
nicSc
hema
VCC
C102
20pF
R201
330
D
207
D201
D206
R205
330
R203
330
R
204
330
1.P
ICBLOCK S
W7
D205
J20
1
9
1011
12
13
14
15
16
1
23
4
5
6
7
8
2.LEDB
LOCK
R208
330
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VREF-/CVREF
RA3/AN3/VREF+
RA4/T0CKI/C1OUT
RA5/AN4/SS/C2OUT
RE0/RD/AN5
RE1/WR/AN6
RE2/CS/AN7
VDD
OSC1/CLKI
OSC2/CLKO
RC0/T1OSO/T1CKI
RC1/T1OSI/CCP2
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RC4/SDI/SDARC5/SDO
RC6/TX/CK
RC7/RX/DT
VDD
RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD
1
2
3
4
5
6
7
8
9
10
11
13
14
15
16
17
18
19
20
2324
25
26
32
33
34
35
36
37
38
39
40
R207
330
R101
100
D208
D202
D203
R206
330
R202
330
D20
4
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
17/25
Cable Wiring
Use a 8 pin ribbon cable to connect PICs
jumpers B0 B7 to LEDs jumpers L0 L7
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
18/25
C Program
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
19/25
Exercise
Develop a program to cause an array of 8
LEDs to light up one at a time from left toright
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
20/25
Solution
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
21/25
Exercise
Develop a program to cause an array of 8
LEDs to light up one at a time from left toright, then right to left
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
22/25
Solution
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
23/25
Lessons Learnt
User requirements drive our code
No duplication code
One task, one function (Modularization)
Use parameters whenever its possible
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
24/25
Exercise
Develop programs to control the blink of eight
LEDs according to the following patterns Pattern 0:
Pattern 1:
Pattern 2:
Pattern 3:
8/3/2019 03a Digital Ouput- Digital Ouputs - Light Emitting Diodes
25/25
References
Microcontroller.
http://www.electronics.netmyne.com/microcontroller.html
PIC Circuits Gallery LED flasher.
http://www.interq.or.jp/japan/se-inoue/e_pic6_1.htm
What's a Microcontroller Student Guide v 2.2.
Parallax 2004