Embedded Record

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 136

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


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


* 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
EX NO:1 VOLTAGE MEASUREMENT

AIM: a)

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

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. Compile the above ‘C’Program 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 digitin the 7 segment (0-5V) will
also vary automatically.

AIM: b)
ToWrite a ‘C’ Program to measure voltage from 0 to 5 volts and display on 2 digits 7
segment displays.

APPARATUS REQUIRED

4. 89c51 SB Trainer Kit.


5. Power chord
6. RS232 Cable.

SOFTWARE USED

3. RIDE Compiler
4. WIN ISP

PROGRAM

#include<reg51.h>

#include<string.h>

#include<stdio.h>

#define zero 0x3f

xdata char *segsel;

xdata char *segdata;

int k;

//unsigned int m[1];

unsigned int arr[11] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7D,0x07,0x7f,0x6F,0x80};


//0Xc0,0XF9,0XA4,0Xb0,0X99,0X92,0X82,0XF8,0X80,0x98,0x7f } ;

unsigned int arr1[11]


={0xBf,0x86,0xDb,0xCf,0xE6,0xEd,0xFD,0x87,0xFf,0xEF,0x80};

int ij;

//Prototype Declaration

void I2C_WRITE(unsigned char);

void Data_Write(unsigned char [],unsigned int);

unsigned char I2C_READ();

void Delay_Time();

void busycheck();
void I2C_START();

void I2C_STOP() ;

void lcdint();

void ser_int();

//char f[5];

unsigned int READ;

sbit SCLK=P3^2;

sbit SDA =P3^3;

bit ACK;

#define HIGH 01;

#define LOW 00;

void time()

int i;

TMOD=0x10;

TH1=0xdc;

TL1=0x00;

TR1=1;

while(TF1!=1)

{}

TF1=0;

TR1=0;

void time1()

TMOD=0x10;

TH1=0x4b;
TL1=0xfd;

TR1=1;

while(TF1!=1)

{}

TF1=0;

TR1=0;

idata unsigned char dat;

idata unsigned char i;

float adc_data;

void delay1(int x)

int i;

for(i=0;i<x;i++);

void main()

segsel = 0xff12;

segdata = 0xff21;

ser_int();

I2C_START();

I2C_WRITE(0X9e);

I2C_WRITE(0X40);

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;
*segdata=arr[0];

time();

while(1)

I2C_START();

I2C_WRITE(0x9f);

adc_data = I2C_READ();

if((adc_data==0x00)||(adc_data==0x01))

*segsel=0x2f;

*segdata=arr[0];

time1();

*segsel=0x1f;

*segdata=arr[0];

time1();

/* *segsel=0xf7;

*segdata=arr[0];

time();*/

else if((adc_data==0x05)||(adc_data==0x06)||(adc_data==0x07)||
(adc_data==0x08)||(adc_data==0x09))

*segsel=0x2f;

*segdata=arr1[0];

time1();
*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0x0A)||(adc_data==0x0B)||
(adc_data==0x0C)||(adc_data==0x0D)||(adc_data==0x0E))

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

else if((adc_data==0x0F)||(adc_data==0x10)||(adc_data==0x11)||
(adc_data==0x12)||(adc_data==0x13))

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0x14)||(adc_data==0x15)||(adc_data==0x16)||
(adc_data==0x17)||(adc_data==0x18))

{
*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0x19)||(adc_data==0x1A)||
(adc_data==0x1B)||(adc_data==0x1C)||(adc_data==0x1D))

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0x1E)||(adc_data==0x1F)||
(adc_data==0x20)||(adc_data==0x21)||(adc_data==0x22))

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();

}
else if((adc_data==0x23)||(adc_data==0x24)||
(adc_data==0x25)||(adc_data==0x26)||(adc_data==0x27))

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();

else if((adc_data==0x28)||(adc_data==0x29)||(adc_data==0x2A)||
(adc_data==0x2B)||(adc_data==0x2C))

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

else if((adc_data==0x2D)||(adc_data==0x2E)||(adc_data==0x2F)||
(adc_data==0x30)||(adc_data==0x31))

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[9];
time();

else if((adc_data==0x32)||(adc_data==0x33)||(adc_data==0x34)||
(adc_data==0x35)||(adc_data==0x36))

*segsel=0x2f;

*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

else if((adc_data==0x37)||(adc_data==0x38)||(adc_data==0x39)||
(adc_data==0x3A)||(adc_data==0x3B))

*segsel=0x2f;

*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0x3C)||(adc_data==0x3D)||(adc_data==0x3E)||
(adc_data==0x3F)||(adc_data==0x40))

*segsel=0x2f;

*segdata=arr1[1];

time1();
*segsel=0x1f;

*segdata=arr[2];

time();

else if((adc_data==0x41)||(adc_data==0x42)||(adc_data==0x43)||
(adc_data==0x44)||(adc_data==0x45))

*segsel=0x2f;

*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0x46)||(adc_data==0x47)||
(adc_data==0x48)||(adc_data==0x49)||(adc_data==0x5A))

*segsel=0x2f;

*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0x4B)||(adc_data==0x4C)||
(adc_data==0x4D)||(adc_data==0x4E)||(adc_data==0x4F))

*segsel=0x2f;
*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0x50)||(adc_data==0x51)||
(adc_data==0x52)||(adc_data==0x53)||(adc_data==0x54))

*segsel=0x2f;

*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();

else if((adc_data==0x55)||(adc_data==0x56)||(adc_data==0x57)||
(adc_data==0x58)||(adc_data==0x59))

*segsel=0x2f;

*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();

else if((adc_data==0x5A)||(adc_data==0x5B)||(adc_data==0x5C)||
(adc_data==0x5D)||(adc_data==0x5E))
{

*segsel=0x2f;

*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

else if((adc_data==0x5F)||(adc_data==0x60)||(adc_data==0x61)||
(adc_data==0x62)||(adc_data==0x63))

*segsel=0x2f;

*segdata=arr1[1];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();

else if((adc_data==0x64)||(adc_data==0x65)||(adc_data==0x66)||
(adc_data==0x67)||(adc_data==0x68))

*segsel=0x2f;

*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

}
else if((adc_data==0x69)||(adc_data==0x6A)||(adc_data==0x6B)||
(adc_data==0x6C)||(adc_data==0x6D))

*segsel=0x2f;

