International Islamic University Malaysia



[pic]

[pic]

KULLIYYAH OF ENGINEERING

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

SEMESTER II 2014/2015

Laboratory Manual

ECE 4102

Computer and Information Engineering Lab II

EXPERIMENT 2

Microcontroller Programming:

Using PIC16F88 Kit- Home Security System

1. Objectives

To write a program (source code) and execute the designed program in microcontroller PIC16F88 Kit.

2. Contents

Microcontroller Kit is designed for training in Microcontroller programming. PIC16F88 Microcontroller Kit is used here to design and test the microcontroller programming for students exercise. This Kit consists of Programmer and Application Circuit in one unit. Firstly, the source code program is written according to the desired algorithm. Then students need to download their own programs into the microcontroller. After downloading, the designed program can be executed by microcontroller in Application circuit to test whether the circuit is running as desired or not.

[pic]

Figure 1. Application Circuit of PIC16F88 Kit.

3. Instructions

Complete the laboratory work as follows:

a) Write your own program following this algorithm:

i. Define PORT that will be used as input and output.

ii. Set PORT B6 dan B7 as the digital input reader.

iii. Set initial value of PORT that will be used.

iv. Start the program

v. Set for normal condition: GREEN (port B2) is ON to identify the system is ready.

vi. If any switch is pressed (Switch 1 or Switch 2), then RED (port B0) is blinking and Buzzer is ON for 5s.

vii. Return to normal condition.

b) Download the program to the Kit and test the circuit.

c) Show to the instructor your testing result.

d) Submit the lab report including the program (source code), due one week after laboratory. In your report, give a brief scenario on how this can be used for home security.

/* Name of Program: SECURITY

Connection: LED B0-M, B1-K, B2-H, B3-M, B4-K, B5-H

B6_SW1, B7-SW2

A1-Buzzer

A0=LDR

*/

void main()

{

PORTB = 0; //initial PORTB=0

PORTA = 0; //initial PORTA=0

//SET PORT B as INPUT or OUTPUT

TRISB.F0 = 0; //PORT B0 as Output

TRISB.F1 = 0; //PORT B1 as Output

TRISB.F2 = 0; //PORT B2 as Output

TRISB.F3 = 0; //PORT B3 as Output

TRISB.F4 = 0; //PORT B4 as Output

TRISB.F5 = 0; //PORT B5 as Output

TRISB.F6 = 1; //PORT B6 as input

TRISB.F7 = 1; //PORT B7 as input

//SET PORT A1 as OUTPUT

TRISA.F1 = 0;

//Analog Selection

ANSEL.F5 = 0; //Set AN5 as digital

ANSEL.F6 = 0; //Set AN6 as digital

{

do

{

if((PORTB.F6==1) || (PORTB.F7==1)) //if switch B6 or B7 ON

{

/*then Buzzer ON and RED blinking */

PORTA.F1 = 1; //PORTE Pin A1 High, Buzzer ON

//RED is to blink

PORTB.F0 = 1; //LED Red ON

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(500);

PORTB.F0 = 1; //LED Red ON

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(500);

PORTB.F0 = 1; //LED Red ON

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(500);

PORTB.F0 = 1; //LED Red ON

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(500);

PORTB.F0 = 1; //LED Red ON

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(500);

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(500);

Delay_ms(500);

PORTB.F0 = 1; //LED Red ON

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(500);

Delay_ms(500);

PORTB.F0 = 1; //LED Red ON

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(500);

Delay_ms(500);

PORTB.F0 = 1; //LED Red ON

Delay_ms(500);

PORTB.F0 = 0; //LED Red OFF

Delay_ms(5000); //Buzzer ON for 5 s

}

else

{

PORTB.F2 = 1; //to normal LED Green ON

PORTA.F1 = 0; //Buzzer OFF

}

}

while(1) ;

}

}

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download