Monday 21 August 2017

Friday 18 August 2017

Unit Test I Paper Solution



Microcontroller & Embedded Systems

Unit Test I Paper Solution

Q.1 SOLVE Any Five.
a. Explain Timer Mode (TMOD) register of 8051 Microcontroller.


b. Explain RRC and RLC logic instruction with example.
The RRC instruction rotates the eight bits in the accumulator and the one bit in the carry flag right one bit position. Bit 0 of the accumulator is rotated into the carry flag while the original value of the carry flag is rotated in to bit 7 of the accumulator. Bit 7 of the accumulator is rotated into bit 6, bit 6 into bit 5, and so on. No other flags are affected by this instruction.
The RLC instruction rotates the eight bits in the accumulator and the one bit in the carry flag left one bit position. Bit 7 of the accumulator is rotated into the carry flag while the original value of the carry flag is rotated into bit 0 of the accumulator. Bit 0 of the accumulator is rotated into bit 1, bit 1 into bit 2, and so on. No other flags are affected by this operation.
RRC a                                                                       
mov a, #0A9h                         ; a ß A9
add a, #14h                            ; a ß BD (10111101), Cß0
rrc a                                        ; a ß 01011110, Cß1

RLC a                                                                         
mov a, #3ch                            ; a ß 3ch (00111100)
setb c                                      ; c ß 1
rlc a                                        ; a ß 01111001, Cß1
 
 




c. Write assembly language program for two 8-bit numbers multiplication.
MOV A, #25H                        ; load 25H to reg. A
MOV B, #65H                        ; load 65H in reg. B
MUL AB                                ; 25H * 65H = E99 where B = 0EH and A = 99H

d. What are the Features of 8051 Microcontroller?
  • 4KB ROM
  • 128 bytes internal RAM
    • 4 register banks of 8 bytes each (R0-R7)
    • 16 bytes of bit-addressable area
    • 80 bytes of general purpose memory
  • Four 8-bit I/O ports (P0-P3)
  • Two 16-bit timers (Timer0 & Timer1)
  • One serial receiver-transmitter interface
  • Six interrupt sources (2 external & 3 internal, 1 reset)
  • One oscillator (generates clock signal)
  • Operating frequency is 12 MHz
  • Available in ROM/EPROM/EEPROM versions
  • Separate 64kb program and 64kb data memory
  • Multiply and divide instructions available
  • Has a boolean processor and supports bitwise operations
  • 16 bit address bus multiplexed with port 0 and port 2
  • 8 bit program status word and stack pointer

e. Write assembly language program for 8051 Microcontroller to convert hexadecimal number to decimal number.
MOV A, #9CH
; Store HEX number into A
MOV B, #0AH
; Move the divisor into B
DIV AB
; Divide the HEX number by 10
MOV R0, B
; Move reminder to R0 from B
MOV B, #0AH
; Reload the divisor into B
DIV AB
; Divide the quotient by 10
MOV R1, B
; Move the reminder to R1
MOV R2, A
; Move the last quotient to R2

f. Explain DPTR and PSW register of 8051 Microcontroller.
DPTR is 16-bit register consisting of two bytes, Higher byte referred as DPH, lower byte referred as DPL, DPTR used for addressing off-chip data & code with MOVX & MOVC commands, respectively. With 16-bit pointer DPTR, max of 64K of off-chip data memory & max of 64K off-chip program memory can be addressed. It may be used as general-purpose register also.
INC DPTR for incrementing 16-bit contents of register. There is no such instruction in 8051 to decrement the DPTR, Also possible to load DPTR with 16-bit immediate data using MOV instruction.
DPTR is made up of two 8-bit registers: DPH and DPL. DPTR holds the memory addresses for internal and external code access and external data access,
eg.       MOVC  A, @A + DPTR      
            MOVX  A, @DPTR       
MOVX  @DPTR, A  
DPTR is under the control of program instructions and can be specified by its 16-bit name, or by each individual byte name, DPH and DPL. DPTR does not have a single internal address; DPH and DPL are each assigned an address (83H and 82H).

PSW is an 8-bit register. It consists of carry, auxiliary carry, overflow & parity flags. There are bits RS1 & RS0 for register bank selection. PSW is bit addressable register. Each of PSW bits is referred as PSW.X. Thus PSW.0 is LSB, which is parity flag, & MSB PSW.7 is the carry flag. PSW contains the math flags, user program flag F0, and the register select bits (RS1, RS0) that identify which of the four general-purpose register banks is currently in use by the program.




Q2. A. List components and Explain Embedded Systems architecture.
The embedded system component includes its hardware and software. The most important component in the embedded system is the processor. The processor can be said to be the heart of embedded system. The various units in embedded system include the following:
1. Microprocessor or microcontroller
2. timer/counter
3. Serial and parallel communication port
4. Interrupt controller
5. Input device with the driver circuits
6. Output device with the driver circuit.
7. Power supply, reset and oscillator circuit.
8. any application specific circuit.
The microprocessor is a central processing unit of a general purpose digital computer. They can address megabyte of memory and operate on 8, 16, or 32bit data.
Power supply: any electronic circuit requires a power supply. The power supply circuit that consist of a transformer, rectifier and regulator is also important ingredient of the embedded system. Many embedded system are battery oriented and hence the source of power is battery.
Microprocessor based system or the embedded system are digital system. Some microcontroller has on chip oscillator circuit and requires only a crystal to be connected externally, while some require oscillator circuit to be external. The oscillator circuit that is used in any in any microcontroller based system that generates the clock pulses for the internal operation to be synchronized.

