0% found this document useful (0 votes)
8 views

Elec-1 sem3

Important notes

Uploaded by

krishnajagave
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Elec-1 sem3

Important notes

Uploaded by

krishnajagave
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Q) Explain addressing modes of 8051 microcontroller?

1. Register Addressing: • In 8051, there are 8 registers named from R0 to R7.


• Instructions using register addressing are encoded using the three least-significant
bits of the instruction opcode to specify a register within this logical address space.
• The 8051 assembly language indicates register addressing with the symbol Rn where
n is from 0 to 7.
2. Direct Addressing: • Direct addressing can access any on-chip variable or
hardware register.
• Depending on the higher order bit of the direct address, one of two on-chip memory
is selected.
• When bit 7 = 0, the direct address is between 0 to 127 (00h-7FH) and 128 low-order
on-chip RAM locations are referenced.
• The direct and indirect addressing modes are used to distinguish between the SFR
space and data memory space.
3. Indirect Addressing: • In 8051 assembly language, indirect addressing is
represented by a ‘@’ sign preceding R0 or R1.
• In the register indirect addressing mode, a register is used as a pointer to the data.
Only register R0 and R1 are used for internal RAM indirect data transfer.
• Indirect addressing is essential for stepping through sequential memory locations.
4. Immediate Addressing: • When a source operand is a constant rather than a
variable, then the constant can be incorporated into the instruction as a byte of
‘immediate’ data.
• In this addressing mode, the source operated is a constant i.e. immediate data. Here,
the immediate data must be preceded by the sign"#".
5. Relative Addressing: • Relative addressing is used only with certain jump
instructions. A relative address is 8-bit signed value, which is added to the program
counter to form the address of the next instruction executed. The range of for jumping
is from −128 to +127 locations.
• The relative instructions are based on the value of the program counter.
Q) Which pin is used to demultiplex address and data bus in 8051?
Answer: Pin ALE (Address Latch Enable) is used to demultiplex the address and
data bus in 8051.
• It separates the lower 8 bits of the address (A0–A7) from the data on Port 0.
Q) In which addressing mode '@' symbol is used?
Answer: The '@' symbol is used in indirect addressing mode in 8051.
• For example: MOV A, @R0 means move the contents of the memory location
pointed to by register R0 into accumulator A.
Q) Which bit of IE register (Interrupt Enable) is used to enable all interrupts?
Answer: EA (Enable All) bit, which is bit 7 (MSB) of the IE register, is used to
enable or disable all interrupts globally.
• When EA = 1, individual interrupt enables are considered.
• When EA = 0, all interrupts are disabled.
Q) Which instruction is used to start and stop the timers in 8051
microcontroller?
Answer: The SETB TRx and CLR TRx instructions are used.
• SETB TR0 or SETB TR1 to start Timer 0 or 1.
• CLR TR0 or CLR TR1 to stop Timer 0 or 1.
Q) What is step size of 8-bit ADC if Vin is 2.56 volt?
Answer: Step size = Reference Voltage / (2⁸ – 1) = 2.56 V / 255 ≈ 0.01 V or 10 mV
Q) Which pin of LCD selects command and data register?
Answer: The RS (Register Select) pin of the LCD is used to select command or data
register.
• RS = 0 → Command register
• RS = 1 → Data register
Q) Write any three features of 8051
1. 8-bit CPU with 16-bit address bus.
2. 128 bytes of internal RAM and 4 KB ROM.
3. Two 16-bit timers, 5 interrupt sources, and 32 I/O lines.
Q) Explain in brief interfacing of DAC with 8051
• A Digital-to-Analog Converter (DAC) converts digital signals from 8051 to
analog voltage.
• Typically, a DAC like DAC0808 is connected to one port (e.g., Port 1) of the 8051.
• The 8051 outputs an 8-bit digital value which the DAC converts to a proportional
analog voltage.
• A resistor and op-amp (as current-to-voltage converter) are often used with the
DAC output.
Q) Explain any 3 assembler directives of 8051
1. ORG: Sets the starting address of the program.
o Example: ORG 0000H
2. END: Marks the end of the source code file.
3. EQU: Assigns a constant value to a name.
o Example: COUNT EQU 30H (COUNT will always represent 30H)
Q) Write a short note on : Internal RAM Organisation
• 8051 has 128 bytes of internal RAM (00H to 7FH).
• It is divided into:
o 00H–1FH: Working registers (R0–R7 in 4 banks)
o 20H–2FH: Bit-addressable area (16 bytes)
o 30H–7FH: General-purpose RAM
• The upper 128 bytes (80H to FFH) are only available in 8052 or with special
function registers.
Q) Write a 8051 'C' program to generate 1KHz square waveform at port pin
P1.1 using timer 0 and mode 1. (crystal frequency = 12 MHz)
#include <reg51.h>
void delay_500us();
void main() {
P1_1 = 0; // Initialize P1.1 to 0
TMOD = 0x01; // Timer 0, Mode 1 (16-bit)
while (1) {
P1_1 = ~P1_1; // Toggle P1.1
delay_500us(); // Wait for 0.5 ms
}
}
void delay_500us() {
TH0 = 0xFE; // Load high byte for 500 us
TL0 = 0x0C; // Load low byte for 500 us
TR0 = 1; // Start Timer 0
while (TF0 == 0); // Wait for overflow
TR0 = 0; // Stop Timer 0
TF0 = 0; // Clear overflow flag
}
Q) List registers involved in serial communication of 8051 microcontroller.
Explain function of each register?
Registers Involved in Serial Communication of 8051 Microcontroller
The main registers involved are:
1. SBUF (Serial Buffer Register)
2. SCON (Serial Control Register)
3. PCON (Power Control Register)
4. IE (Interrupt Enable Register) – for enabling serial interrupt
5. TI (Transmit Interrupt Flag) – part of SCON
6. RI (Receive Interrupt Flag) – part of SCON
1. SBUF (Serial Buffer Register)
• Function: Used for both transmission and reception of data.
• Write to SBUF → Sends data to serial port (TX).
• Read from SBUF ← Receives data from serial port (RX).
2. SCON (Serial Control Register) – 8-bit register