*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0x6E)||(adc_data==0x6F)||(adc_data==0x70)||
(adc_data==0x71)||(adc_data==0x72))

*segsel=0x2f;

*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

else if((adc_data==0x73)||(adc_data==0x74)||(adc_data==0x75)||
(adc_data==0x76)||(adc_data==0x77))

*segsel=0x2f;

*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[3];
time();

else if((adc_data==0x78)||(adc_data==0x79)||
(adc_data==0x7A)||(adc_data==0x7B)||(adc_data==0x7C))

*segsel=0x2f;

*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0x7D)||(adc_data==0x7E)||
(adc_data==0x7F)||(adc_data==0x80)||(adc_data==0x81))

*segsel=0x2f;

*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0x82)||(adc_data==0x83)||
(adc_data==0x84)||(adc_data==0x85)||(adc_data==0x86))

*segsel=0x2f;

*segdata=arr1[2];

time1();
*segsel=0x1f;

*segdata=arr[6];

time();

else if((adc_data==0x87)||(adc_data==0x88)||(adc_data==0x89)||
(adc_data==0x8A)||(adc_data==0x8B))

*segsel=0x2f;

*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();

else if((adc_data==0x8C)||(adc_data==0x8D)||(adc_data==0x8E)||
(adc_data==0x8F)||(adc_data==0x90))

*segsel=0x2f;

*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

else if((adc_data==0x91)||(adc_data==0x92)||(adc_data==0x93)||
(adc_data==0x94)||(adc_data==0x95))

*segsel=0x2f;
*segdata=arr1[2];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();

else if((adc_data==0x96)||(adc_data==0x97)||(adc_data==0x98)||
(adc_data==0x99)||(adc_data==0x9A))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

else if((adc_data==0x9B)||(adc_data==0x9C)||(adc_data==0x9D)||
(adc_data==0x9E)||(adc_data==0x9F))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0xA0)||(adc_data==0xA1)||(adc_data==0xA2)||
(adc_data==0xA3)||(adc_data==0xA4))
{

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

else if((adc_data==0xA5)||(adc_data==0xA6)||(adc_data==0xA7)||
(adc_data==0xA8)||(adc_data==0xA9))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0xAA)||(adc_data==0xAB)||
(adc_data==0xAC)||(adc_data==0xAD)||(adc_data==0xAE))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

}
else if((adc_data==0xAF)||(adc_data==0xB0)||
(adc_data==0xB1)||(adc_data==0xB2)||(adc_data==0xB3))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0xB4)||(adc_data==0xB5)||
(adc_data==0xB6)||(adc_data==0xB7)||(adc_data==0xB8))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();

else if((adc_data==0xB9)||(adc_data==0xBA)||(adc_data==0xBB)||
(adc_data==0xBC)||(adc_data==0xBD))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[7];
time();

else if((adc_data==0xBE)||(adc_data==0xBF)||(adc_data==0xC0)||
(adc_data==0xC1)||(adc_data==0xC2))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

else if((adc_data==0xC3)||(adc_data==0xC4)||(adc_data==0xC5)||
(adc_data==0xC6)||(adc_data==0xC7))

*segsel=0x2f;

*segdata=arr1[3];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();

else if((adc_data==0xC8)||(adc_data==0xC9)||(adc_data==0xCA)||
(adc_data==0xCB)||(adc_data==0xCC))

*segsel=0x2f;

*segdata=arr1[4];

time1();
*segsel=0x1f;

*segdata=arr[0];

time();

else if((adc_data==0xCD)||(adc_data==0xCE)||(adc_data==0xCF)||
(adc_data==0xD0)||(adc_data==0xD1))

*segsel=0x2f;

*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0xD2)||(adc_data==0xD3)||(adc_data==0xD4)||
(adc_data==0xD5)||(adc_data==0xD6))

*segsel=0x2f;

*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

else if((adc_data==0xD7)||(adc_data==0xD8)||(adc_data==0xD9)||
(adc_data==0xDA)||(adc_data==0xDB))

*segsel=0x2f;
*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0xDC)||(adc_data==0xDD)||
(adc_data==0xDE)||(adc_data==0xDF)||(adc_data==0xE0))

*segsel=0x2f;

*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0xE1)||(adc_data==0xE2)||
(adc_data==0xE3)||(adc_data==0xE4)||(adc_data==0xE5))

*segsel=0x2f;

*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0xE6)||(adc_data==0xE7)||
(adc_data==0xE8)||(adc_data==0xE9)||(adc_data==0xEA))
{

*segsel=0x2f;

*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();

else if((adc_data==0xEB)||(adc_data==0xEC)||(adc_data==0xED)||
(adc_data==0xEE)||(adc_data==0xEF))

*segsel=0x2f;

*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();

else if((adc_data==0xF0)||(adc_data==0xF1)||(adc_data==0xF2)||
(adc_data==0xF3)||(adc_data==0xF4))

*segsel=0x2f;

*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

}
else if((adc_data==0xF5)||(adc_data==0xF6)||(adc_data==0xF7)||
(adc_data==0xF8)||(adc_data==0xF9))

*segsel=0x2f;

*segdata=arr1[4];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();

else if((adc_data==0xFA)||(adc_data==0xFB)||(adc_data==0xFC)||
(adc_data==0xFD)||(adc_data==0xFE))

*segsel=0x2f;

*segdata=arr1[5];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

I2C_STOP();

}
void delay()

int i,j;

for(i=0;i<0xff;i++)

for(j=0;j<0xff;j++);

void ser_int()

TMOD = 0X20;

TH1 = 0XFD;

TR1 = 1;

TI = 1;

void I2C_START()

SCLK =LOW;

SDA =LOW;

Delay_Time();

SCLK=HIGH;

Delay_Time();

SDA=HIGH;

Delay_Time();

SDA=LOW;

Delay_Time();

SCLK=LOW;

void I2C_WRITE(unsigned char j)


{

dat=j;

for(i=0;i<8;i++)

{ SDA = dat & 0x80;

dat=dat<<1;

SCLK=HIGH;

Delay_Time();

SCLK = LOW;

SDA=HIGH;

Delay_Time();

SCLK = HIGH;

Delay_Time();

ACK = SDA;

Delay_Time();

SCLK=LOW;

}void I2C_STOP()

SCLK=LOW;

Delay_Time();

SDA=HIGH;

}unsigned char I2C_READ()

unsigned char i,j;

j=0;

j=SDA;

for(i=0;i<8;i++)
{

j<<=1;

SCLK=HIGH;

j|=SDA;

Delay_Time();

SCLK=LOW;

Delay_Time();

SDA = LOW;

Delay_Time();

SCLK = HIGH;

Delay_Time();

SCLK = LOW;

Delay_Time();

SDA = HIGH;

return(j);

void Delay_Time()

{ int i;

for(i=0;i<1;i++){}}

PROCEDURE

1. Compile the above ‘C’Program using RIDE Software to create HEX file
2. Down Load the HEX file using WIN ISP software
3. Vary the Potmeter, which is connected to ADC Channel 0(AIP0).
4. While varying the Potmeter, the corresponding digit in the 7 segment 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. The output was observed in PIC kit
and Philips 89C51 kit.

EX NO:2 WATER LEVEL CONTROLLER

AIM: a)

Design water Pump 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)

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

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 ‘C’ program using MPLAB IDE Software to create HEX file
2. Download the HEX file using PICISP software.
3. Connections are given as per the connection diagram.
4. After executing the programthe 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 redsignal.When
water reaches the high level the relay will be cut off.
AIM: b)

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

APPARATUS REQUIRED

1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.
4. ITB 003 Module.

SOFTWARE USED

1.RIDE compiler
2.WIN ISP

PROGRAM

#include <reg51.h>

sbit high = P1^0;


sbit low = P1^1;

sbit motor = P1^2;

sbit gled=P1^4;

sbit rled=P1^3;

void main()

int a,b;

while(1)

gled=0;

rled=0;

a = high & low;

if(a == 0)

motor = 1;

gled=0;

rled=1;

else

motor = 0;

rled=0;

gled=1;

b=high | low;

if(b==1)

{
motor = 0;

} }

PROCEDURE

1. Connect the 10 core cable to the P17 header of 89c51 SB kit and the other side of
9-9 female connector is connected to the ITB-003 module.
2. Set the mode in the ITB 003 to microcontroller mode.
3. Compile the above ‘C’ program using RIDE Software to create HEX file
4. Down Load the HEX file using WIN ISP software
5. 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 Pumpcontroller is designed to sense low and high in the water tank. The program
was executed in both PIC kit and Philips 89C51 kit.

EX NO:3 DIGITAL CLOCK

AIM: a)

Towrite a ‘C’ Program to display the Real Time Clock in the LCD display.

APPARATUS REQUIRED

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

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

set_rtc_time();

while(1)

get_rtc_time();

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

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

lcd_cmd(0xc0);

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

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)

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

void lcd_init()

unsigned int k=0;

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

lcd_cmd(initi[k]);

CONNECTION DIAGRAM
GND
GND Black

Vcc
Vcc Red

Sda
RC4 Yellow

Scl
RC3 Green

PIC16F77A RTC Module

PROCEDURE

1. Compile the above ‘C’ program using MPLAB IDE Software to create HEX file
2. Download the HEX file using PICISP software.
3. Connections are given as per the connection diagram.
4. After executing the programthe time will be displayed in the LCD display.

AIM: b)

Towrite a ‘C’ Program to display the Real Time Clock in the LCD display.

APPARATUS REQUIRED

1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.

SOFTWARE USED

1.RIDE Compiler

2. WIN ISP

PROGRAM

#include<reg51.h>
#include<stdio.h>

#define TRUE 1

#define FALSE 0

xdata char *lcdsel;

xdata char *segdata;

sbit I2C_CLK = P3^2;

sbit I2C_DIO = P3^3;

bit ack;

unsigned char arr[] = { "Real Time Clock " } ;

int ij;

unsigned char sec,min,hr,X,retry;

unsigned char i2c_stop();

unsigned char i2c_write(unsigned char byte_to_send);

unsigned char i2c_read();

char s[20];

int i;

void I2C_NOP (void);

void i2c_start();

void delay()

int i,j;

for(i=0;i<0x33;i++)

for(j=0;j<0xff;j++);

void busycheck()

{delay();

*segdata=0x00;
}

void main()

TMOD=0x20;

TH1=0xFD;

TCON=0x40;

SCON=0x50;

SBUF=' ';

lcdsel = 0xff04;

segdata = 0xff08;

busycheck();

*lcdsel=0x38;

busycheck();

*lcdsel=0x01;

busycheck();

*lcdsel=0x06;

busycheck();

*lcdsel=0x0c;

i2c_start();

i2c_write(0xA0);//HARD WARE SELECTION ADDRESS

i2c_write(0x02);//SECONDS RESISTOR ADDRESS

i2c_write(0x01);//MINITS

i2c_write(0x20);//SECOND

i2c_write(0x01);//HOUR

i2c_stop();

loop:

i2c_start();
i2c_write(0xA0);

i2c_write(0x02);

i2c_stop();

I2C_NOP();

i2c_start();

i2c_write(0xA1);

sec=i2c_read();

min=i2c_read();

hr=i2c_read();

i2c_stop();

sprintf(s," %x:%2x:%x ",hr,min,sec);

busycheck();

*lcdsel=0x80;

for(ij=0;ij<16;ij++)

busycheck();

*segdata=0x01;

*lcdsel=arr[ij];

busycheck();

*lcdsel=0xc0;

for(i=0;i<16;i++)

busycheck();

delay();

*segdata=0x01;

*lcdsel=s[i];
}

printf("\nTime = %2x:%2x:%2x",hr,min,sec);

I2C_NOP();

goto loop;

void i2c_start()

I2C_DIO = 1;

I2C_CLK = 1;

I2C_NOP();

I2C_DIO = 0;

I2C_NOP();

I2C_CLK = 0;

unsigned char i2c_stop()

retry = 9;

I2C_DIO = 1;

while (retry--)

if (!I2C_DIO)

I2C_CLK = 1;

I2C_NOP();

I2C_CLK = 0;

unsigned char i2c_write(unsigned char byte_to_send)