Q2. B. Define Embedded Systems. What are the Specialities of the Embedded Systems.
A system that has embedded software and hardware, that makes it dedicated system application or product is called as Embedded system.
Another way of defining the embedded system is any system that has a microprocessor or a microcontroller embedded into system to control the system is called as embedded system.
Specialities of the Embedded Systems:
1.      Reliability
2.      Performance
3.      Power Consumption
4.      Cost
5.      Size
6.      Limited User Interface
7.      Software Upgradation Capability

Q3. A. Explain Addressing Modes of 8051 Microcontroller.
Ans: - The 8051 provides a total of five distinct addressing modes. (1) immediate (2) register (3) direct (4) register indirect (5) indexed
 (1) immediate: The operand comes immediately after the op-code. The immediate data must be preceded by the pound sign, "#".
MOV DPL, #21H
MOV DPL, #45H
MOV P1, #55H                       ; to send data 55H to 8051 port 1
(2) register: Register addressing mode involves the use of registers to hold the data to be manipulated.
MOV DPTR, #25F5H            MOV  R6, #DPL         MOV R7, #DPH
Source and destination register should match in size. Can move data between accumulator and register. Movement of data between registers is not valid. MOV R0, R1
(3) direct: There are 128 bytes of RAM in the 8051. The RAM has been assigned addresses 00 to 7FH. 1. RAM locations 00 - 1 FH are assigned to the register banks and stack. 2. RAM locations 20 - 2FH are set aside as bit-addressable space to save single­bit data. 3. RAM locations 30 - 7FH are available as a place to save byte-sized data. It is most often used to access RAM locations 30 - 7FH. This is due to the fact that register bank locations are accessed by the register names of R0 - R7. There is no such name for other RAM locations so must use direct addressing. In the direct addressing mode, the data is in a RAM memory location whose address is known, and this address is given as a part of the instruction.

(4) register indirect: A register is used as a pointer to the data. If the data is inside the CPU, only registers R0 and R 1 are used for this purpose. R2 - R7 cannot be used to hold the address of an operand located in RAM when using indirect addressing mode. When RO and R 1 are used as pointers they must be preceded by the @ sign. In absence of @ sign, MOV will be interpreted as an instruction moving contents of register R0 to A, instead the contents of memory location pointed to by R0. One of the advantages of register indirect addressing mode is that it makes accessing data dynamic rather than static as in the case of direct addressing mode. Looping is not possible in direct addressing mode. This is the main difference between the direct and register indirect addressing modes. R0 and R1 are the only registers that can be used for pointers in register indirect addressing mode. Since R0 and Rl are 8 bits wide, their use is limited to accessing any information in the internal RAM (scratch pad memory of 30H - 7FH, or SFR). To access data stored in external RAM or in the code space of on-chip ROM, we need a 16-bit pointer, the DPTR.

(5) indexed: Indexed addressing mode is widely used in accessing data elements of look-up table entries located in the program ROM space of the 8051. The instruction used for this purpose is : MOVC A, @ A+DPTR. The 16-bit register DPTR and register A are used to form the address of the data element stored in on-chip ROM. Because the data elements are stored in the program (code) space ROM of the 8051, the instruction MOVC is used instead of MOV. The "C" means code. In this instruction, the contents of A are added to the 16-bit register DPTR to form the 16­bit address of the needed data. The 8051 has another 64K bytes of memory space set aside exclusively for data storage. This data memory space is referred to as external memory and it is accessed by the MOVX instruction. The 8051 has a total of 128K bytes of memory space since 64K bytes of code added to 64K bytes of data space gives us 128K bytes. One major difference between the code space and data space is that, unlike code space, the data space cannot be shared between code and data.

Q3. B. Explain Pin Configuration of 8051 Microcontroller.
The pin configuration of 8051 consists of 40 pin dual in line package. The devices 8031,8751 has the same pin-out, same timing and same electrical characteristics. The difference lies in the on chip program memory, that is different for different user requirement.
Vcc: Supply voltage.
GND: Ground
Port 0: port 0 is an 8bit open drain bidirectional I/O port. As an output port each pin can sink eight TTL input. When 1s are written to port 0 pins, the pins can used as high impedance input.
Port 1: port 1 is an 8bit bidirectional I/O port with internal pull-ups. The port 1 output buffer can sink source four TTL input. When 1s are written to port 1 pins are pulled high by internal pull-ups and can be used as inputs.

Port 2: port 2 is a 8 bit bidirectional I/O port with internal pull ups. The port 2 output buffers can sink/source four TTL inputs. When 1s are written to port 2 pins are pulled high by internal pull-ups and can be used as inputs.
Port 3: port 3 is a 8 bit bidirectional I/O port with internal pull ups. The port 3 output buffers can sink/source four TTL inputs. When 1s are written to port 3 pins are pulled high by internal pull-ups and can be used as inputs.
RST: (Reset input)a high on this input pin for two machine cycle, while the oscillator is running reset the device.
PSEN: program store enables is the read strobe to external program memory.
When 8051 is executing code from external program memory, PSEN activation are skipped during each access to external data memory.
EA/Vpp: External access enables. EA must be strapped to ground in order to enable the device to fetch code from external memory location starting from 0000H to 0FFFH.