Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

ACHARIYA COLLEGE OF ENGINEERING

TECHNOLOGY
(Approved by AICTE & Affiliated to Pondicherry University)
Achariyapuram, Villianur, Puducherry-605
Puducherry 110

EC P72-- EMBEDDED SYSTEMS LAB


(Observation Note)

Student Name : ______________________

Reg.No : ______________________

Year / Sem : ______________________


VOLTAGE MEASUREMENT

AIM:
To write a C program to measure the voltage from 0 to 5 volts and
displaying the measured value using seven segment displays.

APPARATUS REQUIRED:
1) PIC16F877a kit
2) 5V Adapter
3) RS 232 Cable

SOFTWARE USED:
1) MP Lab IDE Compiler
2) PIC ISP Downloader
3) WINX Talk
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)

long int value;

int i=0;

unsigned char arr[10] = {0x3f, 0x06, 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()

set up_adc_ports [RA0 – ANALOG];


set up_adc (ADC_ clock_INTERNAL);

while(1)

set_adc_channel(0);

value =read_adc();

i = ((value *50)/255);

write_reg(i/w,i%10);

}
ALGORITHM:

Step 1: Start the program.

Step 2: Initialise the long int and int values as zero.

Step 3: Assign the value of char[10] =


{0x3f,0x06,0x56,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}

Step 4: Pass the argument as int x1 and int x2.

Step 5: Declare character x=0 and x=lar[x1]/0x80.

Step 6: Start the I2C CAN bus and pass the arguments 0x40 in I2C write
bus.

Step 7: The arguments arr[x1]/0x80 is written in I2C write bus and stop the
function.

Step 8: Now again start the bus and write 0x42 and arr[x2] and stop the
function.

Step 9: In the main function setup the ADC port with RA0 as analog and
clock interval.

Step 10: If while condition is true then set the ADC channel as 0 and value
is assigned as read_adc.

Step 11: Initialize the value of i as value *50/255 and pass i/w, i%10 as
arguments in write seg.

Step 12: Stop the program.


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) Vary the parameter, which is connected to ADC channel0.
4) While varying the parameter, the corresponding digit in seven segment
(0-5V) will also vary automatically.

RESULT:

Thus the voltmeter is designed to measure voltages from 0 to 5V in the


segment display and the C program was compiled and executed successfully.
DESIGN OF WATER PUMP CONTROLLER TO SENSE THE WATER
LEVEL IN THE TANK

AIM:
To design a water pump controller by sensing the low and high level in
the water tank.

APPARATUS REQUIRED:
1) PIC 16F877A kit
2) 5V adapter
3) RS 232 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,rc=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);

output_high(PIN-D6);

output_low(PIN-D7);

else

output_low(PIN-D4);
output_low(PIN-D6);

output_high(PIN-D7);

if(a==0)

output_low(PIN-D6);

}
CONNECTION DIAGRAM:
GND
1

RD1
PC0
RD4
RD6 PC1
RD4 PC2
RD0 PB0

Serial port termination in


17B-003 Module

PIC 16F877A

ALGORITHM:

Step 1: Start the program

Step 2: Initialize the value int and check for condition

Step 3: Initialize a and b as input which takes the pine D0 and D1.

Step 4: Print the value of b as a product of a and b.

Step 5: Check for the condition, if b input is zero, then the output is
predicted.

Step 6: If the a input is zero, then the output low is at pin – D6.

Step 7: Stop the program.


PROCEDURE:

1) Compile the above C program using the MPLAB IDE software to create
hex file.
2) Download the hex file using PIC ISP software.
3) Connections are given as per the connection diagram.
4) After executing the program, the low level in the tank is reused and it is
indicated by green signal and high level in water is given the red signal.
5) When water reaches the high level the relay will be cut – off.

RESULT:

Thus the water pump controller by sensing low and high level in water
tank was studied and output was verified.
DIGITAL CLOCK WITH LCD DISPLAY