{

unsigned char index;

for(index = 0x80; index != 0; index >>= 1)

if (byte_to_send & index)

I2C_DIO = 1;

else

I2C_DIO = 0;

I2C_CLK = 1;

I2C_NOP();

I2C_CLK = 0;

I2C_DIO = 1;

I2C_NOP();

I2C_CLK = 1;

I2C_NOP();

ack = I2C_DIO;

I2C_CLK = 0;

return(ack == 0);

unsigned char i2c_read()

unsigned char index;

I2C_DIO = 1;

X = 0;

for(index = 0x80; index != 0; index >>= 1)

{
I2C_NOP();

I2C_CLK = 1;

if (I2C_DIO)

X |= index;

I2C_CLK = 0;

I2C_DIO = ack; // ACK (0) or NACK (1) bit

I2C_NOP();

I2C_CLK = 1;

I2C_NOP();

I2C_CLK = 0;

return(X);

void I2C_NOP (void)

_nop_ ();

_nop_ ();

_nop_ ();

_nop_ ();

_nop_ ();

_nop_ ();

PROCEDURE

1. Compile the above ‘C’ program using RIDE Software to create HEX file
2. Download the HEX file using WIN ISP software
3. The real time clock will be displayed in the16x2 LCD.
RESULT

Thus the digital clock is designed and the application software is developed in
Embedded C and the hardware was based on PIC 16f877A and Philips 89C51. The
application program was designed to display the time in the LCD display .

EX NO:4 TEMPERATURE MEASUREMENT

AIM: a)

Towrite a ‘C’ Program to display temperature value in the 7 segment using


LM35sensor.

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

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

GND
GND
Vcc Vcc
o/p
RA 2

VI Sense 17
Module

PIC16F77A

PROCEDURE
1. Connections are given as per the connection diagram.
2. Compile the above ‘C’ program using MPLAB IDE Software to create HEX file
3. Download the HEX file using PIC ISP software.
4. After executing the program the corresponding temperature will be displayed in
the 7 segment.

AIM: b)

Towrite a ‘C’ program to display temperature value in the 7 segment using LM35
sensor.

APPARATUS REQUIRED

1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.

SOFTWARE USED

1.RIDE Compiler

2.WIN ISP

PROGRAM

#include<reg51.h>
#include<string.h>

#include<stdio.h>

#define zero 0x3f

xdata char *segsel;

xdata char *segdata;

int k;

unsigned int arr[11] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7D,0x07,0x7f,0x6F,0x80};

unsigned int arr1[11] ={0xBf,0x86,0xDb,0xCf,0xE6,0xEd,0xFD,0x87,0xFf,0xEF,0x80};

int ij;

sbit rs =P1^0;

sbit rw= P1^1;

sbit en =P1^2;

unsigned char a[5]={0x38,0x01,0x06,0x0c,0x80};

//Prototype Declaration

void I2C_WRITE(unsigned char);

void Data_Write(unsigned char [],unsigned int);

unsigned char I2C_READ();

void Delay_Time();

void busycheck();

void I2C_START();

void I2C_STOP() ;

void lcdint();

void ser_int();

unsigned int READ;

sbit SCLK=P3^2;

sbit SDA =P3^3;

bit ACK;
#define HIGH 01;

#define LOW 00;

void time()

int i;

TMOD=0x10;

TH1=0xdc;

TL1=0x00;

TR1=1;

while(TF1!=1)

{}

TF1=0;

TR1=0;

void time1()

TMOD=0x10;

TH1=0x4b;

TL1=0xfd;

TR1=1;

while(TF1!=1)

{}

TF1=0;

TR1=0;

idata unsigned char dat;


idata unsigned char i;

int adc_data;

void delay1(int x)

int i;

for(i=0;i<x;i++);

void main()

segsel = 0xff12;

segdata = 0xff21;

ser_int();

I2C_START();

I2C_WRITE(0X9e);

I2C_WRITE(0X42);

*segsel=0x2f;

*segdata=arr1[0];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

while(1)

I2C_START();

I2C_WRITE(0x9f);

adc_data = I2C_READ();

if((adc_data==0x00)||(adc_data==0x01)||(adc_data==0x02)||(adc_data==0x03))
{

*segsel=0x2f;

*segdata=arr[3];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

else

if((adc_data==0x04)||(adc_data==0x05)||(adc_data==0x06)||
(adc_data==0x07))

*segsel=0x2f;

*segdata=arr[3];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0x08)||(adc_data==0x09)||(adc_data==0x0a)||(adc_data==0x0b))

*segsel=0x2f;

*segdata=arr[3];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();
}

else if((adc_data==0x0c)||(adc_data==0x0d)||(adc_data==0x0e)||(adc_data==0x0f))

*segsel=0x2f;

*segdata=arr[3];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0x10)||(adc_data==0x11)||(adc_data==0x12)||(adc_data==0x13))

*segsel=0x2f;

*segdata=arr[3];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();

else if((adc_data==0x14)||(adc_data==0x15)||(adc_data==0x16)||(adc_data==0x17))

*segsel=0x2f;

*segdata=arr[3];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();
}

else if((adc_data==0x18)||(adc_data==0x19)||(adc_data==0x1a)||(adc_data==0x1b))

*segsel=0x2f;

*segdata=arr[3];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

else if((adc_data==0x1c)||(adc_data==0x1d)||(adc_data==0x1e)||(adc_data==0x0f))

*segsel=0x2f;

*segdata=arr[3];

time1();

*segsel=0x1f;

*segdata=arr[9];

time()

else if((adc_data==0x20)||(adc_data==0x21)||(adc_data==0x22)||(adc_data==0x23))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();
}

else if((adc_data==0x24)||(adc_data==0x25)||(adc_data==0x26)||(adc_data==0x27))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0x28)||(adc_data==0x29)||(adc_data==0x2a)||(adc_data==0x2b))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

else if((adc_data==0x2c)||(adc_data==0x2d)||(adc_data==0x2e)||(adc_data==0x2f))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();
}

else if((adc_data==0x30)||(adc_data==0x31)||(adc_data==0x32)||(adc_data==0x33))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0x34)||(adc_data==0x35)||(adc_data==0x36)||(adc_data==0x37))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0x38)||(adc_data==0x39)||(adc_data==0x3a)||(adc_data==0x3b))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();
}

else if((adc_data==0x3c)||(adc_data==0x3d)||(adc_data==0x3e)||(adc_data==0x3f))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();

else if((adc_data==0x40)||(adc_data==0x41)||(adc_data==0x42)||(adc_data==0x43))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

else if((adc_data==0x44)||(adc_data==0x45)||(adc_data==0x46)||(adc_data==0x47))