SM0 SM1 SM2 REN TB8 RB8 TI RI

• SM0, SM1: Select serial mode (Mode 0 to Mode 3)


• SM2: Multiprocessor communication enable (used in Modes 2 & 3)
• REN: Receiver Enable (1 = enable reception)
• TB8: 9th data bit to transmit (in Mode 2/3)
• RB8: 9th data bit received (in Mode 2/3)
• TI: Transmit Interrupt flag (set when transmission is complete)
• RI: Receive Interrupt flag (set when reception is complete)
3. PCON (Power Control Register) – Only relevant bit for serial is:
• SMOD (bit 7): Double baud rate bit
o If SMOD = 1, baud rate is doubled in Modes 1, 2, and 3.
4. IE (Interrupt Enable Register)

EA — ET2 ES ET1 EX1 ET0 EX0

• ES (bit 4): Enable Serial Interrupt


o When set to 1, allows the serial interrupt to occur on TI or RI.
5. TI (Transmit Interrupt Flag)
• Set when a byte has been successfully transmitted via SBUF.
• Must be cleared by software after servicing.
6. RI (Receive Interrupt Flag)
• Set when a byte is received in SBUF.
• Must be cleared by software after reading the byte.
Q) Differentiate between microprocessor and microcontroller
Q) Explain any five types of instructions used in 8051 microcontroller with
suitable example?
1. Data Transfer Instruction : • Following instructions are used for data transfer : (1)
MOV (2) MOVX (3) MOVC (4) PUSH and POP (5) XCH
• In case of data transfer instruction, data is moved from source to destination without
affecting the source contents.
Examples : MOVX @ Ri, A : Move the accumulator contents to external RAM
address location pointed by RI (8-bit address).
2. Arithmetic Instructions : • Microcontroller applications often involve applying
mathematical calculations on data.
• MCS-51 supports 8-bit arithmetic unsigned operations. It is also possible to carry
both signed and unsigned addition and subtraction by using the OV flag.
3.Logical Instruction : • In 8051, bitwise logical operations like AND, OR and XOR
are possible. These instructions requires two 8-bit operands.
• No flags are affected by AND, OR and XOR instructions.
• In logical instructions again there are two types (1) byte level logical instructions
and (2) bit level logical instructions.
4. Boolean Variable Manipulation Instructions : • Operands for Boolean variable
manipulation are defined in these instructions. Also OR, AND operations are
possible with bit operands. There are instructions that test a specified bit and
transfer control to the desired location.
• For example, JB P1.0 instruction will test P1.0 bit and will jump the relative address
given in the instruction.
5. Branching Instructions : • In 8051 both conditional and unconditional branch
operations are possible.
• A JMP or CALL instruction replaces the contents of the program counter with a new
program address which causes program execution to begin from new address.
Q) Draw bit format of IP (Interrupt Priority) register and explain function of each bit?

