Вы находитесь на странице: 1из 2

#include <REGX51.

H>
#define adc_port P2
#define rd P1_0
#define wr P1_1
#define cs P1_2
#define intr P1_3

//ADC Port
//Read signal P1.0
//Write signal P1.1
//Chip Select P1.2
//INTR signal P1.3

void conv();
void read();

//Start of conversion function


//Read ADC function

unsigned char adc_val;


void main() {
while (1) {
conv();
read();
P3 = adc_val;
}
}

//Forever loop
//Start conversion
//Read ADC
//Send the read value to P3

void conv() {
cs = 0;
wr = 0;
wr = 1;
cs = 1;
while (intr);
}

//Make
//Make
//Make
//Make
//Wait

CS low
WR low
WR high
CS high
for INTR to go low

void read() {
cs = 0;
rd = 0;
adc_val = adc_port;
rd = 1;
cs = 1;
}

//Make
//Make
//Read
//Make
//Make

CS low
RD low
ADC port
RD high
CS high

Relay concept in 8051 microcontroller and its interfacing


By ankur bhardwaj 7:19:00 AM embedded
A relay is an electrically operated switch or an electromechanical switch. Relay
s are used where it is necessary to control an electronic circuit by a low-power
signal or where several circuits must be controlled by one signal.
Principle:
Current flowing through the coil of the relay creates a magnetic field which att
racts a lever and changes the switch contacts. The coil current can be on or off
so relays have two switch positions and most have double throw (changeover) swi
tch contacts.
Construction and working:
Relays are made up of electromagnet and a set of contacts generally based on Sin
gle Pole Double Throw (SPDT) or Double Pole Double Throw (DPDT) switching method
. It has 3 pins to perform function
COM = Common, always connect to NC; it is the moving part of the switch.
NC = Normally Closed, COM is connected to this when the relay coil is off.
NO = Normally Open, COM is connected to this when the relay coil is on.
Relays allow one circuit to switch a second circuit which can be completely sepa
rate from the first. For example a low voltage battery circuit can use a relay t
o switch a 230V AC mains circuit. There is no electrical connection inside the r
elay between the two circuits; the link is magnetic and mechanical.

An electric current through a conductor will produce a magnetic field at right a


ngles to the direction of electron flow. If that conductor is wrapped into a coi
l shape, the magnetic field produced will be oriented along the length of the co
il. The greater the current, the greater the strength of the magnetic field, all
other factors being equal:
It can be connected to any port of the microcontroller according to your circuit
diagram. It is generally connected to P2 or P3 port of the 8051 microcontroller
and thus, used to control the high power devices like motors, transformers, hea
ters and bulbs etc.
Interfacing:
Interfacing with Bulbs
Interfacing with Motor
Code:
#include "REG52.h"
sbit RELAY1=P3^2;
long int i;
void main()
{
RELAY1=0;
for(j=0;j<15000;j++);
while(1)
{
for(i=0;i<6;i++) // run loop for 6 times ON/OFF
{
RELAY1=0;
for(j=0;j<15000;j++);
RELAY1=1;
for(j=0;j<15000;j++);
}
}

Вам также может понравиться