0% found this document useful (0 votes)
15 views11 pages

FMA Endsem

The document provides a comprehensive overview of programming and interfacing with the 8051 microcontroller, including configuring ports, timer modes, and interrupt structures. It includes code examples for various tasks such as setting ports as input, starting timers, and copying data between ports. Additionally, it describes the ADC 0809 interfacing, data types, and the significance of various registers in the 8051 architecture.

Uploaded by

cartoonai7711
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views11 pages

FMA Endsem

The document provides a comprehensive overview of programming and interfacing with the 8051 microcontroller, including configuring ports, timer modes, and interrupt structures. It includes code examples for various tasks such as setting ports as input, starting timers, and copying data between ports. Additionally, it describes the ADC 0809 interfacing, data types, and the significance of various registers in the 8051 architecture.

Uploaded by

cartoonai7711
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Q.1) Write a program in C to configure Port as input port and Port pin P2.0 as input pin ?

Ans) #include <stdio.h>


// Define register addresses for the microcontroller (hypothetical addresses)
#define PORT1_DIRECTION_REG 0x1000 // Address for Port 1 direction register
#define PORT2_DIRECTION_REG 0x1001 // Address for Port 2 direction register
#define PORT2_PIN0_MASK 0x01 // Mask for Port 2 Pin 0