• PX0: This Priority Use for External Interrupt 0


• PT0: This Priority Use for Timer 0
• PX1: This Priority Use for External Interrupt 1
• PT1: This Priority Use for Timer 1
• PS: This Priority Use for Serial Port
• PT2: This Priority Use for Timer 2 (in 8052)
‘1’ = High priority, ‘0’ = Low priority.
a) Explain the function of following pins of 8051 microcontroller? i) ALE ii)
PSEN iii) EA iv) RESET v) RXD
i) ALE: Latches the lower byte of address from multiplexed AD0–AD7.
ii) PSEN (Program Store Enable): Used to read external program memory.
iii) EA (External Access): When low, accesses external memory; when high, accesses
internal memory.
iv) RESET: Resets the microcontroller. Active high signal.
v) RXD (Receive Data): Used to receive data serially (part of UART
communication).
Q) Which port of 8051 requires external pull up resistors?
Ans Port 0 of 8051 requires external pull-up resistors.
Q) Which registers are used as data pointer in indirect addressing mode.

Answer: R0 and R1 (of selected bank).


Q) What extension is used to save ‘C’ Language program.
Answer: In 8051, C programs are stored in code memory (ROM) and use DPTR for
accessing memory. Variable values are stored in RAM using registers.
Q) Name the timer register of 8051 microcontroller used as bit addressable.
Answer: TCON (Timer Control Register) is bit-addressable.
Q) Define step angle of stepper motor.
Answer: Step angle = 360° / Number of steps per revolution.
Typically, for 200 steps/rev, step angle = 1.8°
Q) In half duplex, data is transmitted in only one direction at a time-comment.
Answer: In half-duplex communication, data is transmitted in only one direction at a
time, not simultaneously.
Q) Explain function of following instructions. i) CLR A ii) NOP iii) RR A iv)
SUBB A, # 05 H v) SWAP A
i) CLR A – Clears the accumulator (A = 00H).
ii) NOP – No operation (used for delay or timing).
iii) RR A – Rotates the accumulator right (A = A >> 1, bit 0 goes to bit 7).
iv) SUBB A, #05H – Subtracts 05H + carry from accumulator.
v) SWAP A – Swaps nibbles in A (high nibble ↔ low nibble).
Q) Timer Mode 2 of 8051
• 8-bit auto-reload mode.
• TLx counts, when it overflows, it reloads from THx.
• Used in baud rate generation and precise timing.
Q) Immediate Addressing Mode
• Operand is part of instruction.
• Example: MOV A, #45H loads 45H into A directly.
Q) Draw and explain interfacing of external 16 kb RAM with 8051
microcontroller?

