* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Experiment 3 - LED Lights Controller
Buck converter wikipedia , lookup
Switched-mode power supply wikipedia , lookup
Scattering parameters wikipedia , lookup
Resistive opto-isolator wikipedia , lookup
Power dividers and directional couplers wikipedia , lookup
Two-port network wikipedia , lookup
Analog-to-digital converter wikipedia , lookup
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): a) Write your own program to control LED lights using LDR following this algorithm: i. Set initial value of PORT that will be used. ii. Define PORT that will be used as input and output. iii. Select the analog input port. iv. Activate ADC in all analiog ports. v. Read analog data from LDR b) Download the program and show to the instructor your testing result. c) 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; TRISB.F1 = 0; TRISB.F2 = 0; TRISB.F3 = 0; TRISB.F4 = 0; TRISB.F5 = 0; //PORT B0 as Output //PORT B1 as Output //PORT B2 as Output //PORT B3 as Output //PORT B4 as Output //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); PORTB = input_a0; } while(1); } } // get analog data from A0 //binary value PORTB = analog data A0 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.