Вы находитесь на странице: 1из 43

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 as part of
a complete device including hardware and mechanical parts. In contrast, a general purpose
computer, such as a personal computer, can do many different tasks depending on programming.
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 do not
require extended amount of memory and a simple LCD display is sufficient as a user interface, 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.

1
* 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

2
EX NO:1 VOLTAGE MEASUREMENT

AIM:

To Write 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);

i2c_stop();

3
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. Compile the above CProgram using MPLAB IDE Software to create HEX file
2. Down Load the HEX file using PICISP software .
3. Vary the Potmeter, which is connected to ADC Channel 0(TP1)
4. While varying the Potmeter, the corresponding digit in 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.

4
EX NO:2 WATER LEVEL CONTROLLER

AIM:

Design a water Pumb controller by sensing the low and high level in the water tank.

APPARATUS REQUIRED

1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE.
4. 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);

if(b == 0)

5
{

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

6
CONNECTION DIAGRAM

GND

PA 0
RD 1 1
PC 0 9
RD 4 2
PC 1 8
RD 6 3
PC 2 7
RD 7 4
6
PB 0
RD 0 5

PIC16F77A Serial port termination in


ITB-003 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 .
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 .

7
DIGITAL CLOCK

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 set_rtc_time();

void get_rtc_time();

void lcd_init();

void delay(unsigned long del);

void lcd_cmd(unsigned char cmd);

void lcd_dat(unsigned char dat);

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;

char rtc[];

unsigned char initi[5]={0x38,0x01,0x06,0x0C,0x80};

char x[]="TIME:";

void data1(char x[])

output_high(pin_C0);

output_low(pin_C1);

output_low(pin_C2);

8
for(i=0;x[i]!='\0';i++)

output_D(x[i]);

output_high(pin_C2);

delay_us(500);

output_low(pin_C2);

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 main()

lcd_init();

data_display(x);

9
set_rtc_time();

while(1)

get_rtc_time();

printf("T: %x : %x : %x \t",hour,minute,second);

//printf("D: %x : %x : %x \r\n",readtime[3],readtime[4],readtime[5]);

sprintf(rtc,"%02x:%02x:%02x ",hour,minute,second);

lcd_cmd(0xc0);

//data1(rtc);

data_display(rtc);

void set_rtc_time()

i2c_start();

i2c_write(0xa0);

i2c_write(0x02);

i2c_write(0x55);

i2c_write(0x15);

i2c_write(0x05);

i2c_stop();

void get_rtc_time()

i2c_start();

10
i2c_write(0xa0);

i2c_write(0x02);

i2c_stop();

i2c_start();

i2c_write(0xa1);

second = i2c_read(0);

i2c_stop();

i2c_start();

i2c_write(0xa0);

i2c_write(0x03);

i2c_stop();

i2c_start();

i2c_write(0xa1);

minute = i2c_read(0);

i2c_stop();

i2c_start();

i2c_write(0xa0);

i2c_write(0x04);

i2c_stop();

i2c_start();

i2c_write(0xa1);

hour = i2c_read(0);

i2c_stop();

void delay(unsigned long del)

11
{

while(del=del-1);

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);

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);

12
void lcd_init()

unsigned int k=0;

for(k=0;k<5;k++)

lcd_cmd(initi[k]);

CONNECTION DIAGRAM:

13
GND
GND Black

Vcc
Vcc Red

Sda
RC4 Yellow

Scl
RC3 Green

PIC16F77A 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 .
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 .

EX NO:4 TEMPERATURE MEASUREMENT

AIM:

14
To Write a C Program to display temperature value in the 7 segment using LM35
sensor.

APPARATUS REQUIRED

1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE.
4. VI SENSE 17 MODULE

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)

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]);

15
i2c_stop();

i2c_start();

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);

CONNECTION DIAGRAM

16
GND
GND
Vcc Vcc
o/p
RA2

VI Sense 17
Module

PIC16F77A
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 .
4. 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.

EX NO:5 PC COMMUNICATION

17
AIM:

To Write 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.

18
RESULT

Thus the above Cprogram to display the message in the serial window was executed
and verified successfully.

