Professional Documents
Culture Documents
Technical Clarification /Suggestion : Technical Support Division, Vi Microsystems Pvt. Ltd., Plot No :75,Electronics Estate, Perungudi,Chennai - 600 096,INDIA. Ph: 91- 44-2496 1842, 91-44-2496 1852 Mail : service@vimicrosystems.com, Web : www.vimicrosystems.com
1 Vi Microsystems Pvt.Ltd..
CONTENTS
INTRODUCTION
LIST OF EXPERIMENTS 1.VOLTAGE MEASUREMENT 2.WATER PUMP CONTROLLER 3.DIGITAL CLOCK 4.TEMPERATURE MEASUREMENT 5.PC COMMUNICATION 6.RF TRANSMITER AND RECEIVER 7.HOT CHAMPER CONTROLLER 8.OBSTACLE DETECTION THROUGH ULTRASONIC SENSOR. 9.SPRINKLER CONTROLLER 10. LAMP CONTROLLER
2 Vi Microsystems Pvt.Ltd..
INTRODUCTION
EMBEDDED SYSTEMS An embedded system is a special-purpose computer system designed to perform one or a few dedicated functions, often with real-time computing constraints. It is usually embedded aspart of a complete device including hardware and mechanical parts. In contrast, a generalpurposecomputer, such as a personal computer, can do many different tasks depending onprogramming. Embedded systems control many of the common devices in use today FEATURES OF EMBEDDED SYSTEMS i. Cost Micro controllers with the supplementary circuit components are much cheaper than a computer with an analog and digital I/O. ii. Size and Weight Micro controllers are compact and light compared to computers. iii. Simple applications If the application requires very few number of I/O and the code is relatively small, which donot require extended amount of memory and a simple LCD display is sufficient as a userinterface, a microcontroller would be suitable for this application. iv. Reliability Since the architecture is much simpler than a computer it is less likely to fail. v. Speed All the components on the microcontroller are located on a single piece of silicon. Hence, the applications run much faster than it does on a computer. FEATURES OF PIC16F877 High-Performance RISC CPU * Only 35 single-word instructions to learn. * All single-cycle instructions except for program branches, which are twocycle. * Operating speed: DC 20 MHz clock input DC 200 ns instruction cycle. * Up to 8K x 14 words of Flash Program Memory, Up to 368 x 8 bytes of Data Memory (RAM), Up to 256 x 8 bytes of EEPROM Data Memory. * Pin out compatible to other 28-pin or 40/44-pin PIC16CXXX and PIC16FXXX micro controllers. Peripheral Features * Timer0: 8-bit timer/counter with 8-bit prescaler.
3 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL * Timer1: 16-bit timer/counter with prescaler, can be incremented during Sleep via external crystal/clock. * Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler. * Two Capture, Compare, PWM modules. - Capture is 16-bit, max. Resolution is 12.5 ns - Compare is 16-bit, max. Resolution is 200 ns - PWM max. Resolution is 10-bit * Synchronous Serial Port (SSP) with SPI (Master mode) and I2C (Master/Slave). * Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address detection. * Parallel Slave Port (PSP) 8 bits wide with external RD, WR and CS controls (40/44-pin only). * Brownout detection circuitry for Brown-out Reset (BOR). Analog Features * 10-bit, up to 8-channel Analog-to-Digital Converter (A/D). * Brownout Reset (BOR). * Analog Comparator module with: - Two analog comparators. - Programmable on-chip voltage reference (VREF) module. - Programmable input multiplexing from device inputs and internal voltage reference. - Comparator outputs are externally accessible. Special Micro controller Features * 100,000-erase/write cycle Enhanced Flash program memory typical. * 1,000,000-erase/write cycle Data EEPROM memory typical. * Data EEPROM Retention > 40 years. * Self-re-programmable under software control. * In-Circuit Serial Programming (ICSP ) via two pins. * Single-supply 5V In-Circuit Serial Programming. * Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation. * Programmable code protection. * Power saving Sleep mode. * Selectable oscillator options. * In-Circuit Debug (ICD) via two pins. Application * Industrial control * Medical systems * Access control * Point-of-sale * Communication gateway * Embedded soft modem * General purpose applications
4 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL PIN TERMINATION OF 16F877A CONTROLLER IN (P8 VPIC BUS )
5 Vi Microsystems Pvt.Ltd..
EX NO:1 AIM:
VOLTAGE MEASUREMENT
ToWrite a C Program to measure voltage from 0 to 5 volts and display on 2 digits 7 segment displays. APPARATUS REQUIRED 1. PIC16F877A KIT 2. 5 V ADAPTER 3. RS232 CABLE. SOFTWARE USED 1. MPLAB IDE COMPILER. 2. PIC ISP DOWNLOADER. PROGRAM #include<16f877.h> #use delay(clock=20000000) #use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7) #use I2C(master, sda=PIN_C4, scl=PIN_C3) long int value; int i=0; unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; void write_seg(int x1,int x2) { unsigned char x=0; x=(arr[x1]|0x80); i2c_start(); i2c_write(0x40); i2c_write(arr[x1]|0x80);
6 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL i2c_stop(); i2c_start(); i2c_write(0x42); i2c_write(arr[x2]); i2c_stop(); } void main() { setup_adc_ports( RA0_ANALOG ); setup_adc(ADC_CLOCK_INTERNAL ); while(1) {set_adc_channel( 0 ); value = read_adc(); i=((value*50)/255); write_seg(i/10,i%10); //printf(" %d.%d \n\r",i/10,i%10); } } PROCEDURE 1. 2. 3. 4. Compile the above CProgram using MPLAB IDE Software to create HEX file Down Load the HEX file using PICISP software . Vary the Potmeter, which is connected to ADC Channel 0(TP1) While varying the Potmeter, the corresponding digitin the 7 segment (0-5V) will also vary automatically.
RESULT Thus the voltmeter is designed to measure voltages from 0 to 5v in the 7 segment display and the C program was compiled and executed successfully.
7 Vi Microsystems Pvt.Ltd..
EX NO:2 AIM:
Design a water Pumb controller by sensing the low and high level in the water tank. APPARATUS REQUIRED 1. 2. 3. 4. PIC16F877A KIT 5 V ADAPTER RS232 CABLE. ITB 003 Module.
SOFTWARE USED 1. MPLAB IDE COMPILER. 2. PIC ISP DOWNLOADER. PROGRAM #include<16f877a.h> #include<stdio.h> #use delay(clock=20000000) #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7) volatile int a=0,b=0; void main() { while(1) { a=input(PIN_D0); b=input(PIN_D1); printf("\n\r %d %d ",a,b); b=a&b; printf("%d",b);
8 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL if(b == 0) { output_high(PIN_D4); // MOT output_high(PIN_D6); // LED:RED output_low(PIN_D7); // LED:GREEN
} else { output_low(PIN_D4); // MOT output_low(PIN_D6); // LED:GREEN output_high(PIN_D7); // LED:RED } if(a==0) { output_low(PIN_D6); // LED:GREEN } } }
9 Vi Microsystems Pvt.Ltd..
CONNECTION DIAGRAM
PROCEDURE 1. Compile the above CProgram using MPLAB IDE Software to create HEX file 2. Down Load the HEX file using PIC ISP software . 3. Connections are given as per the connection diagram. 4. After executing the program,the low level in the tank is sensed and it is indicated by green signal and the high level in the water tank is indicated by red signal.When water reaches the high level the relay will be cut off.
RESULT Thus water Pumb controller is designed to sense low and high in the water tank .
10 Vi Microsystems Pvt.Ltd..
EX NO:3 AIM:
DIGITAL CLOCK
ToWrite a C Program to display the Real Time Clock in the LCD display. APPARATUS REQUIRED 1. 2. 3. 4. PIC16F877A KIT 5 V ADAPTER RS232 CABLE. RTC BOARD
SOFTWARE USED 1. MPLAB IDE COMPILER. 2. PIC ISP DOWNLOADER. PROGRAM #include <16F877A.H>
#use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #use I2C(master, sda=PIN_C4, scl=PIN_C3)
void lcd_init(); void delay(unsigned long del); void lcd_cmd(unsigned char cmd); void lcd_dat(unsigned char dat);
11 Vi Microsystems Pvt.Ltd..
unsigned char time[]={0X56,0X38,0X10,0X01,0X01,0X11}; unsigned char readtime[0X06]; unsigned long int hour,second,minute,date,month,year; unsigned int i; unsigned char rtc[13]; unsigned char initi[5]={0x38,0x01,0x06,0x0C,0x80}; char x[]="REALTIME:";
void data_display(char x[]) { output_high(pin_E0); output_low(pin_E1); output_low(pin_E2); for(i=0;x[i]!='\0';i++) { output_D(x[i]); output_high(pin_E2); delay_us(500); output_low(pin_E2); } } void data_display1(unsigned char rtc[])
12 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL { output_high(pin_E0); output_low(pin_E1); output_low(pin_E2); for(i=0;x[i]!='\0';i++) { output_D(rtc[i]); output_high(pin_E2); delay_us(500); output_low(pin_E2); } }
get_rtc_time();
printf("T: %x : %x : %x \t",hour,minute,second);
13 Vi Microsystems Pvt.Ltd..
data_display1(rtc);
} void get_rtc_time()
14 Vi Microsystems Pvt.Ltd..
void lcd_cmd(unsigned char cmd) { output_low(pin_E0); output_low(pin_E1); delay(500); output_d(cmd); delay(500); output_high(pin_E2); delay(500); output_low(pin_E2);
16 Vi Microsystems Pvt.Ltd..
GND
GND
PIC16F877A
RTC Module
PROCEDURE 1. Compile the above CProgram using MPLAB IDE Software to create HEX file 2. Down Load the HEX file using PIC ISP software .
17 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL 3. Connections are given as per the connection diagram. 4. After executing the program,the time will be displayed in the LCD display.
RESULT Thus the digital clock is designed to display the time in the LCD display .
18 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL EX NO:4 AIM: ToWrite a C Program to display temperature value in the 7 segment using LM35 sensor. APPARATUS REQUIRED 1. 2. 3. 4. PIC16F877A KIT 5 V ADAPTER RS232 CABLE. LM35 SENSOR TEMPERATURE MEASUREMENT
The are many cool sensors available now a days, ranging from IR distance sensor modules, accelerometers, humidity sensors, temperature sensors and many many more(gas sensors, alcohol sensor, motion sensors, touch screens). Many of these are analog in nature. That means they give a voltage output that varies directly (and linearly) with the sensed quantity. For example in LM35 temperature sensor, the output voltage is 10mV per degree centigrade. That means if output is 300mV then the temperature is 30 degrees. In this tutorial we will learn how to interface LM35 temperature sensor with PIC18F77A microcontroller and display its output on the 7 segment display.
19 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL Another important characteristic of the LM35DZ is that it draws only 60 micro amps from its supply and possesses a low self-heating capability. The sensor self-heating causes less than 0.1 oC temperature rise in still air. connect the +Vs Pin to 5v and GND to GND. The output must be connected to the analog input pin 2 of the PIC16f877A MCU. It is labeled AN2 in the datasheet. It is pin number 4 on the 40 pin package. It is also called RA2 because it is shared with PORTA2.
PROGRAM #include<16f877.h> #use delay(clock=20000000) #use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7) #use I2C(master, sda=PIN_C4, scl=PIN_C3) float value; unsigned int i=0; unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}; void delay(unsigned long int del) { while(del--); } void write_seg(int x1,int x2) { i2c_start(); i2c_write(0x40); i2c_write(arr[x1]); i2c_stop(); i2c_start();
20 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL i2c_write(0x42); i2c_write(arr[x2]); i2c_stop(); } void main() { setup_adc_ports( ALL_ANALOG ); setup_adc(ADC_CLOCK_INTERNAL ); while(1) { set_adc_channel( 2 ); value = read_adc(); value = value; i=((int)(value)); i=(i*2); printf(" Temperature in Cel %d \n\r",i); if(i>=99){i=99;} write_seg(i/10,i%10); delay(48000); } }
21 Vi Microsystems Pvt.Ltd..
PIC16F877A
PROCEDURE 1. 2. 3. 4. Connections are given as per the connection diagram. Compile the above CProgram using MPLAB IDE Software to create HEX file Down Load the HEX file using PIC ISP software . After executing the program,the corresponding temperature wil be displayed in the 7 segment.
RESULT Thus the C Program was written to display the temperature value in the 7 segment using LM35 sensor
22 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL EX NO:5 AIM: ToWrite a C Program to display the message in the serial window. APPARATUS REQUIRED 1. PIC16F877A KIT 2. 5 V ADAPTER 3. RS232 CABLE. SOFTWARE USED 1. MPLAB IDE COMPILER. 2. PIC ISP DOWNLOADER 3. WINX TALK PROGRAM #include<16f877a.h> #include<stdio.h> #use delay(clock=20000000) #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7) void main() { while(1) { printf(" Vi Microsystems Pvt Ltd Chennai-95 \n"); } } PROCEDURE 1. Compile the above CProgram using MPLAB IDE Software to create HEX file 2. Down Load the HEX file using PIC ISP software . 3. After executing the program,the message Vi Microsystems Pvt Ltd Chennai-95 will be seen in the WINX TALK communication window with 9600 baudrate.
23 Vi Microsystems Pvt.Ltd..
PC COMMUNICATION
RESULT Thus the above Cprogram to display the message in the serial window was executed and verified successfully.
24 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL EX NO:6 AIM: ToWrite a C Program to establish a remote link between two microcontroller using RF transmitter and receiver and send the message abcd from the transmitter side to receiver side. APPARATUS REQUIRED 1. PIC16F877A KIT 2. 5 V ADAPTER 3. RS232 CABLE. SOFTWARE USED 1. MPLAB IDE COMPILER. 2. PIC ISP DOWNLOADER PROGRAM IN TRANSMITTER SIDE #include<16f877a.h> #include<stdio.h> #use delay(clock=20000000) #use rs232(baud=1200,xmit=pin_C6,rcv=pin_C7) unsigned char receive[5]; unsigned char a='a'; unsigned char b='b'; unsigned char c[4]="abc"; int i; int j; void rx() { unsigned int i; for(i=0;i<5;i++) {
25 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL receive[i]=getch(); } } void tx(unsigned char y[]) { for(i=0;y[i]!='\0';i++) { putchar(y[i]); } } void wait(int z) { int i; for(i=0;i<z;i++){}
} void main() {
while(1) {
for(j=0;j<10000;j++) { printf("%c",a);
26 Vi Microsystems Pvt.Ltd..
} }
#use delay(clock=20000000) #use rs232(baud=1200,xmit=pin_c6,rcv=pin_c7) unsigned int i; unsigned char a; void delay(unsigned long del) { while(del--); }
void lcd_dat(unsigned char dat) { output_high(pin_E0); output_low(pin_E1); delay(500); output_D(dat); delay(500); output_high(pin_E2); delay(500); output_low(pin_E2); }
EMBEDDED SYSTEM LAB MANUAL lcd_cmd(0X0C); delay(500); lcd_cmd(0X01); delay(500); lcd_cmd(0X80); delay(500); }
a=getch();
printf("%c",a);
lcd_cmd(0x8d);
29 Vi Microsystems Pvt.Ltd..
30 Vi Microsystems Pvt.Ltd..
VCC GND
5 4 3 2 1
9 8 7 6
PIC16F877A
RF RECEIVER
PROCEDURE 1. Compile the above CProgram using MPLAB IDE Software to create HEX file 2. Down load the transmitter program in the transmitter side and receiver program in the receiver side. . 3. Connections are given as per the connection diagram. 4. After executing the program,the message abcd will be displayed in the receiver side in the LCD display
RESULT Thus the above Cprogram to establish a remote link between two microcontroller using RF transmitter and receiver was implemented successfully.
31 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL EX NO:7 AIM: Towrite a C Program to design a hot chamber to maintain the temperature say at 40 degree centigrade. APPARATUS REQUIRED 1. 2. 3. 4. 5. 6. PIC16F877A KIT 5 V ADAPTER RS232 CABLE AD590 SENSOR MINI FURNANCE TEMPERATURE ON/OFF CONTROLLER. HOT CHAMBER CONTROLLER
SOFTWARE USED: 1. MPLAB IDE COMPILER. 2. PIC ISP DOWNLOADER 3. WINX TALK THEORY
The AD590 is a two-terminal integrated circuit temperaturetransducer which produces an output current proportionalto absolute temperature. For supply voltages between +4Vand +30V the device acts as a high impedance, constantcurrent regulator passing 1mA/K. Laser trimming of thechip's thin film resistors is used to calibrate the device to298.2mA output at 298.2 Kelvin (+258C).The AD590 is particularly useful in remote sensingapplications. The AD590 is insensitive to voltage dropsover long lines due to its high impedance current output.Any well-insulated shielded twisted pair is sufficient foroperation hundreds of feet from the receiving circuitry.
void main() {
while(1) { setup_adc_ports( ALL_ANALOG ); setup_adc(ADC_CLOCK_INTERNAL ); set_adc_channel( 1 ); value = read_adc(); i=(int)(value*0.3); printf(" %d \n\r",i); if(i>40) { output_low(PIN_D0); printf(" Above "); } else if(i<35) { output_high(PIN_D0); printf(" Below "); } } }
33 Vi Microsystems Pvt.Ltd..
PROCEDURE 1. Connections are given as per the connection diagram. 2. Compile the above CProgram using MPLAB IDE Software to create HEX file 3. Down Load the HEX file using PIC ISP software .
34 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL 4. After executing the program, the relay connected to the RD0 will be cut off after the temperature exceeds 40 degree centigrade which will be displayed in the communication port.
RESULT Thus a hot chamber was designed to maintain the temperature say at 40 degrees centigrade and C Program was compiled and executed successfully.
35 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL EX NO: 8 AIM: Towrite a C Program to design an obstacle detection system using ultrasonic transmitter receiver. APPARATUS REQUIRED 1. 2. 3. 4. PIC16F877A KIT 5 V ADAPTER RS232 CABLE ULTRA SONIC SENSOR MODULE OBSTACLE DETECTOR USING ULTRASONIC
The Ultrasonic distance sensor consists of a ultrasonic transducer mounted on a small PCB, with mounting holes. It can detect objects 0-in. to 254-in. (6.45-meters), and range objects 6-in. to 254-in. (6.45 meters). Ultrasonic sensors are more of a shotgun distance sensor, as opposed to the 'laser beam' IR 36 Vi Microsystems Pvt.Ltd..
void lcd_dat(unsigned char dat) { output_high(pin_E0); output_low(pin_E1); delay(500); output_D(dat); delay(500); output_high(pin_E2); delay(500); output_low(pin_E2); }
void lcd_init(void) {
38 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL lcd_cmd(0X38); delay(500); lcd_cmd(0X06); delay(500); lcd_cmd(0X0C); delay(500); lcd_cmd(0X01); delay(500); lcd_cmd(0X80); delay(500); }
void lcd_disp(unsigned char w[],unsigned char add) { unsigned char i=0; for(i=0;w[i]!='\0';i++) { lcd_cmd(add+i); lcd_dat(w[i]); delay(500); } }
lcd_dat(((con%100)/10)+0x30);
lcd_dat((con%10)+0x30);
void main()
40 Vi Microsystems Pvt.Ltd..
41 Vi Microsystems Pvt.Ltd..
VCC GND
5 4 3 2 1
VCC
GND
O/P
9 8 7 6
PIC16F8 77A
PROCEDURE 1. 2. 3. 4. First Compile the above CProgram using MPLAB IDE Software to create HEX file Down Load the HEX file using PIC ISP software . Connections are given as per the connection diagram. After executing the program, the distance covered by the ultrasonic sensor is displayed in the LCD.
RESULT: Thus an obstacle detection system was designed using ultrasonic sensor and C Program was compiled and executed successfully
42 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL EX NO: 9 AIM: Towrite a C Program to design a moisture sensor and sprinkler controller. APPARATUS REQUIRED 1. 2. 3. 4. 5. PIC16F877A KIT 5 V ADAPTER RS232 CABLE MOISTURE SENSOR MODULE. SPRINKLER CONTROLLER MODULE. SPRINKLER CONTROLLER
SOFTWARE USED 1. MPLAB IDE COMPILER. 2. PIC ISP DOWNLOADER 3. WINX TALK THEORY
43 Vi Microsystems Pvt.Ltd..
PROGRAM #include<16f877.h> #use delay(clock=20000000) #use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7) long int value; int i=0; void main() { while(1) { setup_adc_ports( ALL_ANALOG ); setup_adc(ADC_CLOCK_INTERNAL ); set_adc_channel( 1 ); value = read_adc(); i=(int)(value/2); printf("MOISTURE SENSOR: %3d \n",i); if(i>80) { output_low(PIN_D0);
44 Vi Microsystems Pvt.Ltd..
CONNECTION DIAGRAM
45 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL PROCEDURE 1. 2. 3. 4. 5. Connections are given as per the connection diagram. Compile the above CProgram using MPLAB IDE Software to create HEX file Down Load the HEX file using PIC ISP software . Connect the output of humidity sensor to ADC input 1 (RA1) of the pic controller. After executing the program, the relay connected to the RD0 will be cut off after the sensor value exceeds 80,which will be displayed in the communication port AT 9600 baud rate.
RESULT: Thus a moisture sensor and sprinkler controller was designed and C Program was compiled and executed successfully.
46 Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL EX NO: 10 AIM: To design a light sensor to control the lamp. APPARATUS REQUIRED PIC16F877A KIT 5 V ADAPTER RS232 CABLE RTC MODULE LDR SET UP. LAMP CONTROLLER
SOFTWARE USED MPLAB IDE COMPILER. PIC ISP DOWNLOADER WINX TALK. THEORY
A Light Dependent Resistor (aka LDR, photoconductor, or photocell) is a device which has a resistance which varies according to the amount of light falling on its surface. DRs or Light Dependent Resistors are very useful especially in light/dark sensor circuits. Normally the resistance of an LDR is very high, sometimes as high as 1000 000 ohms, but when they are illuminated with light resistance drops dramatically. An LDR can even be used in a simple remote control circuit using the backlight of a mobile phone to turn on a device - call the mobile from anywhere in the world, it lights up the LDR, and lighting (or a garden sprinkler) can be turned on remotely.
47 Vi Microsystems Pvt.Ltd..
PROGRAM #include<16f877.h> #use delay(clock=20000000) #use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7) long int value; int i=0; void main() { while(1) { setup_adc_ports( ALL_ANALOG ); setup_adc(ADC_CLOCK_INTERNAL ); set_adc_channel( 1 ); value = read_adc(); i=(int)(value/2); printf("LDR SENSOR: %3d \n",i); if(i>80) { output_low(PIN_D0); } else {
48 Vi Microsystems Pvt.Ltd..
PROCEDURE Connections are given as per the connection diagram. Compile the above CProgram using MPLAB IDE Software to create HEX file Down Load the HEX file using PIC ISP software . Connect the LDR output to the analog input 1 of microcontroller. After executing the program, the time will displayed in the communication port and the Lamp connected to the RD1 will be glow for one minute delay
RESULT: Thus the light sensor to control the lamp was designed and C Program was compiled and
executed successfully.
T
49
Vi Microsystems Pvt.Ltd..
EMBEDDED SYSTEM LAB MANUAL EX NO: 11 AIM: To design a light sensor and real time clock to control a lamp for 1 minute delay. APPARATUS REQUIRED PIC16F877A KIT 5 V ADAPTER RS232 CABLE RTC MODULE LDR SET UP. LAMP CONTROLLER USING RTC AND LDR
SOFTWARE USED MPLAB IDE COMPILER. PIC ISP DOWNLOADER WINX TALK. THEORY
A Light Dependent Resistor (aka LDR, photoconductor, or photocell) is a device which has a resistance which varies according to the amount of light falling on its surface. DRs or Light Dependent Resistors are very useful especially in light/dark sensor circuits. Normally the resistance of an LDR is very high, sometimes as high as 1000 000 ohms, but when they are illuminated with light resistance drops dramatically. An LDR can even be used in a simple remote control circuit using the backlight of a mobile phone to turn on a device - call the mobile from anywhere in the world, it lights up the LDR, and lighting (or a garden sprinkler) can be turned on remotely.
50 Vi Microsystems Pvt.Ltd..
i2c_start(); i2c_write(0xa1);
52 Vi Microsystems Pvt.Ltd..
year = 0;
PROCEDURE Connections are given as per the connection diagram. Compile the above CProgram using MPLAB IDE Software to create HEX file Down Load the HEX file using PIC ISP software . After executing the program, the time will displayed in the communication port and the Lamp connected to the RD1 will be glow for one minute delay
RESULT: Thus the light sensor to control the lamp was designed and C Program was compiled and executed successfully.
55 Vi Microsystems Pvt.Ltd..
56 Vi Microsystems Pvt.Ltd..