int main() {
// Set Port 1 as input port
// Assuming '0' for input and '1' for output in the direction register
*(unsigned char*)PORT1_DIRECTION_REG = 0x00; // Set Port 1 as input (all 0s)

// Set Port 2 Pin 0 as input pin


// First, set the bit corresponding to Port 2 Pin 0 to '0' for input
*(unsigned char*)PORT2_DIRECTION_REG &= ~PORT2_PIN0_MASK;

// Now, you can perform other operations or continue with your program logic

return 0;
}
Q.2) Draw the TCON and TMOD register and explain use of individual bits of TCON & TMOD register in
detail?
Ans) 1) TCON Register :
TF1 >TCON.7 :Timer 1 overflow flag. Set by hardware D7 D6 D5 D4 D3 D2 D1 D0
when timer/counter 1 overflows. Cleared by
hardware as the processor vectors to the interrupt
service routine >TR1 >TCON.6 :Timer 1 run control
bit. Set/cleared by software to turn timer/counter 1 TIMER 1 TIMER 0
on/off >TF0 >TCON.5 :Timer 0 overflow flag. Set by
hardware when timer/counter 0 overflows. Cleared by hardware as the processor vectors to the interrupt service
routine >TRO >TCON.4 :Timer 0 run control bit. Set/cleared by software to turn timer/counter 0 on/off >IE1
>TCON.3 :External interrupt 1 edge flag. Set by CPU when the external interrupt edge (H-to-L transition) is
detected. Cleared by CPU when the interrupt is processed >IT1 >TCON.2 :Interrupt 1 type control bit. Set/cleared
by software to specify falling edge/low- level triggered external interrupt >IEO >TCON.1 :External interrupt 0 edge
flag. Set by CPU when the external interrupt edge (H-to-L transition) is detected. Cleared by CPU when the interrupt
is processed >ITO >TCON.0 :Interrupt 0 type control bit. Set/cleared by software to specify falling edge/low- level
triggered external interrupt
2) TMOD Register :
Bit 7/3 > Symbol GATE > Function: OR Gate D7 D6 D5 D4 D3 D2 D1 D0
enable bit which controls RUN / STOP of timer
1/0. Set to 1 by program to enable timer to
run if bit TR1 / 0 in TCON is set and signal on
external interrupt INT1/0 pin is high. Cleared
to O by program to enable timer to run if bit TR1 / 0 in TCON is set. >Bit M1 M0 Mode Operation Mode
6/2 >symbol C/T : Set to 1 by program to make timer 1 / 0 act as a 0 0 0 13 bit timer mode
counter by counting pulses from external input pins P2.5 (T1) or P2.4 0 1 1 16 bit timer mode
(TO). Cleared to O by program to make timer act as a timer by counting 1 0 2 8 bit timer mode
internal frequency. >Bit 5/1 > Symbol M1: Mode selection bit. >Bit 4/0 1 1 3 Split timer mode
> Symbol M0 : Mode selection
Q. 3) State the stapes to generate time delay
Ans- : 1. Load TMOD register indicating timer 0 is used and mode 1 is selected. >2. Load TLO and THO registers
with count values. >3. Start the timer by setting TRO bit = 1.
4. Monitor the timer flag (TF0) with the JNB TFO, target address instruction. When it is raised, get out of the loop.
5. Stop the timer by clearing TRO bit = 0 with CLR TRO instruction.
6. Clear TFO flag with CLR TFO instruction.
Q4) Explain the function of bit TFO in TCON register and write a program in C language to start timer 0?
Ans) TF0 >TCON.5 BIT :Timer 0 overflow flag. Set by hardware when timer/counter 0 overflows. Cleared by
hardware as the processor vectors to the interrupt service routine >
#include <REG51.h> // Include the 8051 header file (modify based on your microcontroller)
void main() {
TMOD = 0x01; // Timer 0, Mode 1 (16-bit timer mode)
TH0 = 0x00; // Load initial value for Timer 0's high byte
TL0 = 0x00; // Load initial value for Timer 0's low byte
TR0 = 1; // Start Timer 0
while(1) {
// Your main program logic here
}
}
Q5) Write a program in C language to copy the contents of Port 2 to Portal 1?
Ans) #include <REG51.h> // Include the 8051 header file (modify based on your microcontroller)
void main() {
unsigned char port2_data;
while(1) {
// Read data from Port 2
port2_data = P2;
// Copy the data to Port 1
P1 = port2_data;
}
}
Q6) Describe the Timer modes in 8051 microcontrollers ?
Ans) The 8051 microcontroller has FOUR timer modes: Mode 0, Mode 1, Mode 2 and Mode 3 . Each mode provides
different functionality and is suitable for different timing requirements. Here's a brief description of each mode: >
1. Timer Mode 0 (13-bit Timer): 13-bit timer (TL-5-bits and TH-8-bits). Counter overflow is indicated by time
interrupt flag 2.>Timer Mode 1 (16-bit Timer): 16-bit timer (TL-8-bits and TH-8-bits) Rest is same as mode 0.>
3.Timer Mode 2 (8-bit Timer): Automatic reload mode, 8-bit counter (TL-8-bit) overflow from. >TL not only sets TF,
but also reloads TL with the contents of TH. > 4.Timer Mode 3 : Establishes TL and TH as two separate counters
Q.7) Write a short note on C Data types for 8051 microcontroller.?
Data type Size in bits Range or usage
Unsigned char 8 0 to 255 (00H to FFH)
(Signed) Chr 8 - 128 to +127
Signed short 16 -32768 to +32767
Unsigned short 16 0 to 65535
Unsigned int 16 0 to 65535 (0000H to FFFFH)
(Signed) int 16 - 32768 to +32767
S bit 1 Bit addressable locations of SFRS
Bit 1 Bit addressable locations of internal RAM
SFR 8 SFR locations of 8051 i.e. 80 H to FFH (only used locations)
SFR 16 16 0 to 65535
enum 8/16 -128 to +127 or - 32768 to +32767
Signed long 32 - 2147483648 to 2147483647
Unsigned long 32 0 to 4294967295
Q. 8) Write a program in C to toggle all bits of Port 1.? [Means start next line]
Ans-#include <REG51.h> // Include the 8051 header file (modify based on your microcontroller)
void main() {
while(1) {
P1 = ~P1; // Toggle all bits of Port 1
}
}
.
Q.9) Explain interrupt structure of 8051 microcontroller with neat diagram ?
Ans) The 8051 provides 5 interrupt sources. These are shown in
Fig. Q.3.1. The external Interrupts INTO and INTI can each be
either level-activated or transition-activated, depending on bits
ITO and IT1 in Register TCON. The flags that actually generate
these interrupts are bits IEO and IE1 in TCON. When an external
interrupt is generated, the flag that generated it is cleared by the
hardware when the service routine is vectored to only if the
interrupt was transition-activated. If the interrupt was level-
activated, then the external requesting source is what controls the
request flag, rather than the on-chip hardware. > The Timer 0 and
Timer 1 interrupts are generated by TFO and TF1, which are set by
a rollover in their respective Timer/Counter registers (except see
Timer 0 in Mode 3). The timer flag set upon generation of
interrupt is cleared by the on-chip hardware when microcontroller
starts execution of particular interrupt service routine. > The serial
port interrupt is generated by the logical OR of RI and TI. Neither
of these flags is cleared by hardware when the service routine is
vectored to service routine. In fact, the service routine will normally have to determine whether it was RI or TI that
generated the interrupt and the bit will have to be cleared in software.
Q. 10) Write down the steps to program ADC 0809 ?
Ans- Select the desire channel by sending address of channel on ADD A, ADD B and ADD C lines. > 2. Send the ALE
signal. >3, Send Start of Conversion (SOC) signal. > 4 Wait for End of Conversion (EOC) Signal. > 5. Read data by
enabling Output Enable (OE) signal.
Q11) Explain interfacing of ADC 0809 with 8051 microcontrollers With Diagram ?
Ans- ADC 0809 > The ADC0808, ADC0809 data acquisition component is a Monolithic CMOS device with an 8-bit
analog-to-digital converter, 8-channel multiplexer and microprocessor compatible control logic. The 8-bit A/D
converter uses successive approximations the conversion technique. The converter features a high Impedance
chopper stabilized comparator, a 256R voltage divider with analog switch tree and a successive approximation
register. > INTERFACING ADC 0809 WITH 8051 > 8051 microcontroller it doesn’t have an On chip ADC to accept
the digital input, it will not accept analog input, so we need a ADC to process the analog signal. For interfacing ADC
0809 we require 8 data lines. So ADC 0809 is an 8 bit ADC has 8 channels works on successive approximation
conversion technique
Q. 12) Write short note on IE (Interrupt enable) Register ?

Symbol Position Name and Significance


EA IE.7 Enable all control bit. >Cleared by software to disable all interrupts, independent
of Uie state of IE.4-IE.O.
- IE.6 (Reserved)
ET2 IE.5 (Reserved)
ES IE.4 Enable Serial port control bit. > Set/cleared by software to enable/disable
interrupts from TI or RI flags.
ET1 IE.3 Enable Timer 1 control bit. > Set/cleared by software to enable/disable interrupts
. from timer/counter 1
EX1 IE.2 Enable External interrupt 1 control bit. > Set/cleared by software to enable/
disable interrupts from INT1
ET0 IE.1 Enable Timer O control bit. > Set/cleared by software to enable/disable interrupts
. from timer/counter 0 .
EX0 IE.0 Enable external interrupt O control bit. > Set/cleared by software to
enable/disable Interrupts from INTO.
Q. 13) Explain the SOC, EOC, OE, (ADD A, ADD B, and ADD C), START, OUTPUT ENABLE, pin of ADC 0809 ?
Ans- : ADC 0808/0809 has eight input channels, so to select desired input channel, it is necessary to send 3-bit
address on A, B and C inputs. The address of the desired channel is sent to the multiplexer address inputs through
port pins. After at least 50 ns, this address must be latched. This can be achieved by sending ALE signal. After
another 2.5 us, the Start of Conversion (SOC) signal must be sent high and then low to start the conversion process.
To indicate end of conversion ADC 0808/0809 activates EOC signal. The microprocessor system can read converted
digital word through data bus by enabling the output enable signal after EOC is activated
Q. 14) Write down the steps in executing on an interrupt.?
Ans-In response to the interrupt, the microcontroller goes through following steps: >1. It completes the execution
of current instruction and save the address of the next instruction, i.e. the contents of PC on the stack. > 2. It also
saves the current status of all the interrupts internally i.e. not on the stack. >3. It then transfers the program control
to a fixed location in memory called the Interrupt Vector Table (IVT). IVT holds the address of the interrupt service
routine. > 4. The microcontroller gets the address of the Interrupt Service Routine (ISR) from IVT and transfers
program control to the ISR. It executes instructions within the interrupt service routine in sequence till it reaches
the RETI (Return From The Interrupt) instruction. >5. Upon executing the RETI instruction, it gets the Program
Counter (PC) address from the stack and restores the interrupt logic. Since PC is loaded with the address of the
next instruction from where the interrupt was initiated, it starts to execute from that address.
Q.15) Explain (IP) Interrupt Priority Register of 8051 Microcontroller ?

