Embedded Record
Embedded Record
Embedded Record
INTRODUCTION
LIST OF EXPERIMENTS
1.VOLTAGE MEASUREMENT
3.DIGITAL CLOCK
4.TEMPERATURE MEASUREMENT
5.PC COMMUNICATION
9.SPRINKLER CONTROLLER
EMBEDDED SYSTEMS
i. Cost
Micro controllers with the supplementary circuit components are much cheaper than a
computer with an analog and digital I/O.
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
Peripheral Features
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.
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
PROGRAM
#include<16f877.h>
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
int i=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);
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
SOFTWARE USED
3. RIDE Compiler
4. WIN ISP
PROGRAM
#include<reg51.h>
#include<string.h>
#include<stdio.h>
int k;
int ij;
//Prototype Declaration
void Delay_Time();
void busycheck();
void I2C_START();
void I2C_STOP() ;
void lcdint();
void ser_int();
//char f[5];
sbit SCLK=P3^2;
bit ACK;
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;
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;
dat=j;
for(i=0;i<8;i++)
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;
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.
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
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)
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
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
SOFTWARE USED
1.RIDE compiler
2.WIN ISP
PROGRAM
#include <reg51.h>
sbit gled=P1^4;
sbit rled=P1^3;
void main()
int a,b;
while(1)
gled=0;
rled=0;
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.
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
PROGRAM
#include <16F877A.H>
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void set_rtc_time();
void get_rtc_time();
void lcd_init();
unsigned int i;
char rtc[];
char x[]="TIME:";
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);
}
}
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();
while(del=del-1);
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);
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()
for(k=0;k<5;k++)
lcd_cmd(initi[k]);
CONNECTION DIAGRAM
GND
GND Black
Vcc
Vcc Red
Sda
RC4 Yellow
Scl
RC3 Green
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
SOFTWARE USED
1.RIDE Compiler
2. WIN ISP
PROGRAM
#include<reg51.h>
#include<stdio.h>
#define TRUE 1
#define FALSE 0
bit ack;
int ij;
char s[20];
int i;
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(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();
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;
retry = 9;
I2C_DIO = 1;
while (retry--)
if (!I2C_DIO)
I2C_CLK = 1;
I2C_NOP();
I2C_CLK = 0;
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);
I2C_DIO = 1;
X = 0;
{
I2C_NOP();
I2C_CLK = 1;
if (I2C_DIO)
X |= index;
I2C_CLK = 0;
I2C_NOP();
I2C_CLK = 1;
I2C_NOP();
I2C_CLK = 0;
return(X);
_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 .
AIM: a)
APPARATUS REQUIRED
1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE.
4. VI SENSE 17 MODULE
SOFTWARE USED
#include<16f877.h>
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
float value;
while(del--);
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);
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
SOFTWARE USED
1.RIDE Compiler
2.WIN ISP
PROGRAM
#include<reg51.h>
#include<string.h>
#include<stdio.h>
int k;
int ij;
sbit rs =P1^0;
sbit en =P1^2;
//Prototype Declaration
void Delay_Time();
void busycheck();
void I2C_START();
void I2C_STOP() ;
void lcdint();
void ser_int();
sbit SCLK=P3^2;
bit ACK;
#define HIGH 01;
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;
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;
dat=j;
for(i=0;i<8;i++)
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;
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
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)
APPARATUS REQUIRED
1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE.
SOFTWARE USED
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)
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
SOFTWARE USED
1.RIDE Compiler
2. WIN ISP
3. WINX TALK
PROGRAM
#include <reg51.h>
#include <stdio.h>
void InitUart(void)
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.
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
#include<16f877a.h>
#include<stdio.h>
#use delay(clock=20000000)
#use rs232(baud=1200,xmit=pin_C6,rcv=pin_C7)
int i;
int j;
void rx()
unsigned int i;
for(i=0;i<5;i++)
receive[i]=getch();
{
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);
#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;
while(del--);
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);
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);
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);
for(i=0;w[i]!='\0';i++)
lcd_cmd(add+i);
lcd_dat(w[i]);
delay(500);
void print()
lcd_disp(arr1,0xC0);
void main()
lcd_init();
while(1)
a=getch();
printf("%c",a);
lcd_cmd(0x8d);
lcd_dat(a);
GND BLACK
5
YELLOW
9
4
8
3 RXD
7
2
6
1
PIC16F877A 9 PI N D” MALE IN
PIC16F77A
RF RECEIVER
PROCEDURE
AIM: b)
APPARATUS REQUIRED:
SOFTWARE USED:
1.RIDE Compiler
3.WINXTALK
#include<reg51.h>
char arr[4]="abcd";
void delay()
int i;
for(i=0;i<5000;i++);
void main()
int i;
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();
#include<reg51.h>
#include<string.h>
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:
PROGRAM
#include<16f877.h>
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
float value;
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);
else if(i<35)
output_high(PIN_D0);
}
CONNECTION DIAGRAM
i/p
P4
o/p
-12V
RA1 P3
P5
GND
GND
PIC16F77A GND
(black)
Heater
Relay
o/p power cable
(Red)
MINI furnace
ON/OFF controller
PROCEDURE
Towrite a ‘C’ Program to design a hot chamber to maintain the temperature say at 40
degree centigrade.
APPARATUS REQUIRED:
SOFTWARE USED:
1.RIDE Compiler
3.WINXTALK
PROGRAM:
#include<reg51.h>
#include<stdio.h>
#include<string.h>
#define HIGH 1
#define LOW 0
sbit sclk=P3^2;
sbit sda=P3^3;
bit ack;
for(i=0;i<x;i++);
}
void i2c_start()
sda=1;
sclk=1;
delay(500);
sda=0;
delay(500);
sclk =0;
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 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)
APPARATUS REQUIRED
1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE
4. ULTRA SONIC SENSOR MODULE
SOFTWARE USED:
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)
while(del--);
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);
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);
for(i=0;w[i]!='\0';i++)
lcd_cmd(add+i);
lcd_dat(w[i]);
delay(500);
lcd_dat(((con%1000)/100)+0x30);
lcd_dat(((con%100)/10)+0x30);
lcd_dat((con%10)+0x30);
void print()
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
AIM: b)
Towrite a ‘C’ Program to design an obstacle detection system using ultrasonic
transmitter receiver.
APPARATUS REQUIRED:
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
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.
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
PROGRAM
#include<16f877.h>
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
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);
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
AIM b)
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 sclk=P3^2;
sbit sda=P3^3;
bit ack;
for(i=0;i<x;i++);
void i2c_start()
sda=1;
sclk=1;
delay(500);
sda=0;
delay(500);
sclk =0;
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 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 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
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.
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
PROGRAM
#include<16f877a.h>
#include<stdio.h>
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
float value=0;
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;
if((year==1)|| (i>70))
{
output_high(PIN_D1);
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
Rewrite program
#include<16f877.h>
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)
float value;
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)
APPARATUS REQUIRED:
SOFTWARE USED:
1.RIDE COMPILER
3.WINXTALK
PROGRAM:
#include<reg51.h>
#include<stdio.h>
#include<string.h>
#define HIGH 1
#define LOW 0
sbit sclk=P3^2;
sbit sda=P3^3;
bit ack;
for(i=0;i<x;i++);
}
void i2c_start()
sda=1;
sclk=1;
delay(500);
sda=0;
delay(500);
sclk =0;
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 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:
RESULT: