Computer Systems Architecture Lab Manual: CSEN601 Spring 2006
Computer Systems Architecture Lab Manual: CSEN601 Spring 2006
Spring 2006
In this lab the main Micro Controller Unit (MCU) that will be used is PIC 16F877/16F877A.
The pin outs of the 16F877 will be discussed in the lab; Figure 1.2 briefly summarizes the function of each
of the port pins. Note that, in many cases, the port pins can serve more than one purpose.
Pin(s) Function:-
Pin 1: RESET, this is the reset pin of the PIC 16F877, it is ACTIVE LOW, that means whenever you want
to reset the PIC, you should give a LOW signal on this pin to restart your program.
Pins 1–7: Port A. The pins on this port may be used for digital input and output, as well as analog to digital
conversion (except for RA4).
Pin 8-10: Port E. The pins on this port may be used for digital input and output, as well as analog to digital
conversion.
Pin 15–18 & 23-26: Port C. The pins on this port may be used for digital input and output. Also RC1 &
RC2 can be used for PWM [Pulse Width Modulation], RC6 & RC7 for serial communication
Pin 19–22 & 27-30: Port D. The pins on this port may be used for digital input and output.
Pins 33–40: Port B. The pins on this port may be used for digital input and output, also has some week pull
up resistances that can be enabled from your program.
Note: Please always refer back to the PIC datasheet from Microchip.
The process of starting any microcontroller is a non-trivial one. The underlying hardware is complex and a
small, manufacturer-defined, ‘reset routine’ must be run to place this hardware into an appropriate state
before it can begin executing the user program. Running this reset routine takes time, and requires that the
microcontroller’s oscillator is operating.
Where your system is supplied by a robust power supply, which rapidly reaches its specified output voltage
when switched on, rapidly decreases to 0V when switched off, and – while switched on – cannot ‘brown
out’ (drop in voltage), then you can safely use low-cost reset hardware based on a capacitor and a resistor to
ensure that your system will be reset correctly. Figure 1.3 illustrates the basic connection of the PIC16F877
and a simple reset circuit.
Vcc
1K
1 40
2 39
3 38
4 37
5 36
6 35
7 34
8 33
PIC16F877
9 32
Vcc
10 31 Gnd
Vcc 11 30
22pF Gnd 12 29
13 28
14 27
4MHz
15 26
16 25
22pF 17 24
18 23
19 22
20 21
Abstract:-
Introduce the PIC to the students through practical experience of writing on each pin of one
of the ports of the PIC and write values to them. Students should be able to access each pin and also access
the whole port.
Circuit diagram:-
Vcc
1K
1 40
2 39
3 38
4 37
5 36
6 35
7 34
8 33
PIC16F877
9 32
Vcc
10 31 Gnd
Vcc 11 30
22pF Gnd 12 29
13 28
14 27
4MHz
15 26
16 25
22pF 17 24
18 23
19 22
20 21
Initialize
!"#
$ % &
'!
(
% ) * &
*+
, --
$ % &
, --
$ % &
(
(
Abstract:-
Experiment how to let the PIC microcontroller respond to input and observe the result by connecting
LEDs on another port.
Circuit diagram:-
Vcc
1K
1 40
2 39
3 38 PORTB
4 37
5 36
6 35
Vcc 1K 7 34
1K 8 33
PIC16F877
PORTE 1K 9 32
Vcc
10 31 Gnd
Vcc 11 30
22pF Gnd 12 29
13 28
14 27
4MHz
15 26
16 25
22pF 17 24
18 23
19 22
20 21
*%+
% )) %
. , #
. ,
. ,
. ! ,
(
. #
. , ,
.
. ! ,
(
. ! #
. , ,
. ,
. !
(
(
Notes:
#What happens if the program sets the working bit only and not the other PORTB
pins? Example:
/
. , # . , (
. # . (
. ! # . ! (
/
!#What’s wrong with this code? What happens if you press more that one button at
the same time?
Circuit diagram:-
+5v
Vcc
M +9v
1K Relay
330ohm
1 40
2 39
2N2222
3 38
4 37
Vcc 5 36
6 35
1K 7 34
8 33
PIC16F877
9 32
Vcc
10 31 Gnd
Vcc 11 30
22pF Gnd 12 29
13 28
14 27
4MHz
15 26
16 25
22pF 17 24
18 23
19 22
20 21
#
#
0 % )1
. , #
. 2
(
. ,
(
Notes:
1) What if you want to control the direction of the motor? What would you do?
What component(s) will be added to the circuit and how will it/they be
connected? Hint: check the relay terminals and connections.
2) What happens if we removed the ‘else’ from the program? How will this
affect the behavior of the circuit?
Abstract:-
Introduce the usage of sensors with the PIC microcontroller. While sometimes sensors give an
analog output that has to be used with an analog to digital converter, here we’ll learn a simple trick of using
a simple transistor and a potentiometer (variable resistance) to output a digital output to the PIC from the
sensor. Adjusting the potentiometer controls the “sensitivity” of the sensor that’s connected to the transistor
based on the simple rule of voltage divider.
Circuit diagram:-
+5v
Vcc
M +9v
10K Relay
330ohm
1 40
2
2N2222
39
3 38
Vcc Vcc 4 37
5 36
6
LDR 10K
35
7 34
330 8 33
PIC16F877
10k 9 32
Vcc
2N2222
pot 10 31 Gnd
Vcc 11 30
22pF Gnd 12 29
13 28
14 27
4MHz
15 26
16 25
22pF 17 24
18 23
19 22
20 21
#
#
0 % + 1
. , #
. 2
(
. ,
(
(
Notes:
How about using two sensors and mounting your circuit at the bottom of a
robot, two sensors each on one side of a drawn white line on a black floor (or vice
versa, black line on a white floor), and by implementing the right code, your robot
will be able to follow this line.
More flexible than PROMs and once very common, UV EPROMs now seem rather primitive compared
with EEPROMs (see below). They can be useful for prototyping but are prohibitively expensive for use in
production.
Many older members of the 8051 family are available with on-board UV EPROM.