Symbol Position Name and significance


- IP.7 (Reserved)
- IP.6 (Reserved)
- IP.5 (Reserved)
PS IP.4 Serial port Priority control bit. >Set/cleared by software to. specify high/low priority
Interrupts for Serial port.
PT1 IP.3 Timer 1 Priority control bit. > Set/cleared by software to specify high/low priority Interrupts
for timer/counter 1.
PX1 IP.2 External interrupt 1 Priority control bit. > Set/cleared by software to specify high/low priority
interrupts for INT1
PT0 IP.1 Timer O Priority control bit. > Set/cleared by software to specify high/low
priority Interrupts for timer/counter 0
PX0 IP.0 External interrupt O Priority control bit. Set/cleared by software to specify high/low priority
interrupts for INTO
Q. 16) Write Short note on SCON register.?

Symbol Position Name and significance


SM0 SCON.7 Serial port Mode control bit 0. >Set/cleared by software
SM1 SCON.6 Serial port Mode control bit 1. > Set/cleared by software
SM2 SCON.5 Serial port Mode control bit 2. >Set by software to disable reception of frames
for which bit 8 is zero.
REN SCON.4 Receiver Enable control bit. Set/cleared by software to enable/disable serial
data reception..
TB8 SCON.3 Transmit Bit 8. >Set/cleared by hardware to determine state of ninth data bit
transmitted in 9-bit UART mode
RB8 SCON.2 Receive Bit 8. >Set/cleared by hardware to indicate state of ninth data bit
received.
TI SCON.1 Transmit Interrupt flag. >Set by hardware when byte transmitted. Cleared by
software after servicing.
RI SCON.0 Receive Interrupt flag. >Set by hardware when byte received. Cleared by
software after servicing
Note : The state of (SMO, SM1) selects:
Mode SMO SM1
0 0 0 - Shift register; baud = f/12
1 1 1 - 8-bit UART, variable data rate.
2 1 0 - 9-bit UART, fixed data rate;
3 baud = f/52 or f/64
. 1 1 - 9-bit UART, variable data rate.
Q. 17) Explain Steps to transfer Data Serially in 8051 microcontroller ?
Ans- To program 8051, to transfer data serially we have to perform following sequence of actions: >1. Load the
TMOD register with the value 20H to use timer 1 in mode 2 (8-bit auto-reload) to set the baud rate. > 2. Load TH1
to set the desire baud rate for serial data transfer. >3.Load SCON register with the value 50H, to use serial mode
1, where an 8-bit data is framed with start and stop bits. > 4. Set TR1 to 1 to start timer 1. > 5. Clear TI with CLR TI
instruction. > 6. Write a character to be sent in to the SBUF register. > 7. Check the TI flag bit with instruction JNB
TI, XXXX to see if the character has been transferred completely. > 8. Go to step 5 to transfer the next character.
Q. 18) Explain Steps to receive Data Serially in 8051 microcontroller.?
Ans- To program 8051, to receive data serially we have to perform following sequence of actions: > 1. Load the
TMOD register with the value 20H to use timer 1 in mode 2 (8-bit auto-reload) to set the baud rate. > 2. Load TH1
to set the desire baud rate for serial data transfer. > 3. Load SCON register with the value 50H, to use serial mode
1, where an 8-bit data is framed with start and stop bits. > 4. Set TR1 to 1 to start timer 1. > 5. Clear RI with CLR RI
instruction. > 6. Check the RI flag bit with instruction JNB RI, XXXX to see if an entire character has been received
yet. > 7. If RI is set, SBUF has the byte. Save this byte. >8. Go to step 5 to receive the next character.
Q. 19) Explain Serial port structure of 8051 microcontroller ?
Ans- The 8051 microcontroller has an integrated Serial Port (UART) that allows for serial communication with
external devices. The serial port structure of the 8051 consists of several registers and control bits that facilitate
the configuration and operation of the UART module. Here's an explanation of the serial port structure of the 8051
microcontroller: >1. SBUF (Serial Data Buffer): •SBUF is an 8-bit register used for storing the data to be transmitted
or the data received through the serial port. • >2.SCON (Serial Control):•SCON is an 8-bit register that controls the
operation of the UART module•SM0 and SM1 (Serial Mode Select): •These two bits determine the operating mode
of the UART module. •SM2 (Multiprocessor Communication Enable): •SM2 is used in multiprocessor
communication mode. •When SM2 = 0, the microcontroller operates as a standard UART3. PCON (Power Control):
•PCON is a control register that includes the SMOD bit for selecting the UART baud rate. •SMOD = 0 provides a
standard baud rate, while SMOD = 1 provides a double baud rate. 4. Baud Rate Generator: •The 8051
microcontroller uses a Baud Rate Generator (BRG) to generate the appropriate clock for serial
communication.•The BRG is configured based on the desired baud rate and the system clock frequency.
5. TxD and RxD Pins: •The TxD (Transmit Data) and RxD (Receive Data) pins are used for the physical connection
of the microcontroller with external devices for serial communication. •TxD is an output pin for transmitting data,
while RxD is an input pin for receiving data.
Q.20) Write short note AT commands required for GSM
Ans- AT commands are a set of instructions used to control and communicate with GSM (Global System for Mobile
Communications) modules in mobile devices. These commands are sent to the GSM module via a serial interface
(UART). Here is a brief overview of some common AT commands used for GSM communication: 1. AT (Attention):
The basic command to check the communication with the GSM module. It should respond with "OK" if the
communication is established. 2. AT+CPIN (Enter PIN): Used to enter the PIN (Personal Identification Number) for
accessing the SIM card. 3. AT+CMGF (Message Format): Sets the SMS (Short Message Service) message format.
Typically set to either text mode (AT+CMGF=1) or PDU mode (AT+CMGF=0). 4. AT+CSCA (Service Center Address):
Sets or queries the service center address for SMS messages. 5. AT+CMGS (Send SMS): Used to send an SMS
message. Followed by the recipient's phone number and the message content. 6. AT+CMGL (List Messages): Lists
SMS messages stored in the SIM card or module memory. 7. AT+CMGD (Delete Message): Deletes an SMS
message. Used with the index of the message. 8.ATD (Dial): Initiates a voice call. Followed by the phone number
to be dialed. 9.ATH (Hang-Up): Ends an ongoing voice call.
Q. 21) Write down a short note on interfacing of a GSM module with 8051 microcontroller
Ans- Interfacing a GSM (Global System for Mobile Communications) module with an 8051 microcontroller involves
establishing communication between the two to enable functionalities such as sending SMS messages and making
voice calls. The GSM module typically communicates with the 8051 through a UART (Universal Asynchronous
Receiver/Transmitter) interface. The basic steps include configuring the serial communication parameters,
initializing the GSM module, and implementing specific AT commands for desired functionalities. The 8051's UART
is configured to match the communication settings of the GSM module, including baud rate, data bits, stop bits,
and parity. AT commands, a standardized set of instructions for GSM modules, are then sent from the 8051 to the
GSM module to perform operations such as sending SMS messages or making voice calls. Responses from the GSM
module can be read by the microcontroller to determine the success or status of the executed commands.
Interfacing a GSM module with an 8051 microcontroller enables embedded systems to integrate cellular
communication capabilities, providing a platform for remote monitoring, control, and communication in various
applications.

