Interfacing Relay With 8051

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 6

Interfacing Relay

with 8051
Microcontroller
www.pantechsolutions.net
RELAY INTERFACE WITH 8051

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt


WHAT IS RELAY?

• A relays is an electrical switch that opens and closes under control of


another electrical circuit.
• It is therefore connected to ouput pins of the microcontroller and used to
turn on/off high-power devices such as motors, transformers, heaters,
bulbs, antenna systems etc
• Relay is connected to port 1.0

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt


RELAY INTERFACING ASSEMBLY CODE

org 00h
back: mov a,#00h
mov P1,a
acall secdelay
mov a,#01h
mov P1,a
acall secdelay
Sjmp back
Secdelay: mov r5,#25
H3: mov r4,#55
H2: mov r3,#ff
Djnz r3,h1
Djnz r4,h4
Djnz r5,h5ret

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt


RELAY INTERFACE C CODE
#include <reg51.h>
#include<stdio.h>
sbit relay1 = P0^4;
void DelayMs(unsigned int);
void main (void)
{
P2 = 0;
while(1)
{
relay1 = 1;
DelayMs(200);
relay1 = 0;

DelayMs(200);
}
} void DelayMs(unsigned int n)
{
unsigned int i,j;
for(j=0;j<n;j++)
{
for(i=0;i<1000;i++);
}
}

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt


For More Tutorials
www.pantechsolutions.net
http://www.slideshare.net/pantechsolutions
http://www.scribd.com/pantechsolutions
http://www.youtube.com/pantechsolutions

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt

You might also like