Академический Документы
Профессиональный Документы
Культура Документы
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
1
* Timer1: 16-bit timer/counter with prescaler, can be incremented during Sleep
via external crystal/clock.
* Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler.
* Two Capture, Compare, PWM modules.
- Capture is 16-bit, max. Resolution is 12.5 ns
- Compare is 16-bit, max. Resolution is 200 ns
- PWM max. Resolution is 10-bit
* Synchronous Serial Port (SSP) with SPI (Master mode) and I2C
(Master/Slave).
* Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI)
with 9-bit address detection.
* Parallel Slave Port (PSP) 8 bits wide with external RD, WR and CS controls
(40/44-pin only).
* Brownout detection circuitry for Brown-out Reset (BOR).
Analog Features
* 10-bit, up to 8-channel Analog-to-Digital Converter (A/D).
* Brownout Reset (BOR).
* Analog Comparator module with:
- Two analog comparators.
- Programmable on-chip voltage reference (VREF) module.
- Programmable input multiplexing from device inputs and internal
voltage reference.
- Comparator outputs are externally accessible.
Application
* Industrial control
* Medical systems
* Access control
* Point-of-sale
* Communication gateway
* Embedded soft modem
* General purpose applications
2
EX NO:1 VOLTAGE MEASUREMENT
AIM:
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();
3
i2c_start();
i2c_write(0x42);
i2c_write(arr[x2]);
i2c_stop();
void main()
setup_adc_ports( RA0_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
while(1)
{set_adc_channel( 0 );
value = read_adc();
i=((value*50)/255);
write_seg(i/10,i%10);
PROCEDURE
1. Compile the above CProgram using MPLAB IDE Software to create HEX file
2. Down Load the HEX file using PICISP software .
3. Vary the Potmeter, which is connected to ADC Channel 0(TP1)
4. While varying the Potmeter, the corresponding digit in the 7 segment (0-5V) will also
vary automatically.
RESULT
Thus the voltmeter is designed to measure voltages from 0 to 5v in the 7 segment display
and the C program was compiled and executed successfully.
4
EX NO:2 WATER LEVEL CONTROLLER
AIM:
Design a water Pumb controller by sensing the low and high level in the water tank.
APPARATUS REQUIRED
1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE.
4. ITB 003 Module.
SOFTWARE USED
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)
5
{
output_high(PIN_D4); // MOT
output_high(PIN_D6); // LED:RED
output_low(PIN_D7); // LED:GREEN
else
output_low(PIN_D4); // MOT
output_low(PIN_D6); // LED:GREEN
output_high(PIN_D7); // LED:RED
if(a==0)
output_low(PIN_D6); // LED:GREEN
6
CONNECTION DIAGRAM
GND
PA 0
RD 1 1
PC 0 9
RD 4 2
PC 1 8
RD 6 3
PC 2 7
RD 7 4
6
PB 0
RD 0 5
1. Compile the above CProgram using MPLAB IDE Software to create HEX file
2. Down Load the HEX file using PIC ISP software .
3. Connections are given as per the connection diagram.
4. After executing the program,the low level in the tank is sensed and it is indicated by
green signal and the high level in the water tank is indicated by red signal.When
water reaches the high level the relay will be cut off.
RESULT
Thus water Pumb controller is designed to sense low and high in the water tank .
7
DIGITAL CLOCK
PROGRAM
#include <16F877A.H>
#use delay(clock=20000000)
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);
8
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);
9
set_rtc_time();
while(1)
get_rtc_time();
printf("T: %x : %x : %x \t",hour,minute,second);
//printf("D: %x : %x : %x \r\n",readtime[3],readtime[4],readtime[5]);
sprintf(rtc,"%02x:%02x:%02x ",hour,minute,second);
lcd_cmd(0xc0);
//data1(rtc);
data_display(rtc);
void set_rtc_time()
i2c_start();
i2c_write(0xa0);
i2c_write(0x02);
i2c_write(0x55);
i2c_write(0x15);
i2c_write(0x05);
i2c_stop();
void get_rtc_time()
i2c_start();
10
i2c_write(0xa0);
i2c_write(0x02);
i2c_stop();
i2c_start();
i2c_write(0xa1);
second = i2c_read(0);
i2c_stop();
i2c_start();
i2c_write(0xa0);
i2c_write(0x03);
i2c_stop();
i2c_start();
i2c_write(0xa1);
minute = i2c_read(0);
i2c_stop();
i2c_start();
i2c_write(0xa0);
i2c_write(0x04);
i2c_stop();
i2c_start();
i2c_write(0xa1);
hour = i2c_read(0);
i2c_stop();
11
{
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);
12
void lcd_init()
for(k=0;k<5;k++)
lcd_cmd(initi[k]);
CONNECTION DIAGRAM:
13
GND
GND Black
Vcc
Vcc Red
Sda
RC4 Yellow
Scl
RC3 Green
PROCEDURE
1. Compile the above CProgram using MPLAB IDE Software to create HEX file
2. Down Load the HEX file using PIC ISP software .
3. Connections are given as per the connection diagram.
4. After executing the program,the time will be displayed in the LCD display.
RESULT
Thus the digital clock is designed to display the time in the LCD display .
AIM:
14
To Write a C Program to display temperature value in the 7 segment using LM35
sensor.
APPARATUS REQUIRED
1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE.
4. VI SENSE 17 MODULE
SOFTWARE USED
PROGRAM
#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]);
15
i2c_stop();
i2c_start();
i2c_write(0x42);
i2c_write(arr[x2]);
i2c_stop();
void main()
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
while(1)
set_adc_channel( 2 );
value = read_adc();
value = value;
i=((int)(value));
i=(i*2);
if(i>=99){i=99;}
write_seg(i/10,i%10);
delay(48000);
CONNECTION DIAGRAM
16
GND
GND
Vcc Vcc
o/p
RA2
VI Sense 17
Module
PIC16F77A
PROCEDURE
RESULT
Thus the C Program was written to display the temperature value in the 7 segment using
LM35 sensor.
EX NO:5 PC COMMUNICATION
17
AIM:
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 CProgram using MPLAB IDE Software to create HEX file
2. Down Load the HEX file using PIC ISP software .
3. After executing the program,the message Vi Microsystems Pvt Ltd Chennai-95 will
be seen in the WINX TALK communication window with 9600 baudrate.
18
RESULT
Thus the above Cprogram to display the message in the serial window was executed
and verified successfully.
19
AIM:
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();
20
}
for(i=0;y[i]!='\0';i++)
putchar(y[i]);
void wait(int z)
int i;
for(i=0;i<z;i++)
void main()
while(1)
for(j=0;j<10000;j++)
printf("%c",a);
21
}
#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);
22
void lcd_dat(unsigned char dat)
output_high(pin_E0);
output_low(pin_E1);
delay(500);
output_D(dat);
delay(500);
output_high(pin_E2);
delay(500);
output_low(pin_E2);
void lcd_init(void)
lcd_cmd(0X38);
delay(500);
lcd_cmd(0X06);
delay(500);
lcd_cmd(0X0C);
delay(500);
lcd_cmd(0X01);
delay(500);
lcd_cmd(0X80);
delay(500);
23
{
output_high(pin_C0);
delay(500);
output_low(pin_C1);
output_low(pin_C2);
for(i=0;x[i]!='\0';i++)
output_D(x[i]);
output_high(pin_C2);
// delay_us(500);
delay(500);
output_low(pin_C2);
delay(500);
for(i=0;w[i]!='\0';i++)
lcd_cmd(add+i);
lcd_dat(w[i]);
delay(500);
24
void print()
// lcd_disp(arr,0x80);
lcd_disp(arr1,0xC0);
void main()
lcd_init();
// print();
while(1)
a=getch();
printf("%c",a);
lcd_cmd(0x8d);
lcd_dat(a);
// print();
//data1(x);
25
CONNECTION DIAGRAM IN RECEIVER SIDE
VCC RED
GND BLACK
5
YELLOW
9
4
8
3
7 RXD
2
6
1
PROCEDURE
26
1. Connections are given as per the connection diagram.
2. Compile the above CProgram using MPLAB IDE Software to create HEX file
3. Down Load the HEX file using PIC ISP software .
4. After executing the program,the message abcd will be displayed in the receiver
side.
RESULT
Thus the above Cprogram to establish a remote link between two microcontroller using
RF transmitter and receiver was implemented successfully.
27
AIM:
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();
28
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);
29
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
RESULT
Thus a hot chamber was designed to maintain the temperature say at 40 degrees centigrade
and C Program was compiled and executed successfully.
30
EX NO: 8 OBSTACLE DETECTOR USING ULTRASONIC
AIM:
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);
31
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);
32
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);
33
}
void print()
lcd_disp(arr,0x80);
void get()
do{;}while(getc()!='R');
void main()
lcd_init();
print();
while(1)
while(1)
get();
lcd_cmd(0xC0);
lcd_con(a1);
34
}
CONNECTION DIAGRAM
VCC
VCC RED
GND
GND BLACK
O/P
5
YELLOW
9
4
8
3
7
2
6
1
PROCEDURE
RESULT:
Thus an obstacle detection system was designed using ultrasonic sensor and C Program was
compiled and executed successfully.
35
EX NO: 9 SPRINKLER CONTROLLER
AIM:
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();
36
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
SPRINKLER
GND CONTROLLER MODULE
VCC
GND
BLACK
RA 1
VCC
RED
O/P
YELLOW
PIC16F877A
MOISTURE
SENSOR MODE
37
PROCEDURE
RESULT:
Thus a moisture sensor and sprinkler controller was designed and C Program was
compiled and executed successfully.
38
EX NO: 10 LAMP CONTROLLER
AIM:
To design a light sensor and real time clock to control a lamp for 1 minute delay.
APPARATUS REQUIRED
1. PIC16F877A KIT
2. 5 V ADAPTER
3. RS232 CABLE
4. RTC MODULE
5. LDR SET UP.
SOFTWARE USED
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--);
39
void set_rtc_time()
i2c_start();
i2c_write(0xa0);
//i2c_write(0x02);
//i2c_write(0x00);
//i2c_write(0x15);
//i2c_write(0x09);
i2c_stop();
void get_rtc_time()
i2c_start();
i2c_write(0xa0);
i2c_write(0x02);
i2c_stop();
i2c_start();
i2c_write(0xa1);
second = i2c_read(0);
i2c_stop();
i2c_start();
i2c_write(0xa0);
i2c_write(0x03);
i2c_stop();
40
i2c_start();
i2c_write(0xa1);
minute = i2c_read(0);
i2c_stop();
i2c_start();
i2c_write(0xa0);
i2c_write(0x04);
i2c_stop();
i2c_start();
i2c_write(0xa1);
hour = i2c_read(0);
i2c_stop();
void main()
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_rtc_time();
while(1)
get_rtc_time();
set_adc_channel( 1 );
value = read_adc();
i=(int)(value/2);
41
year = 0;
if(minute==0x00)
year=1;
if(minute==0x02)
year=1;
if(minute==0x04)
year=1;
if((year==1)|| (i>70))
output_high(PIN_D1);
output_low(PIN_D1);
42
CONNECTION DIAGRAM
RTC MODULE
SDA
YELLOW
SCK
GREEN
PC 4
VCC
RED
PC 3
GND
BLACK
VCC
GND
AD 1
VCC VCC
RED RED
RD 1
GND GND
BLACK BLACK
O/P RELAY O/P
PIC16F877A YELLOW YELLOW
LAMP SETUP
LDR MODULE
PROCEDURE
RESULT:
Thus the light sensor to control the lamp was designed and C Program was compiled