Q. 22) Explain how the BAUD rate is set for serial communication in 8051 microcontroller.?
Ans- In serial communication the rate at which data bits are transmitted generates a term Baud rate. The Baud
rate is defined as bits/second or the changes in voltage levels/ second.
Baud = (Bit transmitted / Second)
Typical Baud rates are 110, 300, 600, 1200, 2400, 4800 and 9600. A teletype typically uses 110 Baud.
Transmission rate = 110 Baud 110 bits/sec.
Time for one bit = (1/110) = 9.1 ms.
Q. 23) Explain LED interfacing with 8051 microcontroller. ?
Ans- A typical LED consumes 10 to 15 mA. Thus we cannot drive LED directly in current source mode as shown in
the Fig. (a). However, we can drive LED directly in current sink mode, as shown in the Fig. (b). Here, sinking current
of 8051 is not enough to drive LED, so the brightness of LED is poor.

We can use driver transistor to solve the problem of current sinking and sourcing. The Fig. shows the LED interface
using driver transistor. > In Fig. (a), the source current of 8051 port pin is amplified by the npn transistor to drive
the LED. In Fig. Q.14.2 (b), the pnp transistor is used to amplify the sinking current

Where, VLED is the voltage across LED > ILED is the current through LED > Vout is the voltage at output pin > ẞ is the
current gain (Beta) of the transistor
Q. 24) With the help of block diagram explain Power measurement using 8051 ?
Ans- For a sinusoidal wave the power consumed in a circuit is given
by, > P = Vrms Irms CosØ = K1 Vm cos K2 Idc > P = KVm CosØ
Idc as Idc ∝ Irms >The instantaneous value of voltage at the
instant where peak current is observed is V cos o as shown in Fig.
8.5.4. >Inorder to obtain a pulse at the instant of peak current a
phase shifter and zero-cross detector is used.
-The current signal is applied to the phase shifter to get a phase shift
of 90°.
-Then the output of the phase shifter is given to the zero-crossing
detector as shown in Fig.
-The microcontroller reads and examines the output of the zero-
cross detector as to whether the pulse has occurred.
-If the pulse is present, it indicates that the current signal is at its
peak
-At this instant the microcontroller sends a command to the multiplexer to switch on the required channel Inorder
to obtain the instantaneous value of the voltage that is equal to Vm CosØ
Q. 25) Draw interfacing diagram of a stepper motor with 8051 and write program to rotate stepper
motor 360 Degree in anticlockwise direction with step angle of 1.8 degree ?
Ans- A stepper motor is a digital motor. It can be driven by digital signal. Fig. Q.4.1 shows the typical 2 phase motor
interfaced using 8051. Motor shown in the circuit has two phases, with cer.tre-tap winding. The centre taps of
these windings are connected to the 12. V supply. Due to this, motor can be excited by grounding four terminals
of the two windings. Motor can be rotated in steps by giving proper excitation sequence to these windings. The
lower nibble of port 1 of the 8051 is used to generate excitation signals in the proper sequence.

