Professional Documents
Culture Documents
PRACTICAL WORK
DATE :
LECTURER’S NAME:
GROUP NO. :
TOTAL
STUDENT ID & NAME : MARKS
(100%)
(1)
(2)
(3)
2 OBJECTIVE
3 THEORY
C. THEORY
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.
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
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.
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.
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.
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
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