*segsel=0x2f;

*segdata=arr[4];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();
}

else if((adc_data==0x48)||(adc_data==0x49)||(adc_data==0x4a)||(adc_data==0x4b))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

else if((adc_data==0x4c)||(adc_data==0x4d)||(adc_data==0x4e)||(adc_data==0x4f))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0x50)||(adc_data==0x51)||(adc_data==0x52)||(adc_data==0x53))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();
}

else if((adc_data==0x54)||(adc_data==0x55)||(adc_data==0x56)||(adc_data==0x57))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0x58)||(adc_data==0x59)||(adc_data==0x5a)||(adc_data==0x5b))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0x5c)||(adc_data==0x5d)||(adc_data==0x5e)||(adc_data==0x5f))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();
}

else if((adc_data==0x60)||(adc_data==0x61)||(adc_data==0x62)||(adc_data==0x63))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();

else if((adc_data==0x64)||(adc_data==0x65)||(adc_data==0x66)||(adc_data==0x67))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();

else if((adc_data==0x68)||(adc_data==0x69)||(adc_data==0x6a)||(adc_data==0x6b))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();
}

else if((adc_data==0x6c)||(adc_data==0x6d)||(adc_data==0x6e)||(adc_data==0x6f))

*segsel=0x2f;

*segdata=arr[5];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();

else if((adc_data==0x70)||(adc_data==0x71)||(adc_data==0x72)||(adc_data==0x73))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

else if((adc_data==0x74)||(adc_data==0x75)||(adc_data==0x76)||(adc_data==0x77))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();
}

else if((adc_data==0x78)||(adc_data==0x79||(adc_data==0x7a)||(adc_data==0x7b)))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

else if((adc_data==0x7c)||(adc_data==0x7d)||(adc_data==0x7e)||(adc_data==0x7f))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0x80)||(adc_data==0x81)||(adc_data==0x82)||(adc_data==0x83))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();
}

else if((adc_data==0x84)||(adc_data==0x85)||(adc_data==0x86)||(adc_data==0x87))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0x88)||(adc_data==0x89)||(adc_data==0x8a)||(adc_data==0x8b))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();

else if((adc_data==0x8c)||(adc_data==0x8d)||(adc_data==0x8e)||(adc_data==0x8f))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();
}

else if((adc_data==0x90)||(adc_data==0x91)||(adc_data==0x92)||(adc_data==0x93))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

else if((adc_data==0x94)||(adc_data==0x95)||(adc_data==0x96)||(adc_data==0x97))

*segsel=0x2f;

*segdata=arr[6];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();

else if((adc_data==0x98)||(adc_data==0x99)||(adc_data==0x9a)||(adc_data==0x9b))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();
}

else if((adc_data==0x9c)||(adc_data==0x9d)||(adc_data==0x9e)||(adc_data==0x9f))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0xa0)||(adc_data==0xa1)||(adc_data==0xa2)||(adc_data==0xa3))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

else if((adc_data==0xa4)||(adc_data==0xa5)||(adc_data==0xa6)||(adc_data==0xa7))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();
}

else if((adc_data==0xa8)||(adc_data==0xa9)||(adc_data==0xaa)||(adc_data==0x0ab))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0xac)||(adc_data==0xad)||(adc_data==0xae)||(adc_data==0xaf))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

else if((adc_data==0xb0)||(adc_data==0xb1)||(adc_data==0xb2)||(adc_data==0xb3))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();
}

else if((adc_data==0xb4)||(adc_data==0xb5)||(adc_data==0xb6)||(adc_data==0xb7))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();

else if((adc_data==0xb8)||(adc_data==0xb9)||(adc_data==0xba)||(adc_data==0xbb))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();

else if((adc_data==0xbc)||(adc_data==0xbd)||(adc_data==0xbe)||(adc_data==0xbf))

*segsel=0x2f;

*segdata=arr[7];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();
}

else if((adc_data==0xc0)||(adc_data==0xc1)||(adc_data==0xc2)||(adc_data==0xc3))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

else if((adc_data==0xc4)||(adc_data==0xc5)||(adc_data==0xc6)||(adc_data==0xc7))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();

else if((adc_data==0xc8)||(adc_data==0xc9)||(adc_data==0xca)||(adc_data==0xcb))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();
}

else if((adc_data==0xcc)||(adc_data==0xcd)||(adc_data==0xce)||(adc_data==0xcf))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0xd0)||(adc_data==0xd1)||(adc_data==0xd2)||(adc_data==0xd3))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0xd4)||(adc_data==0xd5)||(adc_data==0xd6)||(adc_data==0xd7))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();
}

else if((adc_data==0xd8)||(adc_data==0xd9)||(adc_data==0xda)||(adc_data==0xdb))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[6];

time();

else if((adc_data==0xdc)||(adc_data==0xdd)||(adc_data==0xde)||(adc_data==0xdf))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[7];

time();

else if((adc_data==0xe0)||(adc_data==0xe1)||(adc_data==0xe2)||(adc_data==0xe3))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[8];

time();
}

else if((adc_data==0xe4)||(adc_data==0xe5)||(adc_data==0xe6)||(adc_data==0xe7))

*segsel=0x2f;

*segdata=arr[8];

time1();

*segsel=0x1f;

*segdata=arr[9];

time();

else if((adc_data==0xe8)||(adc_data==0xe9)||(adc_data==0xea)||(adc_data==0xeb))

*segsel=0x2f;

*segdata=arr[9];

time1();

*segsel=0x1f;

*segdata=arr[0];

time();

else if((adc_data==0xec)||(adc_data==0xed)||(adc_data==0xee)||(adc_data==0xef))

*segsel=0x2f;

*segdata=arr[9];

time1();

*segsel=0x1f;

*segdata=arr[1];

time();
}

else if((adc_data==0xf0)||(adc_data==0xf1)||(adc_data==0xf2)||(adc_data==0xf3))

*segsel=0x2f;

*segdata=arr[9];

time1();

*segsel=0x1f;

*segdata=arr[2];

time();

*segsel=0xf7;

*segdata=arr[0];

time();

else if((adc_data==0xf4)||(adc_data==0xf5)||(adc_data==0xf5)||(adc_data==0xf7))

*segsel=0x2f;

*segdata=arr[9];

time1();

*segsel=0x1f;

*segdata=arr[3];