program to rotate the stepper motor In anticlockwise direction through an angle of 180 degrees. The stepper
motor Is controlled through the least significant 4 pins of port 1 of 8051 microcontroller.
Q. 26) With the help of block diagram explain Voltage & current measurement using 8051. ?
Ans- • For the electronic measurement of voltage, current and power in the range of kV, kA and kW we need
current transformer and voltage transformer. >• A Current Transformer (CT) is a type of instrument transformer
designed to provide a current in its secondary winding proportional to the alternating current flowing in its primary.
>• CT not only steps down the current, but it also isolates measurement and control circuitry from the high voltages
typically present on the circuit being measured. >• Similarly, Potential Transformers (PT) are used for voltage
measurement. >•Fig. Q.1.1 shows the block diagram for current and voltage measurement system using 8051
microcontroller. >• I to V Converter: It is used to convert current signal into voltage signal. >• Level Shifter: It is
used to shift the a.c. signal such that it is in the range of 0-5 V, as shown in Fig. >• ADC: It is used to convert the
analog values of current and voltage into digital values with known sampling frequency.

*Only For AC voltage measurement


Voltage Measurement : To measure voltage using the 8051 microcontroller , you need to utilize analog to digital
converter > The analog to digital converter allows the microcontroller to convert voltage value into digital values
> Potential Transformers (PT) are used for voltage measurement. > The output of PT to is given to level shifter >•
Level Shifter: It is used to shift the a.c. signal such that it is in the range of 0-5 V >• ADC: It is used to convert the
analog values of current and voltage into digital values with known sampling frequency.
* Only For AC current measurement
A Current Transformer (CT) is a type of instrument transformer designed to provide a current in its secondary
winding proportional to the alternating current flowing in its primary. >>• I to V Converter: It is used to convert
current signal into voltage signal which is proportional to current signal . > Level Shifter: It is used to shift the a.c.
signal such that it is in the range of 0-5 V >• ADC: It is used to convert the analog values of current and voltage into
digital values with known sampling frequency.
Q. 27) How to measure power factor using 8051 microcontroller.?
Ans- Digital values for voltage and current signals are stored in memory. > These digital values are compared with
the digital value corresponds to 0 V to find the zero crossing. In our case, the digital equivalent for zero voltage is
80H. > The number of samples between voltage zero crossing and current zero crossing N are noted. N × Sampling
time gives the time between two zero crossings and it is proportional to the phase angle between voltage and
current signals.
Q. 28) Explain the function of an electromechanical relay and draw an interfacing diagram of relay with
microcontroller 8051 with suitable drive circuit. ?
Ans- A relay is an electrical switch that opens and closes
under the control of another electrical circuit. In the original
form, the switch is operated by an electromagnet to open or
close one or many sets of contacts. > It consists of a coil of
wire surrounding a soft iron core, an iron yoke, which
provides a low reluctance path for magnetic flux, a moveable
iron armature, and a set, or sets, of contacts. > The armature
is hinged to the yoke and mechanically linked to a moving
contact or contacts. It is held in place by a spring so that when
the relay is de- energized there is an air gap in the magnetic
circuit. In this condition, one of the two sets of contacts in the
relay is closed, and the other set is open. >When an electric current is passed through the coil, the resulting
magnetic field attracts the armature, and the consequent movement of the movable contact breaks a connection
with a fixed contact and makes connection with the other contact. >Fig. illustrates the symbol of relay and
interfacing of a relay with 8051. Simply making the pin '0' or '1' will switch ON/OFF the relay.
function of an electromechanical relay:
1. Switching Function: The fundamental purpose of a relay is to act as a switch. When an electrical current is
applied to the coil (electromagnet), it generates a magnetic field that attracts or repels an armature or movable
contact.
2. Isolation: Relays provide isolation between the control circuit (the coil side) and the load circuit (the contact
side). This separation helps protect sensitive control systems from high-voltage or high-current loads, preventing
damage or interference. > 3.Amplification: Relays can be used to amplify a signal. A small electrical signal applied
to the coil can control a much larger current or voltage on the load side of the relay, allowing the control of heavy
loads using low-power control signals. > 4.Control Logic: Relays are integral components in various control
systems, such as industrial automation, HVAC (heating, ventilation, and air conditioning), automotive, and more.
> 5. Protection: In some cases, relays offer protection features such as overload protection, where they can be
designed to trip or disconnect a circuit when the current exceeds a certain threshold, preventing damage to the
system or components. > 6.Latching Function (Latching Relay): Some relays have a latching mechanism that
maintains the last state (either open or closed) even after the control signal is removed. This eliminates the need
for continuous power to keep the relay in its switched state. > 7.Signal Routing: Relays are used for signal routing
in various applications, allowing one input to be connected to multiple outputs or vice versa.

