Practical 2 - LED and Switch v3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

ELECTRICAL ENGINEERING DEPARTMENT

ACADEMIC SESSION: _____________

DEC40053 – EMBEDDED SYSTEM APPLICATIONS

PRACTICAL WORK 2 : BASIC INPUT OUTPUT PROGRAMMING

PRACTICAL WORK DATE :

LECTURER’S NAME :

CLO/PLO/DK/DP : CLO3/PLO5/DK6/DP1/DP3

TOTAL
STUDENT ID & NAME : MARKS
(100%)

(1)

(2)

(3)

DATE SUBMIT : DATE RETURN :


1 LEARNING OUTCOMES (LO)

1. Construct and simulate real-time embedded system application based on PIC16F/PIC18F


microcontroller effectively.

2 OBJECTIVE

1. Write C program for PIC input and output pin.


2. Draw and simulate PIC input and output circuit in Proteus.
3. Build input and output hardware circuit using switch and LEDs.

3 THEORY

An electrical switch is any device used to interrupt the flow of electrons in a circuit. Switches are
essentially binary devices: they are either completely on ("closed") or completely off ("open"). There
are many different types of switches.

The simplest type of switch is one where two electrical conductors are brought in contact with each other
by the motion of an actuating mechanism. Other switches are more complex, containing electronic
circuits able to turn on or off depending on some physical stimulus (such as light or magnetic field)
sensed. In any case, the final output of any switch will be (at least) a pair of wire- connection terminals
that will either be connected together by the switch's internal contact mechanism ("closed"), or not
connected together ("open").

Push button switches are two-position devices actuated with a button that is pressed and released. Most
push button switches have an internal spring mechanism returning the button to its "out," or "unpressed,"
position, for momentary operation. Some push button switches will latch alternately on or off with every
push of the button. Other push button switches will stay in their "in," or "pressed," position until the
button is pulled back out. This last type of push button switches usually has a mushroom-shaped button
for easy push-pull action.

4 EQUIPMENT / TOOLS

1. Personal Computer (PC)


2. MPLAB IDE integrates with XC8 compiler.
3. Proteus 8 Professional

5 PROCEDURE

To begin, create a folder named P2 on your desktop. Inside the folder, create sub folder CIRCUIT and
REFERENCE. Create a new MPLAB X project named PW2.
5.1 Create a main.c source file named as Lab2a. Copy and paste program given in Appendix A into your coding
window. Modify the void main (void) block with the source code below.

{LATD=0xAF;}
else //SW1 open/not pressed
LATD=0;

Compile your source code.

5.2 Open Proteus 8 Professional. Construct circuit shown below.

Set processor clock frequency to 64 MHz. Load the hex file for this circuit and observe the output.
5.3 Create a main.c source file named as Lab2b. Copy and paste program given in Appendix A into your coding
window. Modify the void main (void) block with the source code below.

/ / SW2 is pressed
/ / Other switch conditions

//Your program end here


Compile your source code.

5.4 Design the circuit for Lab2b program in in Proteus 8. Load the hex file for this circuit and observe the output.

5.5 Create a main.c source file named as Lab2c. Copy and paste program given in Appendix A into your coding
window. Modify the void main (void) block with the source code below.
Compile your source code.

5.6 Design the circuit for Lab2c program in in Proteus 8. Load the hex file for this circuit and observe the output.

5.7 Create a main.c source file named as Lab2d. Copy and paste program given in Appendix A into your coding
window. Modify the void main (void) block with the source code below.
Compile your source code.

5.8 Design the circuit for Lab2d program in in Proteus 8. Load the hex file for this circuit and observe the output.

6 RESULT

7 TASK

Write C program for two switches (SW1 and SW2) to control two LEDs. The operation of both switches and
LEDs are shown in table below. Switches are active low and LEDs are active high.

SW2 SW1 Output


1 1 Both LEDs off
1 0 LED 2 on
0 1 LED 1 on
0 0 Both LEDs on

Select any pins at PIC for input and output pins.


Logic ‘0’ - SW is pressed
Logic ‘1’ - SW is not pressed

8 CONCLUSION
Appendix A

#include <xc.h>
#define _XTAL_FREQ 64000000L

void setup(void);
void delay(unsigned int x);

void main (void)