• MOVX A, @ DPTR is the instruction used to read external RAM. This has many
applications where collecting large number of bytes data is required.
• During any memory access cycle, port 0 is time multiplexed. That is, it first provides
the lower byte of the 16-bit memory address and then acts as a bidirectional data bus
to write or read a byte of memory data.
• Port 2 provides the high byte of the memory address during the entire memory
read/write cycle.
• The lower address byte from port 0 must be latched into an external register to save
the byte. Address byte save is accomplished by the ALE clock pulse that provides the
correct timing for 74373 to latch. The port 0 pins then become free to serve as a data
bus.
Q) Interrupts in 8051
• 5 interrupts:
o INT0 (external)
o INT1 (external)
o Timer 0
o Timer 1
o Serial (Rx/Tx)
• Controlled by IE (enable) and IP (priority) registers.
Q) Explain internal RAM organisation of 8051 microcontroller.
• The 128 byte internal RAM, which is organized into three distinct areas
• Thirty-two bytes from address 00H to 1FH that make up 32 working registers are
organized as four banks of eight registers each.
• The four register banks are numbered from 0 to 3 and are made up of eight registers
named R0 to R7.
• Each register can be addressed by name (when its bank is selected) or by its RAM
address. Thus, R0 of bank 3 is R0 (if bank 3 is currently selected) or address 18H
(whether bank 3 is selected or not).
• Bits RS0 and RS1 in the PSW determine which bank of registers is currently in use
at any time when the program is running.
• Register banks not selected can be used as general purpose RAM. Bank 0 is selected
on reset.
• A bit-addressable area of 16 bytes occupies RAM byte addresses 20H to 2FH,
forming a total of 128 addressable bits
• A general purpose RAM and above bit area, from 30H to 7FH is addressable as
bytes.
Q) Input/Output ports of 8051
• 4 I/O Ports (P0–P3), each 8-bit:
o Port 0: Open-drain, needs pull-up
o Port 1: Full I/O
o Port 2: Higher address lines
o Port 3: Special functions (INT, Tx/Rx, etc.)

Q) What is the size of address and data bus of 8051 Microcontroller?


Ans: Address bus = 16-bit, Data bus = 8-bit
Q) Write 8051 C program to generate square wave with 2500 Hz frequency on
pin 2.7. Use Timer 1 in mode 2. Assume XTAL frequency = 12 MHz.
#include <reg51.h>
void delay() {
TH1 = 0xFF; // Load value for delay (approx. 200 µs)
TL1 = 0x38;
TF1 = 0;
TR1 = 1;
while (!TF1);
TR1 = 0;
}
void main() {
TMOD = 0x20; // Timer 1, Mode 2
while (1) {
P2 ^= 0x80; // Toggle P2.7
delay();
}
}
Q) Which special function register is used to keep track of priority of interrupts?
Ans: IP (Interrupt Priority Register)
Q) Which pin of LCD is used for controlling its contrast?
Ans: VEE (or V0) pin is used to adjust contrast.
Q) List any two assembler directives of 8051 microcontroller.
Ans:
1. ORG – Set program origin. 2. END – End of source file.
(Others: DB, EQU)
Q) Write C program for LCD interface to 8051 for displaying ‘ELECTRONICS’.
#include <reg51.h>
#define LCD P2
sbit RS = P3^0;
sbit EN = P3^1;
void delay() {
int i;
for(i = 0; i < 5000; i++);
}
void lcd_cmd(unsigned char cmd) {
LCD = cmd;
RS = 0;
EN = 1;
delay();
EN = 0;
}
void lcd_data(unsigned char dat) {
LCD = dat;
RS = 1;
EN = 1;
delay();
EN = 0;
}
void lcd_init() {
lcd_cmd(0x38); // 2 lines, 5x7 matrix
lcd_cmd(0x0E); // Display ON, Cursor ON
lcd_cmd(0x01); // Clear display
lcd_cmd(0x80); // Set cursor at first line
}
void main() {
lcd_init();
char msg[] = "ELECTRONICS";
int i;
for(i = 0; msg[i] != '\0'; i++)
lcd_data(msg[i]);
while(1);
}
Q) Define step angle of stepper motor.
Ans: Step angle = 360° / Number of steps per revolution
Example: For 200 steps → step angle = 1.8°
Q) State the role of ‘C/T’ in TMOD register.
Ans:
C/T bit = 0 → Timer mode
C/T bit = 1 → Counter mode
Q) Function of pins of 8051:
i) ALE (Address Latch Enable) – Used to latch lower byte of address using external
latch (for accessing external memory).
ii) PSEN (Program Store Enable) – Activates external ROM during code fetch.
iii) EA (External Access) – If low, fetch code from external memory.
iv) RESET – A high pulse ≥ 2 machine cycles resets 8051.
v) RXD – Serial input pin for receiving data (via UART).
Q) Write 8051 C - program to generate 4 kHz square wave on port pin P1.2 using
timer 0 in auto reload mode? [Assume XTAL = 12 MHz]
#include <reg51.h>
sbit wave = P1^2;
void main() {
TMOD = 0x02; // Timer 0, Mode 2 (8-bit auto reload)
TH0 = 0x83;
TL0 = 0x83;
TR0 = 1;
while (1) {
while (!TF0); // Wait overflow
TF0 = 0;
wave = ~wave; // Toggle pin
}
}
Q) Explain the function of following instructions.
i) Mov A, @ Ro ii) CPL bit iii) djNz R2 , Next
iv) RR A v) SUBB A, B
i) MOV A, @R0 – Move data from RAM location pointed by R0 to A.
ii) CPL bit – Complement a bit (toggle its value).
iii) DJNZ R2, Next – Decrement R2 and jump to label Next if R2 ≠ 0.
iv) RR A – Rotate accumulator A right (bit 0 to bit 7).
v) SUBB A, B – Subtract B + carry from A and store result in A.
Q) Draw block diagram to interface DAC0808 with 8051 and write a C program
to generate triangular waveform.