.
Q. 29) With the help of block diagram explain Key interfacing using 8051 .?
Ans- Here eight keys are individually connected to specific pins of port P1. Each port pin gives the status of key
connected to that pin. When port pin is logic 1, key is open, otherwise key is closed.
Software routine to get keycode with key debounce.
START: MOV A, P1 Read key status
: check if keys are open
CJNE A,#FFH,START : if no, goto stert
: otherwise continue
PRO : LCALL DEBOUNCE_DELAY : call debounce delay
AGAIN: MOV A, P1 :Read key status
:check if any key is
: pressed
LJMP AGAIN : if no, gotc AGAIN
: otherwise
: continue
PRO1: LCALL DEBOUNCE_DELAY :call debounce delay
MOV A, P1 : Get key code
RET : Return Form
:subroutin

Q. 30) Draw and explain interfacing of LED in common anode and common cathode configurations. Write
a program in C language for blinking display of a LED connected to port pin P1.0. Use a suitable delay
Ans) common anode type fig in common anode types LED a Anode terminal is connected together as
shown in above fig The supply is given to cathode only the anode terminal is conn Ected to +ve supply
>>when the GND is connected to cathode Then LED become ON 2) common cathode type / in common
Cathode type connection all the cathod terminal are connected Together >>the supply is given to anode
only the cathode terminal Is connected toGND>> when the +vcc is given to anode LED becomes ON .

ss

You might also like