{
setup();
//Your program start here

}
//Your program end here

/*
BAHAGIAN INI JANGAN KACAU :)
*/
void setup(void)
{

ANSELA = 0b00000000;
ANSELB = 0b00000000;
ANSELC = 0b00000000;
ANSELD = 0b00000000;
ANSELE = 0b00000000;
VREFCON0 = 0b10110000; // Fixed Voltage Reference is enabled, x4 (4.096V)
ADCON1 = 0b00110000; //0b00110000=4.096V 0b00100000=2.048V 0b00000000=Vdd
ADCON2 = 0b10000011;

LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
LATD = 0x00;
LATE = 0x00;
}

void delay(unsigned int x)


{
for(;x>0;x--)__delay_ms(1);
}

static void interrupt ISR(void)


{
}
PRACTICAL WORK ASSESSMENT FORM

DEC40053 – EMBEDDED SYSTEM APPLICATIONS

Student Name: Practical Work:

Registration No: Date:

Class: Lecturer’s Name:

1. PRACTICAL WORK ASSESSMENT - 100%

a) Practical Skill Assessment - 70%

b) Practical Report Assessment - 30%

Practical Skill Assessment


/ 70

Practical Report Assessment


/ 30

Total marks
/ 100
Practical Skill Rubric

Skill Excellent Very Good Good Fair Poor Weight Marks


5 4 3 2 1
Ability to Able to write and run Able to write and Able to write and run Able to write and run Unable to run 4
write/run/debug program correctly without run program correctly program correctly with program but have more program.
C program in any logical error. with one logical two logical errors. than two logical errors.
MPLAB X. error.

Ability to The simulation displays The simulation The simulation displays The simulation does not The simulation 3
construct and results very clearly and displays results clearly results clearly and meets display results clearly or does not display
simulate PIC18 intuitively, and meets all and meets most of the many of the display does not meet most results correctly
circuit in display specifications. display specifications. specifications. display specifications. and does not meet
Proteus. most display
specifications.
PIC18 hardware Circuit is fully functional. Circuit is 90% Circuit is 80% Circuit is 70% Circuit cannot 2
circuit functional. functional. functional. function.
Troubleshooting Student was able to Student with a little Student needed a Student needed a large Student was not 2
logically determine a direction was able to moderate amount of amount of direction in able to determine a
method of finding employ critical help to determine a path order to locate the plan to logically
problems. thinking to locate the to find the problems. problems. find the problems.
problems.
Level of Needed Student was able to Student was able to Student was able to Student was unable to Student was unable 1
Assistance complete the task without complete the task with complete the task with complete task without to complete task
assistance. little assistance. moderate assistance. major assistance. with assistance.
Demonstrated Student is able to identify Student is able to Student is able to Student is able to Student cannot 1
Knowledge of and describe necessary identify and describe identify and describe identify and describe identify and
Theory theories for completion of necessary theories for necessary theories for necessary theories for describe necessary
the project. completion of the completion of the completion of the theories for
project with minor project with moderate project with major completion of the
assistance. assistance. assistance. project
Time Routinely used time well Used time fairly well Procrastinated Was unable to Student showed no 1
Management throughout the project to throughout the project. somewhat but did get adequately meet timeline interest in
get the job done on time. the job done on time. due to lack of interest. completing project
on time.
Practical Skill Total Marks
Lab2a

Items Marks Lecturer Sign Lecturer name

1) MPLAB X 5

2) Proteus 5

3) PIC18 Hardware -

4) Circuit observation [5 marks]


Lab2b

Items Marks Lecturer Sign Lecturer name

1) MPLAB X 5

2) Proteus 5

3) PIC18 Hardware -

4) Circuit observation [5 marks]


Lab2c

Items Marks Lecturer Sign Lecturer name

1) MPLAB X 5

2) Proteus 5

3) PIC18 Hardware -

4) Circuit observation [5 marks]


Lab2d

Items Marks Lecturer Sign Lecturer name

1) MPLAB X 5

2) Proteus 5

3) PIC18 Hardware -

4) Circuit observation [5 marks]


Task

Items Marks Lecturer Sign Lecturer name

1) MPLAB X 5

2) Proteus 5

3) PIC18 Hardware -

4) Circuit observation [5 marks]

5) Sketch your circuit [5 marks]

You might also like