#include <reg51.h>
void delay() {
int i;
for(i = 0; i < 5000; i++);
}
void main() {
unsigned char val = 0;
while (1) {
for(val = 0; val < 255; val++) {
P1 = val;
delay();
}
for(val = 255; val > 0; val--) {
P1 = val;
delay();
}
}
}
Q) Write any five features of 8051 microcontroller.
1. 8-bit processor
2. 128 bytes internal RAM
3. 4 parallel I/O ports
4. Two 16-bit timers/counters
5. Full duplex serial communication
6. 32 I/O lines, 64 KB external ROM support
7. Bit-addressable memory
Q) Stepper Motor
• Electromechanical motor that rotates in steps.
• Step angle = 360° / steps per revolution.
• Controlled using pulses and drivers.
Q) Register Banks in 8051
• Total 4 banks (Bank 0 to Bank 3)
• Each has 8 registers (R0–R7)
• Located from 00H–1FH
• Select bank using bits of PSW (RS1, RS0)
Q) Data types used in 8051 C Program
• unsigned char, signed char, int, unsigned int, bit
• Example:
unsigned char a = 0xFF;
bit flag = 1;
Q) Logical Instructions (Any three)
1. ANL A, #data – Logical AND
2. ORL A, #data – Logical OR
3. XRL A, #data – Exclusive OR
4. CPL A – Complement accumulator
5. CLR A – Clear accumulator
Q) TCON Register
• TCON = Timer/Counter Control
• Bit-addressable register
• Controls timers and external interrupts

Bit Function

TF1 Timer1 overflow

TR1 Timer1 run

TF0 Timer0 overflow

TR0 Timer0 run

IE1 Ext Int 1 edge

IT1 Int 1 type

IE0 Ext Int 0 edge

IT0 Int 0 type

Q) What is the size of on-chip ROM in 8051?


