FMA Endsem
FMA Endsem
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)
// 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 ?
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.
.
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