Relay is an electrical control device, it is when the input (such as voltage, current, temperature, etc.) to reach the specified value , so that the controlled amount of a step change of an electrical apparatus.
For example: we only need to use a 12v,0.1a number to control a relay, and then let the relay to act as a millions of volt, millions of amp device switch.
Relays can be used wherever possible, if you want to keep the controller in a safe environment. Let's go to the safe side and let the relays go to the dangerous side, as long as we control the action of the relays, the relays will help us connect some of the lines that we don't want to touch personally.
The classification of relays is thousands, here is not much to say.
Recently because there seems to be no place to use, here first give the most basic through the key to control the relay switch program source code, later if there are other uses, then again.
1 /****************************2 Experiment name: Key control relay3 experimental time: 2014/12/204 Experimental connection: relay connected to the chip p1^4 end, K1 button to connect the p0^0 end of the chip5 *****************************/6#include <reg51.h>7 8Sbit relay = p1^4;//define the IO port used by the relay9Sbit key = p0^0;//define the IO port used by the keyTen One voidMain () A { - while(1) - { the //according to the independent key principle, there is a high level when there is no key pressed, low when the key is pressed down - if(Key = =1) -relay =1;//The key is not pressed and the relay is disconnected. - Else +relay =0;//Press the key and the relay is closed - } +}
Experimental results: When the button is pressed, the relay is closed, the DK Light is on, and the DK lamp is not lit.
[51 Microcontroller Learning note three]----relays