Ans: 4 KB
Q) Define addressing mode.
Ans: Addressing mode refers to the method by which the operand of an instruction is
specified.
Q) What is the role of C/T bit of TMOD register?
Ans: It decides whether the timer operates as a timer (C/T = 0) or as a counter (C/T =
1).
Q) What is the use of SBUF in serial communication?
Ans: SBUF is used to hold data for serial transmission and reception.
Q) Define step angle of stepper motor.
Ans: Step angle = 360° / number of steps per revolution.
Q) In serial communication, which register is used to set the baud rate?
Ans: TH1 (Timer 1 high byte)
b) Explain the function of following instructions. i) ANL a, #05H ii) DEC @RO
iii) NOP iv) MOVX a, @DPTR v) MOV a, @RO
i) ANL A, #05H
• Function: Performs a bitwise AND operation between the accumulator (A) and
the immediate value 05H.
• Example: If A = 0Fh (00001111), then after execution A = 05h (00000101).
• Purpose: Used to clear specific bits in the accumulator.
ii) DEC @R0
• Function: Decrements the value stored in the memory location pointed to
by register R0 by 1.
• Example: If R0 = 40H and memory at 40H = 10H, then after execution
memory at 40H = 0FH.
• Purpose: Used in loops or counters.
iii) NOP
• Function: No Operation — the microcontroller does nothing for 1 machine
cycle.
• Purpose: Used for timing delays or to align instruction timing in critical
sections.
iv) MOVX A, @DPTR
• Function: Moves (reads) a byte from external data memory pointed by DPTR
into accumulator A.
• Used when: Accessing external RAM or peripherals.
• Note: MOVX is used only with external memory.
v) MOV A, @R0
• Function: Copies the byte from the memory location pointed by R0 into the
accumulator (A).
• Example: If R0 = 30H, and memory[30H] = 22H, then A = 22H after execution.
• Purpose: Used for indirect addressing.
Q) Define and explain assembler directive with the help of suitable example.
Definition: Assembler directives are special instructions or commands used in
assembly language programming that guide the assembler during the process of
converting assembly code into machine code. They do not generate machine code
themselves but help in organizing the program and allocating memory.
1.ORG (Origin)
• Purpose: Sets the starting address for the program or data.
• Example:
ORG 0000H ; Start assembling from address 0000H
MOV A, #05H
• Explanation: The instruction MOV A, #05H will be stored at memory location
0000H.
2.DB (Define Byte)
• Purpose: Reserves memory and stores byte(s) of data.
• Example: DATA1 DB 0AH ; Define a byte with value 0AH at label DATA1
Explanation: Allocates one byte of memory and stores 0AH there.
3.DB (Define Byte)
• Purpose: Reserves memory and stores byte(s) of data.
• Example:
COUNT EQU 0AH ; COUNT is now 0AH wherever used
MOV R0, #COUNT
4. END
• Purpose: Marks the end of the source code for the assembler.
• Example:
END ; No code after this will be assembled
Q) Write a 8051 'C' program to generate 24Hz square wave on port pin p1.3
using timer 0 in mode 2(XTAL = 12 MHz).
#include <reg51.h>
sbit wave = P1^3;
void main() {
TMOD = 0x02; // Timer 0 mode 2
TH0 = 0x06;
TL0 = 0x06;
TR0 = 1;
while(1) {
while(!TF0);
TF0 = 0;
wave = ~wave;
}
}
Q) Draw bit format of TCON register and explain function of each bit.

Q) List the various interrupts in 8051 microcontroller and write their


corresponding vector addresses with priority

Interrupt Vector Address Priority

External 0 (INT0) 0003H 1

Timer 0 000BH 2

External 1 (INT1) 0013H 3

Timer 1 001BH 4

Serial communication 0023H 5


Q) Function of LCD pins:
• RS (Register Select): 0 = command, 1 = data
• E (Enable): Triggers LCD to read data
• R/W: 0 = write, 1 = read
Q) Interrupt service routine (ISR):
• A function that executes automatically on interrupt
Example:
Copy code
void serial_ISR(void) interrupt 4 {
// ISR code
}
Q) Register banks in 8051:
• Four banks: Bank 0 to Bank 3
• Each bank has R0–R7
• Located from 00H–1FH
• Selected using PSW register (RS1, RS0)
Q) I/O Ports in 8051:
• 8051 has four 8-bit ports: P0, P1, P2, P3
• P0 and P2 used for external memory
• P1 is general-purpose
• P3 has alternate functions (RxD, TxD, INT0, etc.)

Q) Define assembler directives.


Ans: Assembler directives are instructions for the assembler that control the assembly
process. They do not generate machine code. Example: ORG, END, DB, EQU.

Q) What is the value of program counter after power on reset?


Ans: 0000H
Q) Write function of Auxiliary Carry flag (AC).
Ans: AC is set if there is a carry from bit 3 to bit 4 in an arithmetic operation. It
is used in BCD arithmetic.