AIM:
To write a C program to display the real time clock is LCD display.

APPARATUS REQUIRED:
1) PIC 16F877A kit
2) 5V adapter
3) RS 232 cable
4) RTC board

SOFTWARE USED:
1) MPLAB IDE Compiler
2) PIC ISP Downloader
PROGRAM:

#include<16877a.h>

#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 init hour,second,minute,date,month,year;

unsigned int i;

char rtc[];

unsigned char init i[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:y.x\t”,hour,minute,second);

sprint(rtc,”%0.2x:%0.2x:%0.2x,hour,minute,second);

lcd_cmd(0x10);

data_display(rtc);

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

delay(500);

output_low(PIN-c2);
}

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(init i[k]);

}
CONNECTION DIAGRAM:

GND BLACK
VCC RED
RC4 YELLOW
RC3 GREEN

PIC 16F877A RTC Module

ALGORITHM:

Step 1: Start the program.

Step 2: Initialise the long int and int values as zero.

Step 3: Assign the value of char[10] =


{0x3f,0x06,0x56,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67}

Step 4: Pass the arguments as int x1 and int x2 in the function write_reg.

Step 5: Declare char x=0 and x=lar[x1]/0x80 arguments 0x40 in I2C write
bus.

Step 6: The arguments arr[x1]/0x80 is written in I2C write bus and stop the
function.

Step 7: Now again start the bus and write 0x42 and arr[x2] and stop the
function.

Step 8: Call the function data_display by passing arguments char x and the
output high is taken in pin – E0 and low in E1 or E2.

Step 9: Get the values of hour, minute and second and display the values.

Step 10: In the set_rtc_time function, the I2C bus starts and write with 0x00,
0x02, 0x55, 0x15 and 0x05 and stop the operation

Step 11: Call the function led_cmd and make the output pin as low and
high.

Step 12: Stop the program.


PROCEDURE:

1) Compile the above C program using MPLAB IDE software to create


HEX file.
2) Download the HEX file using PC ISP software.
3) Connections are given as per the connection diagram.
4) After executing the program, time will be displayed in LCD display.

RESULT:

Thus the digital clock was studied and the output was verified.
TEMPERATURE MEASUREMENT WITH 7 SEGMENT DISPLAY

AIM:
To write a C program to display temperature value in a 7 segment using
LH35 sensor.

APPARATUS REQUIRED:
1) PIC 16F877A kit
2) 5V adapter
3) RS 232 cable
4) VI sensor 17 module

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

float value;

unsigned int i=0;

unsigned char arr[10]={0x3f,0x06,0x56,0x46,0x66,0x6d,0x7,0x07,0x7f,0x67}

void delay(unsigned long int del)

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

printf(“Temperature in cel %d”,i);

if(i>=99){i=99;}

write_seg(i\10,i%10);

delay(48000);

}
CONNECTION DIAGRAM

GND GND
VCC DVCC
RC4 O/P

PIC 16F877A (BLACK) VI SENSE


17 MODULE

ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the float and unsigned int value and char arr[10].

Step 3: Call the function and check for condition.

Step 4: Go to main function set up ports and check for conditions.

Step 5: Stop the program.


PROCEDURE:

1) Connections are given as per the circuit diagram.


2) Compile the above C program using MP lab 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 display.

RESULT:

Thus the temperature measurement was done and the output was verified.
REMOTE CONTROL THROUGH FM LINK

AIM:
To write a C program to establish a remote link between two
microcontroller using RF transmitter, receiver an send the message “abcd” from
the transmitter side to the receiver side.

APPARATUS REQUIRED:
1) PIC 16F877a kit
2) 5V adapter
3) RS 232 cable

SOFTWARE USED:
1) MPLAB IDE Compiler
2) PIC ISP Downloader
PROGRAM:

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

while(1)

{
for(j=0;j<10000;j++)

printf(“%c”,a);

RECEIVER SIDE:

#include<16f877a.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);
}
unsigned char i=0;
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_data(a);
}
}
CONNECTION DIAGRAM:

TRANSMITTER SIDE:

VCC RED
GN BLACK

YELLO
PIC RF
1
9
2
8
3
7
4 TxD
6
5

RECEIVER SIDE:

VCC RED
GND BLACK

YELLOW
PIC 16F877A RF
9 1
2
8
3
7
4 RxD
6
5
ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the char value and the int value.

Step 3: Call the function and check for the condition.

Step 4: Call the function of transmitter and check for condition.

Step 5: Call the function of delay and check for the condition.

Step 6: In the main check the condition and print the value.

Step 7: For the receiver side delay, lcd_cmd and lcd_dat and lcd_init and
data – 1 and check the condition.

Step 8: Stop the program.

RESULT:

Thus the remote control through FM link was done and output was
obtained.
HOT CHAMBER CONTROLLER TO MAINTAIN THE
TEMPERATURE AT THE SET POINT

AIM:

To write a program to design a hot chamber to maintain the temperature


say 40˚C.

APPARATUS REQUIRED:

1) PIC 16F877a kit


2) 5V adapter
3) RS 232 cable
4) AD 590 Module
5) Mini Furnace
6) Temp ON/OFF controller

SOFTWARE USED:

1) MPLAB IDE Compiler


2) PIC ISP Downloader
3) WINX talk
PROGRAM:

#include<16f877a.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);
setup_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
P O/P
4

P
5

RA1
GN SENSOR

RD ON/OFF
0 CONTROLLER HEATER
PIC 16F877A

GND POWER
RED CABLE
RELAY O/P

ALGORITHM:

Step 1: Start the program.

Step 2: Is the main function check for condition.

Step 3: Set up ADC ports and initialize the value as read_adc.

Step 4: Check for the condition and get the values.

Step 5: Stop the program.


PROCEDURE:

1) Connections are given as per the circuit 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 relay connected to RD0 will be cut off
after the temperature exceeds 40˚C which will be displayed in
communication port.

RESULT:

Thus the C program for hot chamber to maintain the temperature say at
40˚C was done and the output is verified.
OBSTACLE DETECTOR USING ULTRASONIC

TRANSMITTER - RECEIVER

AIM:

To write a C program to design an obstacle detection system using


ultrasonic transmitter-receiver

APPARATUS REQUIRED:

1) PIC 16F877A kit


2) 5V adapter
3) RS 232 cable
4) Ultrasonic sensor module

SOFTWARE USED:

1) MPLAB IDE Compiler


2) PIC ISP Downloader
PROGRAM:

#include<16f877a.h>

#include<stdlib.h>

#include<sting.h>

#include<stdio.h>

#use delay(clock=20000000)

#use rs232(baud=1200,xmit=PIN-c6,rcv=PIN-c7,stram=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_500(PIN-E2);

delay(500);

output_low(PIN-E2);

void lcd_data(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 print()

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

lcd_disp(arr,0x80);

void get()

do{i}while{get c!=’R’};

a1=((get()-48)*100)&((get()-48)*10)&(get()-48);

void main()

lcd_init();

print();
while(1)

while(1)

get();

lcd_cmd(0xc0);

lcd_con(a1);

}
CONNECTION DIAGRAM:

VCC RED
GND BLACK

YELLOW
PIC 16F877A Ultrasonic
1 sensor module
9
2
8
3
7
4 9 PIN D MATE IN
6 PIC 16F877A
5
ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the value of i, a and char a[].

Step 3: Call the function and check for the condition.

Step 4: The corresponding input & the output is taken in the respective pin.

Step 5: Call the lcd_init function and output condition is checked.

Step 6: Call the lcd_init function and lcd_cmd is calculated.

Step 7: Call the lcd_disp function and initialize the value and check for the
condition.

Step 8: Call the lcd_con function and print and get and check for
condition.

Step 9: Go to the main function and check for the condition.

Step 10: Stop the program.


PROCEDURE:

