PW 4
PW 4
PW 4
(1)
(2)
(3)
2 /100
3 /100
PRACTICAL SKILL ASSESSMENT RUBRIC - CLO 3:
Construct and simulate real-time embedded system application based on PIC16F/PIC18F microcontroller effectively. (P4,
PLO5)
SCORE weight Score
NO CRITERIA
1 2 3 4 5 S1 S2 S3
Program code The program The program code The program The program
is incomplete code is is complete with a code is complete code is
with complete with little inconsistence with a little complete
inconsistent some code typing and inconsistent code and well
code typing inconsistence well organized typing and well organized.
1. Write
and not well code typing and after being organized with a X4
program organized well organized assisted by minimum assist
after being after being lecturer by lecturer
assisted by assisted by
lecturer lecturer
The program The program The program code The program The program
code still have code have three have three or code have one code
an error. or more error. more error. or two error. successfully
Compile and Student Student can Student can fixed Student can run
2. execute cannot fixed
the error after
fixed the error
after being
the error with a
minimum assist by
fixed the error
with a minimum
X4
program being assisted assisted by lecturer assist by lecturer
by lecturer. lecturer.
TOTAL
/80 /80 /80
MARKS
No Activity Observation Marks
Task Result
1 Program /5
Circuit /5
2 Discussion /5
3 Conclusion /5
Total /20
1 LEARNING OUTCOMES (LO):
2 OBJECTIVE
3 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. All three hardware interrupts are direct
to vector table location at 0008H memory.
These interrupts are edge triggered interrupts i.e. triggered by either rising edge
or by falling edge. The edge trigger bit is present in an INTCON2 register.
INTCON
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 SAFETY OPERATING PROCEDURE (SOP)
This is a partial list of basic safety precautions to use when working on a
computer:
Keep food and drinks out of your workspace.
Keep your workspace clean and free of clutter.
Remove your watch and jewelry and secure loose clothing.
Make sure the computer equipment is plug in and turn ON the power
switch.
Never unplug a power supply while the equipment working.
Do not touch areas at hot or that use a high voltage.
Know where the fire extinguisher is located and how to use it.
Bend your knees when lifting heavy objects to avoid injuring your back.
Follow electrical safety guidelines to prevent electrical fires, injuries, and
fatalities in the workplace. Power supplies and monitors contain a high
voltage.
CAUTION
Do not repairing power supplies or monitors if broken. Only experienced
technicians should attempt to repair power supplies and monitors.
6.0 PROCEDURE
6.1 PART A : External Interrupt
To begin, create a subfolder named PW4 on your DEC40053 folder. Create a
new PROTEUS project named PW4A and save it in the PW4 folder. Select
PIC18F4550 and MPLAB XC8 compiler in Firmware.
6.2 Write the given program code below into your source code file and then click on
build project button until successful. If any error occurs, fix it. Show your
programs that have successfully build to your lecturer.
#include <xc.h>
#define _XTAL_FREQ 4000000
void main(void)
{
TRISB=0b00000011; // Set RB0 & RB1 as Input Pin
ADCON1=0x0E; //Set analog port to digital port
INT0IF = 0; //Reset the External Interrupt Flag
INTEDG0 = 1; //Interrupt on the Rising Edge
INT0IE = 1; //Enable the External Interrupt
GIE = 1; //Set the Global Interrupt Enable
while (1){
LB6=1;
__delay_ms(500);
LB6=0;
__delay_ms(500);
}
}
void interrupt isr()
{
INT0IF = 0; //reset the interrupt flag
LB7 = ~LB7; //flip the bit
}
Code1: Coding for External interrupt INT0
RUN Simulation, Press and Release push button SW1. Observe the output.
Modify code 1 above, change interrupt source from INT0 to INT1 and maintain
the others operation. than build the program until successful. If any error occurs,
fix it. Press and Release push button SW2. Show your result to your lecture.
Save As your project with PW4B file name. Modified the schematic diagram
shown below.
T0CON = 0 1 1 0 1 0 0 0
6.5
Show your programs that have successfully build to your lecturer. RUN
simulation code 2, Press and Release SW1 four (4) time.
#include <xc.h>
#define _XTAL_FREQ 4000000
void main(void) {
TRISA4 = ; //Set RA4 as input pin
TRISB = ; //Set PORTB as Output
ADCON1 = 0x ; //Set Analog Port to Digital Port
T0CON = 0b ; //Value T0CON in Binary
TMR0L = 252;
GIE = ; //Set the Global Interrupt Enable
TMR0IE = ; //Enable external interrupt
TMR0IP = ; //Enable interrupt priority bit
TMR0IF = ; //Reset the external interrupt flag
while (1) {
LB6=1;
__delay_ms(500);
LB6=0;
__delay_ms(500);
}
}
6.6 Modify code 2 above, change the counting numbers from FOUR (4) to SEVEN (7)
and maintain the others operation. RUN Simulation, Press and Release push
button SW1 SEVEN (7) times. Show your result to your lecture.
7 TASK
TASK 1
ABC Company Sdn. Bhd has assigned by Majlis Perbandaran Kota Bharu to
install a traffic lights systems at the busiest traffic Jalan Kuala Krai - Kota Bharu.
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 LED for vehicles (red, yellow and green) and active HIGH LED for
pedestrians (green and red).
(b) Push button must be connected to RA4 while LED are connected to
PORTD.
(c) To cross the road, pedestrian has to press the push button that is
programmed as timer interrupt. The systems will function as normal after
the interrupt.
MAIN ROAD
U1
R1 2
RA0/AN0 RC0/T1OSO/T1CKI
15
10k 3 16
RA1/AN1 RC1/T1OSI/CCP2/UOE
4 17
RA2/AN2/VREF-/CVREF RC2/CCP1/P1A
5 23
RA3/AN3/VREF+ RC4/D-/VM
6 24
RA4/T0CKI/C1OUT/RCV RC5/D+/VP
7 25
RA5/AN4/SS/LVDIN/C2OUT RC6/TX/CK
14 26
RA6/OSC2/CLKO RC7/RX/DT/SDO
13
OSC1/CLKI
SWITCH 33 19
RB0/AN12/INT0/FLT0/SDI/SDA RD0/SPP0
34 20
RB1/AN10/INT1/SCK/SCL RD1/SPP1
35 21
RB2/AN8/INT2/VMO RD2/SPP2
36 22
RB3/AN9/CCP2/VPO RD3/SPP3
37 27
RB4/AN11/KBI0/CSSPP RD4/SPP4
38 28
RB5/KBI1/PGM RD5/SPP5/P1B
39 29
RB6/KBI2/PGC RD6/SPP6/P1C
40 30
RB7/KBI3/PGD RD7/SPP7/P1D
8 ZEBRA CROSSING
RE0/AN5/CK1SPP
9
RE1/AN6/CK2SPP
10
RE2/AN7/OESPP
18 1
VUSB RE3/MCLR/VPP
PIC18F4550
VDD
R4
10k
TASK RESULT
8
9 DISCUSSION
10 CONCLUSION