Q) Which timer mode of 8051 microcontroller is 8-bit autoreload mode?


Ans: Timer Mode 2

Q) What is the step size of 8-bit ADC if Vref = 2.56V?


Ans: Step size = Vref / (2⁸ - 1) = 2.56 / 255 ≈ 0.01V

Q) Which is the lowest priority interrupt in 8051?


Ans: Serial communication interrupt

Q) Write ALP program to send values ooHto FFH to port 1.

MOV A, #00H

MOV R0, #00H

LOOP: MOV P1, R0

INC R0

CJNE R0, #00H, LOOP

SJMP $

Q)Draw block diagram to interface 7-segment display with 8051


Q) With the help of neat block diagram explain 8051 microcontroller

• The block diagram of the 8051 in Fig. 1.2 shows all of the features which are unique
to microcontrollers.
• The basic architecture of 8051 microcontroller can be divided into seven parts : 1.
Processing unit
2. Register set
3. Memory units 4. I/O ports and serial port
5. Timing and control unit 6. Interrupt structures 7. Timers
• The programming model of 8051 is shown in Fig. 1.3. From the block diagram and
programming model registers, Special Function Registers (SFR) and its memory
location can be studied.
Q) Differentiate between Asynchronous and synchronous serial communication.
Feature Synchronous Asynchronous
Communication Communication
Clock Signal Uses a common clock signal No clock signal is shared;
shared between sender and sender and receiver use their
receiver. own clocks.
Data Data is transmitted in a Data is sent in individual
Transmission continuous stream. bytes with start and stop bits.
Synchronization Synchronization is achieved Synchronization is done using
using the clock signal. start and stop bits.
Speed Generally faster due to Slower due to overhead of
continuous transmission. start/stop bits.
Complexity More complex hardware Simpler hardware and easier
(requires clock management). to implement.
Example SPI (Serial Peripheral UART (Universal
Protocols Interface), I²C (Inter- Asynchronous Receiver
Integrated Circuit) Transmitter)

Q) Write operation of the following instructions:


i) MOV A, #40H → Loads 40H directly into accumulator A.
ii) MUL AB → Multiplies A and B, result stored in A (low byte) and B (high byte).
iii) SETB 07H → Sets bit 7 (direct addressing).
iv) INC R0 → Increments register R0 by 1.
v) CPL A → Complements all bits of accumulator A.
c) Stepper motor:
• Converts digital pulses into mechanical rotation
• Rotates in steps (e.g., 1.8°, 7.5°)
• Controlled by energizing coils in a sequence
Q)Write 8051 C program to generate sawtooth waveform and draw block
diagram to interface DAC0808:
Ans:
#include <reg51.h>
void delay();
void main() {
unsigned char val = 0;
while(1) {
P1 = val++;
delay();
}
}
void delay() {
int i;
for(i=0; i<300; i++);
}
Q)Draw bit format of IE register and explain function:

Bit Symbol Function

7 EA Enable all interrupts

6 – Reserved

5 ET2 Enable Timer 2 interrupt

4 ES Enable Serial interrupt

3 ET1 Enable Timer 1 interrupt

2 EX1 Enable External interrupt 1


Bit Symbol Function

1 ET 0 Enable Timer 0 interrupt

0 EX0 Enable External interrupt 0

Q) Addressing modes of 8051 (any 3):


