EXPERIMENT NO.1 AIM: Study of 8051 Microcontroller TOOLS: 8051 kit THEORY: Salient Features of 8051 A Microcontroller is a complete computer system built on a single chip. It contains all components like Processor (CPU), RAM, ROM, Serial port, Parallel port, Interrupt logic, Timer etc on chip. A Microcontroller saves cost, saves power consumption and makes the circuit compact. 8051 is an 8-bit Microcontroller On-Chip ROM = 4 KB (Program Memory). On-Chip RAM = 128 Bytes (Data Memory). Four 8 bit bi-directional I/O ports. Serial Port. Two 16 bit Up-Counters (Timers). It supports interrupts with two-level priority. Power saving modes. It is used in appliances such as Washing Machines, Microwaves, Mobile Phones, MP3 Players etc. Pin Diagram of 8051 Port 0(p0.0 to p0.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During external memory access, it functions as multiplexed data and low-order address bus AD0-AD7. Port 1 (p1.0 to p1.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. When logic '1' is written into port latch then it works as input mode. It functions as simply I/O port and it does not have any alternative function. Port 2 (p2.0 to p2.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During external memory access it functions as higher order address bus (A8-A15).
Port 3(p3.0 to port 3.7): It is 8-bit I/O port. In an alternating function each pins can be used as a special function I/O pin. P3.0-RxD: It is an Input signal. Through this I/P signal microcontroller receives serial data of serial communication circuit. P3.1-TxD: It is O/P signal of serial port. Through this signal data is transmitted. P3.2- (INT0): It is external hardware interrupt I/P signal. Through this user, programmer or peripheral interrupts to microcontroller. P3.3-(INT1): It is external hardware interrupt I/P signal. Through this user, programmer or peripheral interrupts to microcontroller. P3.4- T0: It is I/P signal to internal timer-0 circuit. External clock pulses can connects to timer-0 through this I/P signal. P3.5-T1: It is I/P signal to internal timer-1 circuit. External clock pulses can connects to timer-1 through this I/P signal. P3.6-[WR(bar)]: It is active low write O/P control signal. During External RAM (Data memory) access it is generated by microcontroller. when [WR(bar)]=0, then performs write operation. P3.7-[RD(bar)]: It is active low read O/P control signal. During External RAM (Data memory) access it is generated by microcontroller. when [RD(bar)]=0, then performs read operation from external RAM. XTAL1 and XTAL2: These are two I/P line for on-chip oscillator and clock generator circuit. A resonant network as quartz crystal is connected between these two pin. 8051 microcontroller also drives from external clock, then XTAL2 is used to drive 8051 from external clock and XTAL1 should be grounded. [EA(bar)]/VPP: It is and active low I/P to 8051 microcontroller. when (EA)= 0, then 8051 microcontroller access from external program memory (ROM) only. When (EA) = 1, then it access internal and external program memories (ROMS).
[PSEN(bar)]: It is active low O/P signal. It is used to enable external program memory (ROM). When [PSEN(bar)]= 0, then external program memory becomes enabled and microcontroller read content of external memory location. Therefore it is connected to (OE) of external ROM. It is activated twice every external ROM memory cycle. ALE: Address latch enable: It is active high O/P signal. When it goes high, external address latch becomes enabling and lower address of external memory (RAM or ROM) latched into it. Thus it separates A0-A7 address from AD0-AD7. It provides properly timed signal to latch lower byte address. The ALE is activated twice in every machine cycle. If external RAM & ROM is not accessed, then ALE is activated at constant rate of 1/6 oscillator frequency, which can be used as a clock pulses for driving external devices. RESET: It is active high I/P signal. It should be maintained high for at least two machine cycle while oscillator is running then 8051 microcontroller resets. Figure: Pin diagram of 8051
CONCLUSION: Salient features and pin structure of 8051MC were studied in detail.
EXPERIMENT NO.2 AIM: a)to write a program to add and subtract two 8-bit hexadecimal numbers stored at location D000H and D001H also store the result at location D002H using DYNA-51. b) To write a program to Multiply and Divide two 8-bit hexadecimal numbers stored at location D000H and D001H, also store the result from location D002H using DYNA-51 TOOLS: DYNA-8051 kit, MCU 8051 IDE. THEORY: The program is written at memory location C000H. DPTR is initialized to D000H. The instructions used in the program are as follows: MOV:The MOV instruction moves data bytes between the two specified operands. The byte specified by the second operand is copied to the location specified by the first operand. The source data byte is not affected. E.g.: MOV A, B ADD:The ADD instruction adds a byte value to the accumulator and stores the results back in the accumulator. The destination operand is always in register A while the source operand can be a register, immediate data, or in memory. The instruction could change any of the AF, CF, or P bits of flag register. E.g.: ADD 0F0H this instruction will add the contents of 0F0H register to default register A and store the result in default register A. SUBB (subtract with borrow) :In subtraction, the 8051 use the 2 s complement method. There are two case for SUBB instruction; (1) with CY = 0, and (2) with CY = 1.The SUBB instruction subtracts the specified byte variable and the carry flag from the accumulator. The result is stored in the accumulator. This instruction sets the carry flag if a borrow is required for bit 7 of the result. If no borrow is required, the carry flag is cleared. E.g.: SUBB 0F0H this instruction will subtract the contents of 0F0H register from default register A and store the result in default register A. MUL:The MUL instruction multiplies the unsigned 8-bit integer in the accumulator and the unsigned 8-bit integer in the B register producing a 16-bit product. The low-order byte of the product is returned in the accumulator. The high-order byte of the product is returned in the B register. The OV flag is set if the product is greater than 255 (0FFh), otherwise it is cleared. The carry flag is always cleared.
DIV:The DIV instruction divides the unsigned 8-bit integer in the accumulator by the unsigned 8-bit integer in register B. After the division, the quotient is stored in the accumulator and the remainder is stored in the B register. The carry and OV flags are cleared. If the B register begins with a value of 00h the division operation is undefined, the values of the accumulator and B register are undefined after the division, and the OV flag will be set indicating a division-by-zero error. INC:The INC instruction increments the specified operand by 1. An original value of 0FFh or 0FFFFh overflows to 00h or 0000h. No flags are affected by this instruction. When this instruction is used to modify an output port, the value used as the port data is read from the output data latch, not the input pins of the port. E.g.: DPTR initialized at C100 After INC DPTR => C101 LJMP: LJMP is an unconditional long jump. It is 3-byte instruction in which first byte is opcode, and the second and third bytes represent the 16- bit address of the target location. The LJMP instruction transfers program execution to the specified 16-bit address. The PC is loaded with the high-order and low-order bytes of the address from the second and third bytes of this instruction respectively. No flags are affected by this instruction. The program execution will stop at this instruction ALGORITHM: Step1: Get first number in register A Step2: Get second number in register B Step3: Add/Subtract/Multiply/Divide the two numbers Step4: Store Result in Memory location Step5:Stop
FLOWCHART: Start Move First no. to A Move Second no. to B Add/Subtract content of A and B Store the result in A Stop Fig:Addition and Subtraction Start Move Multiplicand to A / Dividend to A Move multiplier to B/Divisor to B Multiply A and B / Divide A by B Store the lower byte in A and upper byte in B of the product /Quotient in A and Remainder in B to the destination Stop Fig: Multiplication and Division
RESULTS: Addition ADDRESS VALUE(eg) INPUT Before execution D000H D001H OUTPUT After execution D002H Subtraction ADDRESS VALUE INPUT Before execution D000H D001H OUTPUT After execution D002H Multiplication ADDRESS VALUE INPUT D000H OUTPUT D001H D002H D003H Division ADDRESS VALUE INPUT D000H OUTPUT D001H D002H D003H
CONCLUSION: Addition and Subtraction of two 8-bit hexadecimal nos. was done using ADD and SUBB instruction respectively and the result was stored in the register A and then shifted to memory location. Multiplication of two 8-bit hexadecimal numbers was done using MUL instruction and the lower byte of the result was stored in the register A and Higher byte in register B and further was shifted to memory location. Similarly Division of two 8-bit hexadecimal numbers was done using DIV instruction. The quotient was stored in a register A and remainder was stored in register B, further quotient and remainder was stored in Memory location.