EX NO:6 REMOTE CONTROL THROUGH FM LINK

19
AIM:

To Write 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++)

receive[i]=getch();

20
}

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);

21
}

PROGRAM IN RECEIVER SIDE

#include<16f877.h>

#include<stdio.h>

#use delay(clock=20000000)

#use rs232(baud=1200,xmit=pin_c6,rcv=pin_c7)

//#use rs232(baud=1200,xmit=pin_c6,rcv=pin_c7,stream=GPS)

char x[]="TIME:";

unsigned int i;

unsigned char a;

void delay(unsigned long del)

while(del--);

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);

22
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)

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 data1(char x[])

23
{

output_high(pin_C0);

delay(500);

output_low(pin_C1);

output_low(pin_C2);

for(i=0;x[i]!='\0';i++)

output_D(x[i]);

output_high(pin_C2);

// delay_us(500);

delay(500);

output_low(pin_C2);

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);

24
void print()

//unsigned char arr[]={"MAGESHWARAN"};

unsigned char arr1[]={"VI MICRO SYSTEMS"};

// lcd_disp(arr,0x80);

lcd_disp(arr1,0xC0);

void main()

lcd_init();

// print();

while(1)

a=getch();

printf("%c",a);

lcd_cmd(0x8d);

lcd_dat(a);

// print();

//data1(x);

CONNECTION DIAGRAM IN TRANSMITTER SIDE

25
CONNECTION DIAGRAM IN RECEIVER SIDE

VCC RED

GND BLACK

5
YELLOW
9
4
8
3
7 RXD
2
6
1

PIC16F877A 9 PIN D MALE IN RF RECEIVER


PIC16F77A

PROCEDURE

26
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 .
4. After executing the program,the message abcd will be displayed in the receiver
side.

RESULT

Thus the above Cprogram to establish a remote link between two microcontroller using
RF transmitter and receiver was implemented successfully.

EX NO:7 HOT CHAMBER CONTROLLER

27
AIM:

To write a C Program to design a hot chamber to maintain the temperature say at 40


degree centigrade.

APPARATUS REQUIRED

1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE
4. AD590 MOULE
5. MINI FURNANCE
6. TEMPERATURE ON/OFF CONTROLLER.

SOFTWARE USED:

1. MPLAB IDE COMPILER.


2. PIC ISP DOWNLOADER
3. WINX TALK

PROGRAM

#include<16f877.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

float value;

unsigned int i=0;

void main()

while(1)

setup_adc_ports( ALL_ANALOG );

setup_adc(ADC_CLOCK_INTERNAL );

set_adc_channel( 1 );

value = read_adc();

28
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 ");

29
CONNECTION DIAGRAM

i/p
P4
o/p

-12V
RA1 P3

P5
GND
GND

AD590 Module Sensor


RD0

PIC16F77A GND
(black)
Heater
Relay
o/p power cable
(Red)
MINI furnace

ON/OFF controller

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 .
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.

30
EX NO: 8 OBSTACLE DETECTOR USING ULTRASONIC

AIM:

To write a C Program to design an obstacle detection system using ultrasonic


transmitter receiver.

APPARATUS REQUIRED

1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE
4. ULTRA SONIC SENSOR MODULE

SOFTWARE USED:

1. MPLAB IDE COMPILER.


2. PIC ISP DOWNLOADER

PROGRAM

#include<16f877a.h>

#include<stdlib.h>

#include<string.h>

#include<stdio.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,stream=GPS)

int i=0;int a1;char a[];

void delay(unsigned long del)

while(del--);

void lcd_cmd(unsigned char cmd)

output_low(pin_E0);

31
output_low(pin_E1);

delay(500);

output_D(cmd);

delay(500);

output_high(pin_E2);

delay(500);

output_low(pin_E2);

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)

lcd_cmd(0X38);

delay(500);

lcd_cmd(0X06);

delay(500);

32
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);

void lcd_con(unsigned int con)

lcd_dat(((con%1000)/100)+0x30);

lcd_dat(((con%100)/10)+0x30);

lcd_dat((con%10)+0x30);