• Immediate: MOV A, #25H
• Register: MOV A, R1
• Direct: MOV A, 30H
• Indirect: MOV A, @R0
• Indexed: MOVC A, @A+DPTR
Q) Features of 8051 microcontroller:
• 4 KB ROM, 128 bytes RAM
• 40-pin DIP
• 32 I/O pins
• 2 Timers, Serial Port
• 5 Interrupts
Q) RAM organization:
• 00H–1FH: Working registers (4 banks)
• 20H–2FH: Bit-addressable area
• 30H–7FH: General purpose RAM
Q) SCON register:
• Used for serial communication
• Bit format: SM0, SM1 (mode select), REN, TB8, RB8, TI, RI
• Controls mode, enable receive, etc.
Q) TMOD register:
• Timer Mode register
• Lower 4 bits → Timer 0
• Upper 4 bits → Timer 1
• Bits: M0, M1 (mode), C/T, GATE
• Sets timer mode and operation type
Q) How much is the capacity of internal ROM of 8051?
Ans: 4 KB (4096 bytes)
Q) Name the interrupt which has highest priority in 8051 microcontroller?
Ans: External interrupt 0 (INT0)
Q) What is the step size for 8-bit ADC if Vref = 4 volts?
Ans: Step size = Vref / (2⁸ - 1) = 4 / 255 ≈ 0.0157 V
Q) Assembler directive ORG and DB of 8051 stands for?
Ans:
• ORG: Origin, used to specify starting address.
• DB: Define Byte, used to store data byte(s) in memory.
Q) What is the significance of Gate bit of TMOD register in 8051?
Ans: If Gate = 1, the timer starts only when external interrupt (INTx) pin is high
and TRx bit is set. If Gate = 0, timer starts with TRx only.
Q) Define step angle of stepper motor.
Ans: It is the angle by which the motor shaft moves in response to each input
pulse. Example: 1.8°, 7.5° per step.
Q) Parallel ports:
8051 has four 8-bit parallel I/O ports (P0–P3).
They can be used for input/output operations. Port0 requires pull-ups.
Q) Synchronous communication:
Data is transmitted with a shared clock between sender and receiver. Faster but
requires synchronization.
Q) Draw and explain simplified block diagram of 8051 microcontroller?

• Intel Corporation introduces an 8-bit microcontroller called 8051. This


microcontroller had 128 bytes of RAM, 4 k bytes of on-chip ROM, two timers and
four ports all on a single chip. The 8051 is an 8-bit processor that means CPU can
work on only 8 bits of data at a time. It has four 8-bit ports.
• Fig. 1.1 shows the block diagram of typical microcontroller. It is the on chip
computer. It contains all blocks such as RAM, ROM, parallel I/O and serial I/O ports
on a single chip. Along with this, it also has ALU, SP and other registers to perform
the features supported by microprocessor.
• Microcontroller can perform simple arithmetic and logical operations. The prime use
of microcontroller is to control operations with proper sequence.
• This chapter provides a broad overview of the architecture of the 8051. The 8051
introduced by Intel Corporations is also referred as MCS-51.
d) TMOD Register: Timer Mode register (8 bits).
• Lower 4 bits → Timer 0
• Upper 4 bits → Timer 1
Each half:
• GATE | C/T | M1 | M0
Used to set timer mode (0 to 3), timer/counter operation, and gate control.
Q) Write a 8051 C-program to generate 1kHz square waveform on port pin P2.5
using Timer 1, mode 1 (Assume Xtal = 12 MHz).
#include <reg51.h>
void delay() {
TMOD = 0x10; // Timer1, Mode1
TH1 = 0xEC;
TL1 = 0x78;
TR1 = 1;
while (TF1 == 0);
TR1 = 0;
TF1 = 0;
}
void main() {
while (1) {
P2 ^= 0x20; // Toggle P2.5
delay();
}
}
a) Data Transfer Instructions (Any 3):
1. MOV A, R0 – Register to accumulator
2. MOV A, 40H – Direct to accumulator
3. MOV R0, #50H – Immediate to register
4. XCH A, R1 – Exchange accumulator and R1
Q) Draw block diagram of interfacing DAC0808 & write a C-program to
generate sawtooth waveform:
#include <reg51.h>
void delay();
void main() {
unsigned char val = 0;
while (1) {
P1 = val++;
delay();
}
}
void delay() {
int i;
for(i=0; i<500; i++);
}
Q)Salient Features of 8051 Microcontroller :
1. It is an 8-bit microcontroller, designed using NMOS technology.
2. 8-bit data bus, 16-bit address bus.
3. 4 k bytes – on-chip ROM.
4. 128 bytes – on-chip RAM.
5. 32 general purpose registers, each of 8-bit.
6. Operating frequency 12 MHz.
7. Multiply and divide instruction available.
8. It has a boolean processor and supports bitwise operations.

You might also like