1) Connections are given as per the circuit diagram.


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

RESULT:

Thus the obstacle detection system was designed using ultrasonic sensor
and the C program for that was compiled and executed.
MOISTURE DETECTOR AND SPRINKLER CONTROLLER DESIGN

AIM:

To write a C program to design a moisture sensor and sprinkler


controller.

APPARATUS REQUIRED:

1) PIC 16F877 kit


2) 5V adapter
3) RS 232 cable
4) Moisture sensor module
5) Sprinkler controller module

SOFTWARE USED:

1) MPLAB IDE Compiler


2) PIC Downloader
3) WINX Talk
PROGRAM:
#include<16f877a.h>
#use delay(clock=20000000)
#use rs232(baud=1200,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);
setup_adc_channel(1);
value=read-abc();
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 Output
YELLOW

BLACK

Sprinkler
Controller
RD0
Module
GND
VCC
RA1

PIC 16F877A

BLACK
RED
YELLOW

Moisture
Sensor Module
ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the value of long int.

Step 3: In the main function, check for the function.

Step 4: Set up the ADC ports and channel and initialize the value as read
ADC.

Step 5: Print the value and check for the condition.

Step 6: Stop the program.


PROCEDURE:

1) Connections are given as per the circuit diagram.


2) Compile the above C program using MPLAB IDE software to create hex
file.
3) Download the hex file using PIC ISP downloader.
4) After executing the program, the relay connected to RD0 will be cut-off
after the sensor value exceeds 80, which is displayed in the
communication port.

RESULT:

Thus the moisture controller using sprinkler controller sensor was


designed and the output was obtained.
DESIGNING A LAMP CONTROLLER HAVING A LIGHT SENSOR
AND A TIMER

AIM:

To design a lamp controller having a light sensor and a timer.

APPARATUS REQUIRED:

1) PIC 16F877A kit


2) 5V adapter
3) RS 232 cable
4) LDR, RTC lamp

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)

#use 12c(master,sda=PIN-c4,scl=PIN-c3)

long int value=0;

unsigned int i=0;

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

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==0xa0)
{
year=1;
}
if(minute==0x02)
{
year=1;
}
printf(“%d time:%x,%x,%x\n\n”,i,hour,minute,second);
if((year==1)||(i>60)
{
output_high(PIN-D1);
}
else if((year==0)&&(i<60))
{
output_low(PIN-D1);
}
}
ALGORITHM:

Step 1: Start the program.

Step 2: Initialize the value of i.

Step 3: Call the delay function.

Step 4: Call the get_rtc function.

Step 5: In main function, pass the function.

Step 6: Check for the condition.

Step 7: Print the output value.

Step 8: Stop the program.

PROCEDURE:

1) Compile the above C program using MPLAB LDE software to create hex
file.
2) Download the hex file using PIC ISP software.
3) After executing the program, the low level in the tank is reused and it is
indicated by signal and high level in the water tank is indicated by red
signal when water reached the high level, the relay will be cut-off.

RESULT:

Thus the lamp controller having light sensor and relay was done and
executed successfully.
PC COMMUNICATION

AIM:
To write a C program to display the message in the serial window.

APPARATUS REQUIRED:
1) PIC 16F877 kit
2) 5V adapter
3) RS 232 cable

SOFTWARE USED:
1) Microprocessor lab 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 MICROSYSTEM”);

}
ALGORITHM:

Step 1: Start the program.

Step 2: Include the inbuilt functions of library such as 16f877a.h, stdio.h


and delay.

Step 3: In the main function, check the condition while(1).

Step 4: Print the value MICROSYSTEM.

Step 5: Stop the program.

PROCEDURE:

1) Compile the above C program using MATLAB IDE software to create


HEX file.
2) Download the HEX file using PIC ISP software.
3) After executing the program, the message “VI MICROSYSTEM” will be
seen in the WINX Talk communication window with 9600 baud rate.

RESULT:

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

You might also like