You are on page 1of 9

ELECTRICAL ENGINEERING DEPARTMENT

ACADEMIC SESSION: OKTOBER 2020


BEU30063-MICROPROCESSOR AND MICROCONTROLLER

PRACTICAL WORK 4 : INTERRUPT PROGRAMMING IN PIC

PRACTICAL WORK
DATE :

LECTURER’S NAME:

GROUP NO. :
TOTAL
STUDENT ID & NAME : MARKS
(100%)

(1)

(2)

(3)

DATE SUBMIT : DATE RETURN :


1 LEARNING OUTCOMES (LO):

1. Demonstrate microcontroller-based system using PIC


microcontroller for microcontroller application and simulation
using appropriate software( P5 , PLO 5 )

2 OBJECTIVE

At the end of the practical session, student should be able to:


i. Write C program to enable interrupt in PIC18F
ii. Modify a program based on the given problem.

3 THEORY

C. THEORY

External Interrupts INT0, INT1 and INT2

The PIC18 has three external hardware interrupts. Pins RB0, RB1,
and RB2, designated as INT0, INT1, and INT2 respectively, are used as
external hardware interrupts. See Figure 4-1. Upon activation of these pins,
the PIC18 gets interrupted in whatever it is doing and jumps to the interrupt
vector to perform the Interrupt Service Routine.

Figure 4-1: External Hardware


Interrupt Pins

External interrupts on the RB0/INT0, RB1/INT1 and RB2/INT2 pins are edge-
triggered. If the corresponding INTEDGx bit in the INTCON2 register is set (=
1), the interrupt is triggered by a rising edge; if the bit is clear, the trigger is on
the falling edge. When a valid edge appears on the RBx/INTx pin, the
corresponding flag bit, INTxF, is set. This interrupt can be disabled by
clearing the corresponding enable bit, INTxE. Flag bit, INTxF, must be
cleared by software in the Interrupt Service Routine before re-enabling the
interrupt.

All external interrupts (INT0, INT1 and INT2) can wakeup the processor from
Idle or Sleep modes if bit INTxE was set prior to going into those modes. If the
Global Interrupt Enable bit, GIE/GIEH, is set, the processor will branch to the
interrupt vector following wake-up. Interrupt priority for INT1 and INT2 is
determined by the value contained in the interrupt priority bits, INT1IP and
INT2IP of the INTCON3 register. There is no priority bit associated with INT0. It
is always a high priority interrupt source.
TMR0 Interrupt

In 8-bit mode (which is the default), an overflow in the TMR0 register (FFh -->
00h) will set flag bit, TMR0IF. In 16-bit mode, an overflow in the
TMR0H:TMR0L register pair (FFFFh ---> 0000h) will set TMR0IF. The interrupt can
be enabled/disabled by setting/clearing enable bit, TMR0IE of the INTCON register.
Interrupt priority for Timer0 is determined by the value contained in the interrupt
priority bit, TMR0IP of the INTCON2 register.

4 EQUIPMENT / TOOLS

1. PC installed software:
a. MPLAB IDE integrates with XC8 compiler.
b. PROTEUS 8 Professional

5 PROCEDURE

PART A : External Interrupt

1. Draw the schematic diagram shown in figure 1 using ISIS 8 Professional.

Figure 1 : schematic diagram


2. Create a new project file for PIC18 with following setting:
i. Set a project name as PRAC_4

ii. Add a new file to project, set a source file name as TaskA.c

Write the given program below into your source file and than build the
program until successful. If any error occurs, fix it.
Show your programs that have successfully build to your lecturer.

Code1: Coding for External interrupt INT0

a. Simulate code 1 using Proteus 8, Press and Release push button SW1

Observation:
b. Load code 1 into Your Board, Press and Release push button PB1
Observation:

3. Modify code 1 above, change interrupt source from INT0 to INT1 and
maintain the others operation.

Simulate your code using Proteus 8, Press and Release push button SW2.
Show your result to your lecture.

Load your code into Your Board, Press and Release push button PB2.
Show your result to your lecture.

TASK B: TIMER 0 INTERRUPT

4. Draw the schematic diagram shown in figure 2 using ISIS 8 Professional

Figure 2 : Schematic Diagram


5. Create a new project file for PIC18F45K22 with following setting:
i. Set a project name as PRAC_4
ii. Add a new file to project, set a source file name as TaskB.c

Refer to T0CON Register and Figure 4.2, complete the given program
below. Rewrite this code into your source file and than build the program
until successful. If any error occurs, fix it.

 Setting Timer0 are:


 Timer0 is ON;
 8-bit Mode;
 Transition on T0CKI pin;
 Increment on low-to-high transition on T0CKI pin;
 Timer0 clock input bypasses prescaler.

Show your programs that have successfully build to your lecturer.

a. Simulate code 2 using Proteus 8, Press and Release SW1 four (4) time.

b. Simulate code 2 using Proteus 8, Press and Release SW1 four (4) time.

Observation:

1. Load code 2 into Your Board, Press and Release push button PB1 four (4)
time
Observation:
Code 2: Event Counter Interrupt

6. Modify code 2 above, change the counting numbers from FOUR (4) to
SEVEN (7) and maintain the others operation.

a. Simulate your code using Proteus 8, Press and Release push button SW1
SEVEN (7) times. Show your result to your lecture.
b. Load your code into Your Board, Press and Release push button PB1
SEVEN (7) times. Show your result to your lecture.
6 RESULT

7 DISCUSSION/TASK

TASK 1

A security door is attached to a sensor switch (active LOW) which is connected


to RB0/INT0 and a buzzer (active HIGH) is connected to RD7. Design a control
system, so that every time the door is opened, the buzzer beeps twice. Apply
interrupt programming for this system. Set the interrupt to be triggered on rising
edge.

TASK 2
ABC Company Sdn. Bhd has assigned by Majlis Perbandaran Kuantan to install
a traffic lights systems at the busiest traffic Jalan Mahkota Kuantan. As a
technical support, you are responsible to design the system for pedestrian to
cross the road. The specifications are given by the engineer as below:
(a) Use PIC18F4550 Microcontroller, an active LOW push button, an active
HIGH buzzer, active HIGH LED for vehicles (red, yellow and green)
and active HIGH LED for pedestrians (green and red).
(b) Push button must be connected to RB1/INT1 while LED and buzzer are
connected to PORTD.
(c) To cross the road, pedestrian has to press the push button that is
programmed as external hardware interrupt. The systems will function as
normal after the interrupt.

8 CONCLUSION

You might also like