time();

else if((adc_data==0xf8)||(adc_data==0xf9)||(adc_data==0xfa)||(adc_data==0xfb))

*segsel=0x2f;

*segdata=arr[9];

time1();
*segsel=0x1f;

*segdata=arr[4];

time();

else if((adc_data==0xfc)||(adc_data==0xfd)||(adc_data==0xfe))

*segsel=0x2f;

*segdata=arr[9];

time1();

*segsel=0x1f;

*segdata=arr[5];

time();

I2C_STOP();

void delay()

int i,j;

for(i=0;i<0xff;i++)

for(j=0;j<0xff;j++);

void ser_int()

TMOD = 0X20;

TH1 = 0XFD;

TR1 = 1;
TI = 1;

void I2C_START()

SCLK =LOW;

SDA =LOW;

Delay_Time();

SCLK=HIGH;

Delay_Time();

SDA=HIGH;

Delay_Time();

SDA=LOW;

Delay_Time();

SCLK=LOW;

void I2C_WRITE(unsigned char j)

dat=j;

for(i=0;i<8;i++)

SDA = dat & 0x80;

dat=dat<<1;

SCLK=HIGH;

Delay_Time();

SCLK = LOW;

}
SDA=HIGH;

Delay_Time();

SCLK = HIGH;

Delay_Time();

ACK = SDA;

Delay_Time();

SCLK=LOW;

void I2C_STOP()

SCLK=LOW;

Delay_Time();

SDA=HIGH;

unsigned char I2C_READ(void)

unsigned char i,j;

j=0;

j=SDA;

for(i=0;i<8;i++)

j<<=1;

SCLK=HIGH;

j|=SDA;

Delay_Time();

SCLK=LOW;

}
Delay_Time();

SDA = LOW;

Delay_Time();

SCLK = HIGH;

Delay_Time();

SCLK = LOW;

Delay_Time();

SDA = HIGH;

return(j);

void Delay_Time()

int i;

for(i=0;i<1;i++)

CONNECTION DIAGRAM
PROCEDURE

1. Connect the temperature sensor to the ADC channel 2 terminated in P11


connector of 89c51 kit.
2. Compile the above ‘C’ program using RIDE Software to create HEX file
3. Download the HEX file using WIN ISP software
4. The corresponding temperature value will be displayed in the 7 segment display.

RESULT

Thus the ‘C’ program was written to display the temperature value in the 7 segment using
LM35 sensor. The program was executed in PIC 16f877A and Philips 89C51 kit.

EX NO:5 PC COMMUNICATION

AIM: a)

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 ‘C’ program using MPLAB IDE Software to create HEX file
2. Download 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 baud rate.

AIM: b)

Towrite a ‘C’ Program to display the message “welcome” in the serial window.

APPARATUS REQUIRED

1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.

SOFTWARE USED

1.RIDE Compiler

2. WIN ISP

3. WINX TALK

PROGRAM

#include <reg51.h>

#include <stdio.h>

int a,b,c; int i;

void InitUart(void)

TMOD = 0x20; // 9600 baud rate

TH1 = 0xFD;

TI = 1;

TR1 = 1;

main()

InitUart();

while(1)

printf("\n\r welcome");

PROCEDURE

1. Compile the above ‘C’ program using RIDE Software to create HEX file
2. Download the HEX file using WIN ISP software
3. The message “welcome” will be displayed in the serial window.
RESULT

Thus the above ‘C’program to display the message in the serial window was executed
and verified successfully. The message was communicated between PIC 16f877A and
personal computer and from Philips 89C51 to personal computer.

EX NO:6REMOTE CONTROL THROUGH FM LINK

AIM: a)

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

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

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

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

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

void print()

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

lcd_disp(arr1,0xC0);

void main()

lcd_init();

while(1)

a=getch();

printf("%c",a);
lcd_cmd(0x8d);

lcd_dat(a);

CONNECTION DIAGRAM IN TRANSMITTER SIDE

CONNECTION DIAGRAM IN RECEIVER SIDE


VCC RED

GND BLACK

5
YELLOW
9
4
8
3 RXD
7
2
6
1

PIC16F877A 9 PI N D” MALE IN
PIC16F77A
RF RECEIVER

PROCEDURE

1. Connections are given as per the connection diagram.


2. Compile the above ‘C’ program using MPLAB IDE Software to create HEX file
3. Download the HEX file using PIC ISP software.
4. After executing the program the message “abcd” will be displayed in the receiver
side.

AIM: b)

Towrite a ‘C’ Program to transmit the data “abcd” through RF module.

APPARATUS REQUIRED:

1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.
4. RF Module

SOFTWARE USED:

1.RIDE Compiler

2.WIN ISP DOWNLOADER

3.WINXTALK

PROGRAM IN TRANSMITTER SIDE

//program for transmitting data stored in microcontroller

#include<reg51.h>

char arr[4]="abcd";

void delay()

int i;

for(i=0;i<5000;i++);

void main()

int i;

//TO SET BAUD RATE AS 300

TMOD=0X20;

TH1=0Xa0;

SCON=0X50;

TR1=1;

while(1)

{
for(i=0;i<4;i++)

SBUF=arr[i];

while(TI==0);

TI=0;

delay();

PROGRAM IN RECEIVER SIDE

#include<reg51.h>

#include<string.h>

xdata char *lcdsel;

xdata char *segdata;

unsigned char c;

int ij;

void delay()

int i,j;

for(i=0;i<0x00;i++)

for(j=0;j<0xff;j++);

void busycheck()

delay();

*segdata=0x00;
}

void main()

lcdsel = 0xff04;

segdata = 0xff08;

TMOD=0x20;

TH1=0xa0;

TR1=1;

SCON=0x50;

busycheck();

*lcdsel=0x38;

busycheck();

*lcdsel=0x06;

busycheck();

*lcdsel=0x01;

busycheck();

*lcdsel=0x0f;

busycheck();

*lcdsel=0x80;

while(1)

while(RI==0);

c=SBUF;

RI=0;

SBUF=c;

while(TI==0);

TI=0;
busycheck();

*lcdsel=0x80;

busycheck();

delay();

*segdata=0x01;

*lcdsel=c;

CONNECTION DIAGRAM
PROCEDURE :

