Search Inside My Blog

Monday, November 8, 2010

Interfacing Relays with 8051



    Relays allow us to control the high power circuits or instruments using low power circuits and voltage levels such as output of microcontrollers. Interfacing relays to 8051 or any other microcontroller is just simple as controlling a LED.
    A relay consists of a coil which is driven by low power circuits such as microcontrollers in order to control high power ac circuits through output switches. Normally there are two types of switches in a relay, they are Normally Open (NO) and Normally Closed (NC) contacts. 'NO' contacts are open when relay is not activated where as the 'NC' contacts are closed, when relay is activated by supplying power to the input coil, the 'NO' contacts are now closed and the 'NC' contacts are open.

The circuit diagram for interfacing relay to a 8051 microcontroller is shown below.
The assembly program for interfacing relay is given below.
;*************************************************
;
;Program: Interfacing relay
;Author: Mahesh
;Description: Relay turns ON when the switch
;connected to P1.0 and turns OFF when pressed
;again
;
;*************************************************

relay equ P0.0
sw equ P1.0

;*************************************************
org 0000h

Main:clr relay        ;Configure inp and outp       
     setb sw
up:  jnb sw,on        ;wait for switch to be pressed
     clr relay
     acall delay
     sjmp up
on:  setb relay       ;Turn ON relay
     acall delay
     acall delay
here:jb sw,here       ;wait for switch to be released
     clr relay        Turn OFF relay
     acall delay
     acall delay
     sjmp up          ;Loop

;*************************************************
delay:mov r7,#0ffh    ;delay subroutine
again:mov r6,#0ffh
     djnz r6,$
     djnz r7,again
     ret

;*************************************************
end 

No comments:

Post a Comment