33
}

void print()

unsigned char arr[]={"DISTANCE IN CMS"};

lcd_disp(arr,0x80);

void get()

do{;}while(getc()!='R');

a1=( (getc()-48)*100)+( (getc()-48)*10)+ (getc()-48);

void main()

lcd_init();

print();

while(1)

while(1)

get();

lcd_cmd(0xC0);

lcd_con(a1);

34
}

CONNECTION DIAGRAM

VCC
VCC RED
GND
GND BLACK
O/P

5
YELLOW
9
4
8
3
7
2
6
1

PIC16F8 77A 9 PIN D MALE IN ULTRASONIC


PIC16F77A SENSOR MODULE

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 .
4. 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.

35
EX NO: 9 SPRINKLER CONTROLLER

AIM:

To write a C Program to design a moisture sensor and sprinkler controller.

APPARATUS REQUIRED

1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE
4. MOISTURE SENSOR MODULE.
5. SPRINKLER CONTROLLER MODULE.

SOFTWARE USED

1. MPLAB IDE COMPILER.


2. PIC ISP DOWNLOADER
3. WINX TALK

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();

36
i=(int)(value/2);

printf("MOISTURE SENSOR: %3d \n",i);

if(i>80)

output_low(PIN_D0);

else

output_high(PIN_D0);

CONNECTION DIAGRAM

RELAY O/P
YELLOW

BLACK
RD 0
SPRINKLER
GND CONTROLLER MODULE

VCC
GND
BLACK
RA 1
VCC
RED
O/P
YELLOW
PIC16F877A

MOISTURE
SENSOR MODE

37
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 .
5. 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.

RESULT:

Thus a moisture sensor and sprinkler controller was designed and C Program was
compiled and executed successfully.

38
EX NO: 10 LAMP CONTROLLER

AIM:

To design a light sensor and real time clock to control a lamp for 1 minute delay.

APPARATUS REQUIRED

1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE
4. RTC MODULE
5. LDR SET UP.

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)

#use I2C(master, sda=PIN_C4, scl=PIN_C3)

float value=0;

unsigned int i=0;

unsigned long int hour,second,minute,date,month,year;

void delay(unsigned int del)

while(del--);

39
void set_rtc_time()

i2c_start();

i2c_write(0xa0);

//i2c_write(0x02);

//i2c_write(0x00);

//i2c_write(0x15);

//i2c_write(0x09);

i2c_stop();

void get_rtc_time()

i2c_start();

i2c_write(0xa0);

i2c_write(0x02);

i2c_stop();

i2c_start();

i2c_write(0xa1);

second = i2c_read(0);

i2c_stop();

i2c_start();

i2c_write(0xa0);

i2c_write(0x03);

i2c_stop();

40
i2c_start();

i2c_write(0xa1);

minute = i2c_read(0);

i2c_stop();

i2c_start();

i2c_write(0xa0);

i2c_write(0x04);

i2c_stop();

i2c_start();

i2c_write(0xa1);

hour = i2c_read(0);

i2c_stop();

void main()

setup_adc_ports( ALL_ANALOG );

setup_adc(ADC_CLOCK_INTERNAL );

set_rtc_time();

while(1)

get_rtc_time();

set_adc_channel( 1 );

value = read_adc();

i=(int)(value/2);

41
year = 0;

if(minute==0x00)

year=1;

if(minute==0x02)

year=1;

if(minute==0x04)

year=1;

printf(" %d Time : %x %x %x \n\r",i,hour,minute,second);

if((year==1)|| (i>70))

output_high(PIN_D1);

if((year==0) && (i<70))

output_low(PIN_D1);

42
CONNECTION DIAGRAM
RTC MODULE

SDA
YELLOW
SCK
GREEN
PC 4
VCC
RED
PC 3
GND
BLACK
VCC

GND

AD 1
VCC VCC
RED RED
RD 1
GND GND
BLACK BLACK
O/P RELAY O/P
PIC16F877A YELLOW YELLOW

LAMP SETUP
LDR MODULE

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 .
4. 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. ET


43

Вам также может понравиться