Kulliyyah of engineering department of electrical and computer engineering



Download 23.82 Kb.
Date13.06.2017
Size23.82 Kb.
#20409




KULLIYYAH OF ENGINEERING

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING


SEMESTER II 2014/2015

Laboratory Manual
ECE 4102

Computer and Information Engineering Lab II



EXPERIMENT 3

Microcontroller Programming:

Using PIC16F88 Kit-Lights Control using LDR

1. Objectives

To program the PIC16F88 microcontroller for the application of lights control using LDR sensor.



2. Contents

Microcontroller PIC16F88 Kit is designed for training in Microcontroller programming. 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.



Figure 1. Application Circuit of PIC16F88 Kit.


In this experiment, students need to write their own program to control the LEDs lights using the LDR (light dependent resistance) sensor. Thus, we will understand how the microcontroller is used to read analog data from the sensor.

LDR is an optoelectronic sensor, that response to light intensity. The higher the light intensity, the lower the resistance of the LDR. This resistance is converted to voltage by using voltage divider circuit. This voltage signal is then acquired by the microcontroller.



3. Reading data from sensor

PIC16F88 can be used as IC for data acquisition since it has Analog Digital Converter Port, available 6 analog inputs on PORT AN0 to AN6.

MikroC has library to operate ADC function:
1. Adc_Read

This is to start analog port reading.

Command: Adc_Read(No. of channel_analog_port);

2. ADCON1

To activate conversion from analog to digital

Command: ADCON1 = 0; activate ADC on all analog ports
4. Instructions of experiment

Complete the laboratory work as follows (work in group of 2 persons):



  1. Write your own program to control LED lights using LDR following this algorithm:

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

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

  3. Select the analog input port.

  4. Activate ADC in all analiog ports.

  5. Read analog data from LDR

  1. Download the program and show to the instructor your testing result.

  2. Submit the lab report including the program (source code), due one week after laboratory. In your report, explain what the program actually does and describe the scenario.

/* Name of Program: ADC

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

B6_SW1, B7-SW2

A1-Buzzer

A0=LDR


*/

unsigned short input_a0;

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

ANSEL.F0 = 1; //Set A1 as analog input

ADCON1 = 0; //activate ADC on all analog ports

{

do



{

input_a0 = ADC_Read(0); // get analog data from A0

PORTB = input_a0; //binary value PORTB = analog data A0

}

while(1);



}

}


The effect on the light intensity can be seen in LED lights in PORT B0 to B5. For example: If LEDs are ON in pin RB3, RB2, RB1, RB0.

Binary value is: 00001111



PORTB

=

RB7

RB6

RB5

RB4

RB3

RB2

RB1

RB0

We can use Qconverter in MikroC: 00001111(binary) is equal to 15 (decimal). This decimal 15 is equivalent to 15/255 x 5 V= 0.29 V.

(Note: that 1111111 (binary)=255(decimal).

That means the output voltage of LDR sensor is 0.29V.





Download 23.82 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page