1. Compile the above Program using RIDE Software to create HEX file
2. Download the HEX file using WIN ISP software.
3. After executing the programthe message “abcd” will be displayed in the receiver
side LCD display.

RESULT

Thus the above ‘C’program to establish a remote link between two microcontroller
using RF transmitter and receiver was implemented successfully.
EX NO:7 HOT CHAMBER CONTROLLER

AIM: a)

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

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

}
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 ‘C’ program using MPLAB IDE Software to create HEX file
3. Download the HEX file using PICISP 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.
AIM: b)

Towrite a ‘C’ Program to design a hot chamber to maintain the temperature say at 40
degree centigrade.

APPARATUS REQUIRED:

1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.

SOFTWARE USED:

1.RIDE Compiler

2.WIN ISP DOWNLOADER

3.WINXTALK

PROGRAM:

#include<reg51.h>

#include<stdio.h>

#include<string.h>

#define HIGH 1

#define LOW 0

sbit relay= P1^1;

sbit sclk=P3^2;

sbit sda=P3^3;

unsigned char j,retry,pot0;

bit ack;

void delay(unsigned int x)

unsigned int i,n;

for(i=0;i<x;i++);

}
void i2c_start()

sda=1;

sclk=1;

delay(500);

sda=0;

delay(500);

sclk =0;

unsigned char i2c_stop()

retry = 9;

sda = 1;

while (retry--)

if (!sda)

sclk = 1;

delay(500);

sclk = 0;

else

sda = 0;

delay(500);

sclk = 1;

delay(500);

sda = 1;
return(HIGH);

sclk = 1;

return (LOW);

unsigned char i2c_write(unsigned char z)

unsigned char i;

for(i=0x80;i!=0;i>>=1)

if(z&i)

sda=1;

else

sda=0;

sclk=1;

delay(500);

sclk=0;

sda=1;

delay(50);

sclk=1;

delay(500);

ack=sda;

sclk=0;

return(ack==0);

}
unsigned char i2c_read()

unsigned char i;

sda=1;

j=0;

for(i=0x80;i!=0;i>>=1)

delay(500);

sclk=1;

if(sda)

j|=i;

sclk=0;

sda=ack;

delay(500);

sclk=1;

delay(500);

sclk=0;

return(j);

void adc()

int s, data_1;

i2c_start();

i2c_write(0x9e);

i2c_write(0x42);

i2c_stop();
delay(500);

i2c_start();

i2c_write(0x9f);

for(s=0;s<10;s++)

pot0=i2c_read();

i2c_stop();

data_1=(0.3*pot0);

printf("HOT CHAMBER:%3d\n",data_1);

if(data_1>40)

relay=0;

else

relay=1;

void main()

TMOD=0X20;

TH1=0XFD;

SCON=0X50;

TR1=1;

SBUF=' ';

while(1)
{

adc();

CONNECTION DIAGRAM
PROCEDURE :

1. Compile the above Program using RIDE Software to create HEX file
2. Download the HEX file using WIN ISP software.
3. Connect the temperature sensor AD5910 to P10 connector of 89C51 SB kit.
4. Connect the output of op07 to ADC channel 2 of 89c51SB Kit
5. Connect the input of ITB -5B to port P1.1 of 89C51SB.
6. When the temperature value exceeds 40degree ,the ITB-5B will be turn off.

RESULT

Thus a hot chamber was designed to maintain the temperature say at 40 degrees centigrade.
The application was developed using both PIC 16f877A and Philips 89C51 microcontrollers.
EX NO: 8 OBSTACLE DETECTOR USING ULTRASONIC

AIM: a)

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

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

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

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

CONNECTION DIAGRAM

VCC
VCC RED
GN D
GND BLACK
O/P
5 YELLOW
9
4
8 3
7 2
6
1

PIC16F8 77A 9 PIN D” MALE I N ULTRASONIC


PIC16F77A SENSOR MODULE
PROCEDURE

1. Connections are given as per the connection diagram.


2. Compile the above ‘C’ program using MPLAB IDE Software to create HEX file
3. Download the HEX file using PICISP software.
4. After executing the program, the distance covered by the ultrasonic sensor is
displayed in the LCD.

AIM: b)
Towrite a ‘C’ Program to design an obstacle detection system using ultrasonic
transmitter receiver.

APPARATUS REQUIRED:

1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.
4. Utrasonic sensor

SOFTWARE USED:

1.RIDE compiler

2.WIN ISP

3.WINXTALK

PROGRAM:

#include<reg51.h>

char a[6],y;

void uartsettings()

TMOD=0X20;

TH1=0XFD;

SCON=0X50;

TR1=1;

char receive()

RI=0;

while(RI==0);

y=SBUF;

return y;

void ultra()
{

int i;

while(receive()!='R');

for(i=0;i<3;i++)

a[i]=receive();

for(i=0;i<3;i++)

SBUF=a[i];

while(TI==0);

TI=0;

SBUF=0x0d;

while(TI==0);

TI=0;

SBUF=0x0a;

while(TI==0);

TI=0;

while(receive()!=0x0d);

a[i]='\0';

void main()

uartsettings();

while(1)

{
ultra();

CONNECTION DIAGRAM

PROCEDURE

1. Connections are given as per the connection diagram.


2. Compile the above ‘C’ program using RIDE software to create HEX file.
3. Download the HEX file usingWIN ISP software.
4. After executing the program, the distance covered by the ultrasonic sensor is
displayed in UART port with 9600 baudrate.

RESULT:

Thus an obstacle detection system was designed using ultrasonic sensor and ‘C’ Program
was compiled and executed successfully. The program when executed gives the distance
between the ultrasound sensor and object in front of sensor in centimeters.

EX NO: 9 SPRINKLER CONTROLLER

AIM: a)
Towrite 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();

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
SPRI NKLER
GND CONTROLLER MODULE

VCC
GND
BLACK
RA 1
VCC
RED
O/P
YELLOW
PI C16F877A

MOISTURE
SENSOR MODE

PROCEDURE

1. Connections are given as per the connection diagram.


2. Compile the above ‘C’ program using MPLAB IDE Software to create HEX file
3. Download the HEX file using PICISP 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.

AIM b)

To design a moisture sensor and sprinkler controller


APPARATUS REQUIRED:

1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.
4. Moisture sensor

SOFTWARE USED:

1.RIDE compiler

2.WIN ISP

3.WINXTALK

PROGRAM:

#include<reg51.h>

#include<stdio.h>

#include<string.h>

#define HIGH 1

#define LOW 0

sbit sprinkler= P1^1;

sbit sclk=P3^2;

sbit sda=P3^3;

unsigned char j,retry,pot0;

bit ack;

void delay(unsigned int x)

unsigned int i,n;

for(i=0;i<x;i++);

void i2c_start()

sda=1;
sclk=1;

delay(500);

sda=0;

delay(500);

sclk =0;

unsigned char i2c_stop()

retry = 9;

sda = 1;

while (retry--)

if (!sda)

sclk = 1;

delay(500);

sclk = 0;

else

sda = 0;

delay(500);

sclk = 1;

delay(500);

sda = 1;

return(HIGH);

sclk = 1;
return (LOW);

unsigned char i2c_write(unsigned char z)

unsigned char i;

for(i=0x80;i!=0;i>>=1)

if(z&i)

sda=1;

else

sda=0;

sclk=1;

delay(500);

sclk=0;

sda=1;

delay(500);

sclk=1;

delay(500);

ack=sda;

sclk=0;

return(ack==0);

unsigned char i2c_read()

unsigned char i;

sda=1;
j=0;

for(i=0x80;i!=0;i>>=1)

delay(500);

sclk=1;

if(sda)

j|=i;

sclk=0;

sda=ack;

delay(500);

sclk=1;

delay(500);

sclk=0;

return(j);

void adc()

int s, data_1;

i2c_start();

i2c_write(0x9e);

i2c_write(0x42);

i2c_stop();

delay(500);

i2c_start();

i2c_write(0x9f);

for(s=0;s<10;s++)
{

pot0=i2c_read();

i2c_stop();

data_1=(1*pot0);

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

if(data_1>160)

sprinkler=1;

else

sprinkler=0;

void main()

TMOD=0X20;

TH1=0XFD;

SCON=0X50;

TR1=1;

SBUF=' ';

sprinkler=0;

while(1)

adc();

}
}

CONNECTION DIAGRAM

PROCEDURE

1. Connections are given as per the connection diagram.


2. Compile the above ‘C’ program using RIDE IDE Software to create HEX file
3. Download the HEX file using WIN ISP software.
4. After executing the program, the relay connected to the P1.1 will be cut off after
the sensor value exceeds 160, which will be displayed in the communication port.

RESULT:

Thus a moisture sensor and sprinkler controller was designed. The application program for
the hardware was developed in Embedded C. the program was executed on PIC 16f877A and
Philips 89C51 and the control of valve was achieved programmatically.

EX NO: 10 LAMP CONTROLLER

AIM: a)
To interface a light sensor to microcontroller and use real time clock to control ON/OFF
of 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--);

void set_rtc_time()

i2c_start();

i2c_write(0xa0);

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

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

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

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 RELAYO/P
PIC16F877A YELLOW YELLOW

LAMP SET UP
LDRMODULE

PROCEDURE

1. Connections are given as per the connection diagram.


2. Compile the above ‘C’ program using MPLAB IDE Software to create HEX file
3. Download the HEX file using PICISP 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.

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

void delay(unsigned long int del)

while(del--);

void main()

setup_adc_ports(ALL_ANALOG);

setup_adc(ADC_CLOCK_INTERNAL);

while(1)

set_adc_channel(1);

value = read_adc();

i=(int)(value/2);

if(i<70)

output_high(PIN_D5);

printf("High");

}
if(i>70)

output_low(PIN_D5);

printf("i=%d",i);

printf("LOW");

}
AIM: b)

To design a light sensor to control a lamp.

APPARATUS REQUIRED:

1. 1. 89c51 SB Trainer Kit.


2. Power chord
3. RS232 Cable.
4. LDR sensor
5. Lamp with relay

SOFTWARE USED:

1.RIDE COMPILER

2.WIN ISP DOWNLOADER

3.WINXTALK

PROGRAM:

#include<reg51.h>

#include<stdio.h>

#include<string.h>

#define HIGH 1

#define LOW 0

sbit lamp = P1^1;

sbit sclk=P3^2;

sbit sda=P3^3;

unsigned char j,retry,pot0;

bit ack;

void delay(unsigned int x)

unsigned int i,n;

for(i=0;i<x;i++);
}

void i2c_start()

sda=1;

sclk=1;

delay(500);

sda=0;

delay(500);

sclk =0;

unsigned char i2c_stop()

retry = 9;

sda = 1;

while (retry--)

if (!sda)

sclk = 1;

delay(500);

sclk = 0;

else

sda = 0;

delay(500);

sclk = 1;

delay(500);
sda = 1;

return(HIGH);

sclk = 1;

return (LOW);

unsigned char i2c_write(unsigned char z)

unsigned char i;

for(i=0x80;i!=0;i>>=1)

if(z&i)

sda=1;

else

sda=0;

sclk=1;

delay(500);

sclk=0;

sda=1;

delay(500);

sclk=1;

delay(500);

ack=sda;

sclk=0;

return(ack==0);

}
unsigned char i2c_read()

unsigned char i;

sda=1;

j=0;

for(i=0x80;i!=0;i>>=1)

delay(500);

sclk=1;

if(sda)

j|=i;

sclk=0;

sda=ack;

delay(500);

sclk=1;

delay(500);

sclk=0;

return(j);

void adc()

int s, data_1;

i2c_start();

i2c_write(0x9e);

i2c_write(0x42);

i2c_stop();
delay(500);

i2c_start();

i2c_write(0x9f);

for(s=0;s<10;s++)

pot0=i2c_read();

i2c_stop();

data_1=(1*pot0);

printf("LDR SENSOR:%3d\n",data_1);

if(data_1>60)

lamp=1;

else

lamp=0;

void main()

TMOD=0X20;

TH1=0XFD;

SCON=0X50;

TR1=1;

SBUF=' ';
lamp=0;

while(1)

adc();

CONNECTION DIAGRAM
PROCEDURE:

1. Connections are given as per the connection diagram.


2. Compile the above ‘C’ program using RIDE IDE Software to create HEX file
3. Download the HEX file using WIN ISP software.
4. After executing the program, lamp connected to the P1.1 will glow,when the
sensor value exceeds 60 the value is displayed in the communication port with
9600 baudrate.

RESULT:

Thus control of the lamp was done by the sensor input.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy