Mc Lab Manual-2013

March 27, 2018 | Author: saisuchandan | Category: Microcontroller, Library (Computing), Assembly Language, Compiler, Computer Programming


Comments



Description

Embedded Systems & MC labTHE 8051 - MICRO CONTROLLER Intel’s 8051 is one of the most popular microcontrollers. Many derivative microcontrollers have since been developed that are based on and compatible with the 8051.Thus, the ability to program an 8051 is an important skill for a system designer to develop products based on these microcontrollers. Difference between Microprocessor & Microcontroller Microprocessor Microcontroller 8051 Features:  40- pin DI package  Harvard Architecture  8-bit Arithmetic Logic Unit  8-bit data bus multiplexed with address bus  On-chip oscillator:1–16MHz operating frequency(fxtal)  Each machine cycle contains 6 states: 12 clock cycles fclk = fxtal/12.  16-bit address bus :216 = 65,536 = 64K bytes of Locations.  4K ROM, 128 bytes RAM, 32 REGs, 16 bytes Bit addressable RAM, 80 bytes user RAM.  4 bank of 8 registers (R0-R7): 8-bit each  Two pointers PC & DPTR  Two 16 bit timers/counters with interrupts  Four 8 bit parallel ports: with single line access  1 serial port with interrupt facility  2 external Interrupts( total - 5 Interrupts)  A & B math registers  Stack: Internal RAM, 8 bit SP=07H – default Dept. ECE, RVCE 1 Embedded Systems & MC lab 8051 Programming Model Bit Addressable Register Dept. ECE, RVCE 2 Embedded Systems & MC lab Program Status Word (PSW) Register Timer/Counter Mode selection (TMOD) Register Timer/Counter Control (TCON) Register Dept. ECE, RVCE 3 ECE. RVCE 4 .Embedded Systems & MC lab Serial control (SCON) Register Interrupt Enable (IE) Register Interrupt Priority (IP) Register Dept. Dept. ECE.Embedded Systems & MC lab Power Control (PCON) register Port 3 alternate pin functions Interrupt Vectors All above mentioned features with control register set is for all 8051 microcontroller and Microcontroller used in lab for practical implementation is from ATMEL with series number AT89C51ED2 and following sections would give complete details and extra features of microcontroller MCB 51 target board. RVCE 5 . It contains a 64-Kbyte Flash memory block for code. ESA MCB 51 development board is built around Atmel AT89C51ED2/RD2 microcontroller. Block Diagram: Fig 1 AT89C51ED2/RD2 Microcontroller AT89C51RD2/ED2 is high performance CMOS Flash version of the 80C51 CMOS single chip 8-bit microcontroller. P0. a 9-source 4-level interrupt controller and three timer/counters. interfaced to port lines. RVCE 6 . ESA MCB 51 Capabilities  The powerful full-chip monitor provides communication with Keil µ Vision Debugger. The AT89C51ED2 provides 2048 bytes of EEPROM for non volatile data storage.  Executes user programs at full speed or debug the program using single step and break point facilities available in Keil µ Vision debugger. The programming voltage is internally generated from the standard VCC pin. ESA MCB 51 is designed to be general purpose development board for single chip MCU applications that may be used as an instructional learning aid and also as a development tool in R&D labs in industries.  24 port lines (i.  On board ISP (In-System Programming) support for on-chip flash programming.e.Embedded Systems & MC lab INTRODUCTION TO ESA MCB 51 TARGET BOARD This is a development board and supports a wide variety of 8051(with on-chip ROM) compatible 8-bit microcontroller.  Examine/ modify the contents of CPU registers and memory contents. P1 and P2) are terminated 0n 26-pin connector. ECE. The AT89C51RD2/ED2 retains all of the features of the Atmel 80C52 with 256 bytes of internal RAM.  80C52 Architecture Compatible – 8051 Instruction Compatible – Four 8-bit I/O Ports (44 Pins Version) Dept. The 64Kbytes Flash memory can be programmed either in parallel mode or in serial mode with the ISP(In System Programming) capability or with software.  All the 32 I/O lines are terminated on 4 different 10 pin connectors.  On board LCD (16 x 2). Power-down Mode Block diagram of AT89C51ED2 Microcontroller: Fig 2 On-Chip memory of AT89C51ED2 Microcontroller: Fig 3 Dept. ECE.Embedded Systems & MC lab          – Three 16-bit Timer/Counters – 256 Bytes Scratch Pad RAM – 9 Interrupt Sources with 4 Priority Levels ISP (In-System Programming) Using Standard VCC Power Supply 2048 Bytes Boot ROM Contains Low Level Flash Programming Routines and a default Serial Loader 64K Bytes On-chip Flash Program/Data Memory – Byte and Page (128 Bytes) Erase and Write – 100k Write Cycles On-chip 1792 bytes Expanded RAM (XRAM) On-chip 2048 Bytes EEPROM Block for Data Storage (AT89C51ED2 Only) SPI(Serial Peripheral ) Interface (Master/Slave Mode) Full-duplex Enhanced UART with Dedicated Internal Baud Rate Generator Hardware Watchdog Timer (One-time Enabled with Reset-Out) Power Control Modes: Idle Mode. RVCE 7 . 1. assembler and debugger enable you to build sophisticated. RVCE 8 . The RS-232 level shifter (MAX-232) is used in between RJ-11 and on chip UART. The target uses the on chip flash monitor to communicate with Keil µ Vision debugger. The Keil µVision development supports three major microcontroller architectures which allow us to develop a wide range of applications. Hence other devices are not seen. ECE. The typical layout of flash monitor and Keil debugger is shown below Fig 4. compiler. the compiler tools are installed only for 8051 variants.Embedded Systems & MC lab Communication between ESA MCB 51 target board & host computer The board is connected to host computer’s serial port through DB-9 connector (PC side) and RJ-11(target side).  Transmission(Tx)  GND  Receiving (Rx)  GND INTRODUCTION TO KEIL EMBEDDED DEVELOPMENT TOOLS Keil software embedded development tools provide a powerful development environment for rapidly creating and testing embedded systems software. The AT89C51ED2 has got serial loader (boot loader) program allows ISP of the flash. Create a project. So. Software Development Cycle When you use the Keil µVision. Create source files in C or assembly. Dept. select the target chip from the device database. The communication is RS-232 standard compliance. complex applications quickly and easily. and configure the tool settings. We are using AT89C51ED2 microcontroller by Atmel.  8 bit 8x51 family of controllers  16-bit Infineon C16x/XC16x and ST10/Super 10  32 bit ARM based devices The supported controllers can be seen in target devices list. Integrated editor. Only four pins of DB 9 are connected to four pins of RJ-11 connector. 2. The flash monitor allows the user to debug the on chip code. on chip UART is used to interface the board with PC. The connected pins are. the project development cycle is roughly the same as it is for any other software development project. E. ECE. µVision IDE The µVision IDE combines project management. 2. and on-line help. Following are the reasons to write instructions in assembly language. The Keil C51 Compiler is a full ANSI implementation of the C programming language that supports all standard features of the C language. 3. The program size is less in assembly coding resulting in need of less memory chips. To reduce the size of program. Robot arms. Anti-lock brake systems. To understand the processor architecture well. In hard embedded systems. option setup. Knowledge of the processor instruction set is not required. 5. Each component is described below Fig 5. Correct errors in source files. 1. RVCE 9 . where response time critical to functionality. The compiler and assembler process source files and create relocatable object files. µVision automatically compiles. a rich-featured editor with interactive error correction. Rudimentary knowledge of the memory structure of the CPU is desirable (but not necessary).Embedded Systems & MC lab 3. Build your application with the project manager. 4. assembles. A51 Macro Assembler & C51 Compiler Source files are created by the µVision IDE and are passed to the C51 Compiler (High level language programs) or A51 Macro Assembler (Assembly level language programs). 5. The following block diagram illustrates the complete µVision software development cycle. the assembly coding can be used to meet all deadlines. The high level language compilers often produce excess or overhead codes. The Keil A51 macro assembler supports the complete instruction set of the 8051 and all derivatives. To write programs for special situations. Using a high-level language like C has many advantages over assembly language programming: 1. make facility. Use µVision to create your source files and organize them into a project that defines your target application. and links your embedded application. Test the linked application. etc. In addition. Dept. So the cost of the system reduces. 4. numerous features for direct support of the 8051 architecture have been added. To speed computer operation.g. reliable program debugging.  With an in-circuit emulator for the program testing. All code and data reside at fixed memory locations. Existing program investments can be quickly adapted to other processors as needed. 7. RVCE 10 . 9. while defining optimized code memory requirement and execution time of object files are considered. The Keil software does two types code optimization techniques (These can be enabled or disabled). µVision Debugger The µVision symbolic. Existing program parts can be more easily included into new programs because of modular program construction techniques. and floating-point arithmetic. An absolute object file or module contains no relocatable code or data. This contributes to source code reusability as well as better overall application structure. 5. The ability to combine variable selection with specific operations improves program readability. LIB51 Library Manager The LIB51 library manager allows you to create object library from the object files created by the compiler and assembler. only those object modules in the library that are necessary to create the program are used. ECE. When the linker processes a library. Simulator mode configures µVision debugger as software only product that accurately simulates target systems including instructions and on-chip peripherals. in some of the compilers special options will be given to generate optimized code as in Keil software. Programs get a formal structure (which is imposed by the C programming language) and can be divided into separate functions. But compilers never generate optimized code as compared assembler which translates assembly programs into machine codes. The debugger includes a high-speed simulator that let you simulate an entire 8051 system including on-chip peripherals and external hardware. object code generated by compilers is only comparable in speed and memory requirement with that of object files generated by assemblers but not the same.Simulator mode and Target mode. 4.Embedded Systems & MC lab 2. The C run-time library contains many standard routines such as: formatted output. Details like register allocation and addressing of the various memory types and data types is managed by the compiler. The language C is a very portable language (based on the ANSI standard) that enjoys wide popular support and is easily obtained for most systems. The µVision debugger offers two operating modes. Keywords and operational functions that more nearly resemble the human thought process may be used. ordered program collections of object modules that may be used by the linker at a later time. BL51 Linker/Locator The BL51 Linker/Locator creates an absolute HEX file using the object modules extracted from libraries and those created by the compiler and assembler. 3.  With the µVision Debugger for simulation and target debugging. Programming and program test time is drastically reduced. Note that. This allows code Dept. Libraries are specially formatted. But. In spite of all these optimizations. numeric conversions. The attributes of the chip you use are automatically configured when you select the device from the Device Database. 8. 6. Many embedded development tools are now available with facility of writing assembly instructions in high level language programs. The absolute HEX file may be used:  To program an Flash ROM or other memory devices. source-level debugger is ideally suited for fast. a file termination record. The appropriate target driver is required depending on the target board connected. 4. contains data and 16-bit address. Address.  Simulation offers optimal input signal. the first two bytes are the CS value. the byte count is 04. This allows addressing of up to a megabyte of address space. 16-bit. The address field of this record has to be 0000. RVCE 11 . two hex digits . For 80x86 processors. identical to 80x86 real mode addressing.Embedded Systems & MC lab testing before hardware is available and gives you benefits for rapid. only one per file is permitted. Usually ':00000001FF'. The format is a text file. two hex digits.  Early software debugging on a functional basis improves overall software reliability. with each line containing hexadecimal values encoding a sequence of data and their starting offset or absolute address. The target mode connects the µvision debugger to real hardware. 3. a number of bytes (hex digit pairs) in the data field. The least significant hex digit of the segment address is always 0.  01. It is calculated by adding together the hex-encoded bytes (hex digit pairs).  02. 2n hex digits. the limit is worked around by specifying higher bits via additional record types. Intel HEX file This is a file format for conveying binary information for applications like programming microcontrollers.  Failure scenarios that would destroy real hardware peripherals are easily checked. on : 0300300002337A1E 03 + 00 + 30 + 00 + 02 + 33 + 7A = E2. Has to be the last line of the file.  Simulation allows breakpoints that are impossible with hardware debuggers.  03. a sequence of n bytes of the data themselves. two hex digits. 00 to 05. four hex digits. Data. and other kinds of chips. Each line of Intel HEX fioile consists of six parts: 1. reliable embedded software development. Limited to 64 kilobytes. Start code. 5. one character. an ASCII colon ':'. Keil Monitor-51 driver is used. 6. data record. End Of File record. a 16-bit address of the beginning of the memory position for the data. 2's complement is 1E There are six record types:  00. Used when 16 bits are not enough. and making a 2's complement (either by subtracting the byte from 0x100. the latter two are the IP value. For example.  Simulation allows software testing on your desktop with no hardware environment. or inverting it by XOR-ing with 0xFF and adding 0x01). There are three types of Intel HEX: 8-bit. the byte count is 02 (the segment is 16-bit).the least significant byte of the two's complement sum of the values of all fields except fields 1 and 6 (Start code ":" byte and two hex digits of the Checksum). it specifies the initial content of the CS: IP registers. defining the type of the data field. The address field is 0000. Byte count. Extended Segment Address Record. No data. ECE. They are distinguished by their byte order. then leaving only the LSB of the result. The address specified by the 02 record is multiplied by 16 (shifted 4 bits left) and added to the subsequent 00 record addresses. EPROMs. 16 (0x10) or 32 (0x20) bytes of data are the usual compromise values between line length and address overhead. For ESA MCB-51 target board. Record type. Start Segment Address Record. and 32-bit. This address is big endian. Checksum. The format described above. segment-base address. Dept. 2. Start Linear Address Record. RVCE 12 .Embedded Systems & MC lab   04. The two data bytes represent the upper 16 bits of the 32 bit address. the byte count is 04. the byte count is 02. Extended Linear Address Record. allowing for fully 32 bit addressing. ECE. when combined with the address of the 00 type record. The 4 data bytes represent the 32-bit value loaded into the EIP register of the 80386 and higher CPU. The address field is 0000. 05. Dept. The address field is 0000. 2. #0100H R0. A DPL. 5. Get data from a source location into accumulator and save in a register 3. R0 A.source address . RVCE 13 . R1 A. #05H DPL. 6. Initialize a source pointer (R0). Save in a reg Dept. 4. @DPTR R2.Embedded Systems & MC lab Experiment 1 a) Write an assembly language program to exchange 5 bytes of data at locations 0100H and at locations 0150H.@DPTR A. Decrement the count register and repeat from step 2 to 5 till count is zero. ECE. Update pointers to point to next elements in the arrays. Algorithm 1. A DPL. Get data from the destination location into accumulator. R0 . Exchange the data at the two memory locations.Block is of length 5 elements MOV MOVX MOV MOV MOVX XCH MOVX MOV .destination address . a destination pointer (R1) & a counter (R3). Before Execution: After Execution: Program: ORG SJMP ORG MOV MOV MOV MOV BACK: 0000H 30H 30H DPTR. R2 @DPTR. #50H R3. #00H R1. 8. 7. 2.#0AH MOVX A.#0100H MOV R0. initialize the 5 data memory locations starting at 0100H & 0150H as shown below. To find SMALLEST. initialize R0 to FFH and use JNC instead of JC. Program: ORG 0000H SJMP 30H ORG 30H MOV DPTR. Update pointer to point to next element in the array. ECE. BACK HERE: SJMP HERE END Output: Before running the program. 4. Get data from a source location into accumulator and save in a register 3. R2 MOVX @DPTR.Embedded Systems & MC lab MOV A. Before Execution: After Execution: b) Write an assembly language program to find the LARGEST/SMALLEST element in array of 10 elements. store the current element as LARGEST element. Initialize a source pointer.#00H MOV R1. Algorithm 1. LARGEST element register & a counter. RVCE 14 . Largest element is initialized to 0 . Compare current array element with available LARGEST element. source address . Else. go to step 5 if current element is smaller. 6. no. Store the LARGEST after the last element of array. A INC R0 INC R1 DJNZ R3. Decrement the count register and repeat from step 2 to 5 till count is zero.@DPTR . of elements BACK: Dept. 5. R0 JC LOOP MOV A.A CLR C SUBB A. Decrement the COMPARISON counter and repeat through step 4 until this counter becomes 0.R0 MOVX @DPTR. 7.A INC DPTR DJNZ R1. 4. Write an assembly language program to sort an array of elements using BUBBLE SORT.R2 MOV R0.Embedded Systems & MC lab LOOP: MOV R2. end program.A HERE: SJMP HERE End Output: Before Execution: . For descending order use JC instead of JNC. carry flag is 0 MOV A. 6. Array starts from location 0101H and size of the array is at location 0100H. If the current element is larger (smaller for descending order) then exchange the 2 numbers in the array. an ITERATION (outer-R3) counter & a COMPARISON (inner-R2) counter. Decrement the ITERATION counter and repeat through step 3 until this counter becomes zero. Algorithm 1. Store the largest element After Execution: Underlined element is largest. 5. Initialize a source pointer.BACK . ECE. RVCE 15 . c) The given list 28 58 84 16 270 42 19 77 59 17 27 255 Dept. Check the number of elements and if it is equal to 0 or 1. Compare the current and the next element in the array. 2. 3. if A> R0. R0 . Program: ORG 0000H SJMP 30H ORG 30H MOV DPTR. 11 comparisons are to be done in first iteration and is reduces by 1 for each subsequent iteration.A MOV DPTR. @DPTR . R0 MOVX @DPTR . R1 MOVX @DPTR. This code excahnge two elements DJNZ R2.R3 MOV R2. ECE. # 0100H .Embedded Systems & MC lab Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5 Iteration 6 Iteration 7 Iteration 8 Iteration 9 Iteration10 Iteration 11 The final sorted list 28 28 16 16 16 16 16 16 16 16 16 58 16 28 28 19 19 19 17 17 17 17 16 58 42 19 28 28 17 19 19 19 19 84 42 19 42 42 17 27 27 27 27 27 42 19 58 58 17 27 28 28 28 28 28 19 77 59 17 27 42 42 42 42 42 42 77 59 17 27 57 57 57 57 57 57 57 59 17 27 57 58 58 58 58 58 58 58 17 27 57 59 59 59 59 59 59 59 59 27 57 77 77 77 77 77 77 77 77 77 57 84 84 84 84 84 84 84 84 84 84 255 255 255 255 255 255 255 255 255 255 255 16 17 19 27 28 42 57 58 59 77 84 255 Note that. RVCE . @DPTR MOV R0.compare with 1 DEC R3 NEXT1: MOV A. A CLR C SUBB A.(2nd . JC for descending order MOV A.First element NEXT : MOVX A. @DPTR JZ STOP . NEXT1 SJMP STOP 16 . A INC DPTR MOVX A. A INC DPTR NOEXCH: STOP: Dept. 11 iterations are required to sort array of 12 elements . NEXT DJNZ R3. A CLR C SUBB A. # 0101H .second element MOV R1. #01H JZ STOP .compare with zero MOV R3.Totally.1st) no 2nd >1st no exchange JNC NOEXCH . A DEC DPL MOV A.Number of elements MOVX A. Algorithm 1.Adjust Ms Part Of Result Also NEXT: Dept.A INC DPTR 17 . After Execution: d) Write an assembly language program to find the sum of an array of 8-bit BCD numbers starting at location 0100H.Adjust Ls Part Of Result To Bcd Form . a counter & a 16-bit result (partial SUM) register. Program: ORG 0000H SJMP 30H ORG 30H MOV DPTR.@DPTR ADD A. RVCE . Initialize a source pointer. # 05H . 5. Update pointer to point to next element in the array. A JNC NEXT MOV A.Source Address MOV R1. Add the first element to partial SUM register & suitably consider carry generated. #0100H . 4. of elements. 6. Store the result at location 0150H (Most Significant Byte) & 0151H (Least Significant Byte). Decrement the count register and repeat from step 2 to 4 till count is zero. R2 ADD A. Store the result present in partial SUM registers to the appropriate memory locations. #01H DA A MOV R2.Embedded Systems & MC lab END Output: Before Execution: The encircled number in the figure is no. # 00H .Partial Sum Lsbyte MOV R2. Adjust the result suitably to decimal form. 2. 3. ECE. # 00H .Partial Sum Msbyte MOV R3. R1 DA A MOV R1.Count BACK: MOVX A. Embedded Systems & MC lab DJNZ R3. R1 MOVX @DPTR. Use of ORG 0000H & END statements 2. A HERE: SJMP HERE END . ECE. R2 MOVX @DPTR. Use of HERE:SJMP HERE statement 4. Use of SJMP 30H & ORG 30H statements 3. RVCE 18 . Use of DA A instruction Dept. Use of MOVX statement 6. BACK MOV DPTR.#0150H MOV A.Store The Result Output: Before Execution: Enter BCD input After Execution: Observations to be recorded for Experiment 1 1. HEX file of any one program 5. A INC DPTR MOV A. Contents of code memory as seen in memory window of Keil for any one program Dept.lst file of any one program 8. Use of AT89c51ED2 as a target 10.Embedded Systems & MC lab 7. ECE. RVCE 19 . Setting clock a real number 9. . 5.#0100H MOVX A. Multiply the MS byte of the multiplicand with the multiplier.A HERE: SJMP HERE END Output: Before Execution: . RVCE 20 . A MOV A. B-MS byte . Store the result at locations 0103h. 0104h & 0105h. MS byte of Multiplier (MS) . 0101h & 0102h.A CLR A ADDC A. 4.Save second byte of result in 0104H .add carry of previous addtion to MS byte of . 8-bit multiplicand (MUP) .A MOV DPTR.#0102H MOVX A. A-LS byte.MS x MUP= 16 partial result2 . @DPTR MOV R2.R1 MUL AB ADD A.@DPTR MOV R1. result2 .Embedded Systems & MC lab Experiment 2 a) Write an assembly language program to find the product of a 16-bit number & an 8bit number stored at location 0100h. Add the LS part of present result with MS part of the previous result & store it.B INC DPTR MOVX @DPTR. MS byte of partial result1+ LS byte of partial . LS x MUP= 16 bit partial result1 . Algorithm 1. 3.save LS byte of result1 in 0103H .#0101H MOVX A. 6. ECE.A MUL AB INC DPTR MOVX @DPTR.LS Byte Of Multiplier (LS) . partial result2 .R2 MOV R3. 2.A MOV DPTR. Store the LS part of result & preserve the MS part of the result in a register.R3 INC DPTR MOVX @DPTR. Add the MS part of present result with carry of the previous addition & store it Program: ORG 0000H SJMP 30H ORG 30H MOV DPTR.@DPTR MOV B.Save MS byte of result in 0105H Dept. Multiply the LS byte of the multiplicand with the multiplier.B MOV B. Initialize a set of registers with operands. This code store result .#00H MOV DPTR.MS byte of 16 bit dividend MOV R3.Embedded Systems & MC lab After Execution:The correct result in odrder is FEFF01H b) Write an assembly language program to divide a 16-bit number in R2 & R3 by another 8-bit number in R4. Convert the 8 bit divisor to a 16 bit number (by prefixing 0’s). The operation is (R2R3) / (R5R4) . DPL MOV DPTR. 2. Repeat until (Dividend >Divisor) . 3. #0150H Dept.LS byte of 16 bit dividend MOV R4. R5 MOV R3. Store the result at location 150h & 151h. R2 ADD A. Algorithm 1. Subtract divisor from LS byte .e. R3 ADDC A. A MOV A. A MOV A. RVCE . 4. ECE. R4 MOV R2. A MOV A. R4 MOV R2. 8-bit divisor . Quotient will be there in DPTR (16-bit) 21 . DPH MOV R0. Get the correct remainder . R2 CLR C SUBB A. quotient & remainder at suitable locations. 5.#0FFFFH BACK: INC DPTR MOV A. Initialize a set of registers with operands & a 16 bit quotient register. #0FFh .#0FFh . Repeat step 3 as long as (dividend) > (divisor).16 bit quotient in DPTR . A JNC BACK MOV A. Subtract the 16 bit divisor from the 16 bit dividend & increment the quotient register. Store the result i. 6. R3 SUBB A. R5 MOV R3. #0E8H MOV R5. The division operation is implemented as repeated subtraction. Program: ORG 0000H SJMP 30H ORG 0030H MOV R2. Subtract divisor from MS byte . Change the values of registers depending upon operation required.Embedded Systems & MC lab MOVX @DPTR. RVCE 22 . The 16-bit remainder will be there in . Program: ORG 0000H SJMP 30H ORG 30H MOV A.HERE DJNZ R2. 3. Use a delay subroutine (in delay program load designed values to R1.register with 00h 2. A OVER: SJMP OVER END Output: After Execution: . Initialize A . A MOV A. select Dept. R3 INC DPTR MOVX @DPTR. A MOV A. after selecting DEBUG session in the main menu.#0FFH DJNZ R3. loop and decrement until 0) to create a delay of 1 second. ECE. R2 and R3. R2 INC DPTR MOVX @DPTR. decrement a for binary down counter MOV R1. Increment A .#20H MOV R2. R3(MS byte) and R2(LS byte) The above program also performs division of two sixteen bit numbers.DECR1 DJNZ R1.#0FFH MOV R3.register (decrement for down counter) repeatedly. A MOV A. DECR RET END Note: To run this program. Algorithm: 1.#00 BACK: ACALL DELAY INC A SJMP BACK DELAY: DECR: DECR1: HERE: . c) i) Write an ALP to implement (display) an eight bit up/down binary (hex) counters on watch window. R0 INC DPTR MOVX @DPTR. store ‘0’. Program: ORG 0H SJMP 30H ORG 30H MOV A. R2 and R3.#20H MOV R2.TEMP DJNZ R2. #0FFH DJNZ R3. ECE. else logically OR them and store the result in 5th location of the array. RVCE 23 . Algorithm: 1. then store ‘1’ in the last bit of bit addressable memory (7FH). then logically AND all 4 elements. in the Watches select watch 1(or 2) and press F2 and enter a (for accumulator A) d) Write an ALP using subroutines to perform the following. an array of 4 elements is stored in external memory locations starting from 0100H. Use a delay subroutine (in delay program load designed values to registers R1. DECR DJNZ R1. ii) If the last two elements are equal. else.#0FFH MOV R3. after selecting DEBUG session in the main menu. #01 for BCD up counter DELAY: DECR1: DECR: TEMP: . in the Watches select watch 1(or 2) and press F2 and enter a (for accumulator A) as shown below. else. iii) If both these bits are set. ii) Write an ALP to implement (display) an eight bit up/down BCD counters on watch window. store ‘0’. Add A register with 01 and decimal adjust the result (for down counter add 99h) repeatedly. select View-> Watch& call Stack window. loop and decrement until 0) to create a delay of 1 second.register with 00h 2. Initialize A .ADD.#00 BACK:ACALL DELAY ADD A. then store ‘1’ in the first bit (00H) of bit addressable memory. 3.Embedded Systems & MC lab View-> Watch& call Stack window. i) If the first two elements are equal.#99H DA A JNZ BACK HERE:SJMP HERE MOV R1. DECR1 RET END Note: To run this program. Dept. if both bits are set.@DPTR MOV R2. Program: ORG 0000H SJMP 30H ORG 30H MOV DPTR.A INC DPTR MOVX A. Compare the last 2 numbers for equality using sub-routine SECOND & store result in bit address 7Fh.02H. A STOP: SJMP STOP NEXT: ACALL L_OR JMP OVER FIRST: CJNE A. NEXT ACALL L_AND OVER:INC DPTR MOVX @DPTR.@DPTR MOV R0.@DPTR MOV R3. SKIP SETB 00H RET SKIP: CLR 00H RET SECOND: CJNE A. else. 5. logically OR them using L_OR sub-routine. 4.A ACALL SECOND JNB 7FH. then logically AND all elements using L_AND sub-routine. NEXT JNB 00H.Embedded Systems & MC lab Algorithm: 1. SKIP1 SETB 7FH RET SKIP1: CLR 7FH RET Dept.A INC DPTR MOVX A. ECE. Read the elements of the array from the address 0100h 2. Check the result of steps 2 & 3. Compare the first 2 numbers for equality using sub-routine FIRST & store result in bit address 00h.00H. 3. Store the result in 5th location.@DPTR MOV R1.#0100H MOVX A. A ACALL FIRST INC DPTR MOVX A. RVCE 24 . RVCE 25 . Move NUM1 from internal data memory location20h into R0 register.R1 ANL A.R1 ORL A. Store the bit result in last address of bit addressable memory. R0 ANL A. NUM2 & NUM3 are stored in internal data RAM locations 20h. i) If NUM1=0.R2 ORL A. then LSB of 21h (AND) LSB of 22h. ii) If NUM1=1. e) 3-eight bit numbers NUM1. Go to step5. iii) If NUM1=2.R3 RET L_OR: MOV A. 2. enter D: 20H in memory #2 window as shown below. If NUM1=0. Write an ALP to compute the following. 21h & 22H respectively.R2 ANL A. Dept. then Complement MSB OF NUM2.Embedded Systems & MC lab L_AND: MOV A. ECE.R3 RET END Output: Before Execution: After Execution: To observe the bit addressable memory locations of internal data RAM. Algorithm: 1. R0 ORL A. then MSB OF NUM3 (OR) MSB OF NUM2. then LSB OF NUM3 (AND) LSB OF NUM2. MSB of NUM2 (21H) .#1.CK3 CPL 0FH MOV C.NUM1 . If NUM1=1.LSB of NUM2 (21H) .CK2 MOV C.#2.MSB of NUM1 (21H) . Go to step5 5. If NUM1=2. ECE.08H ANL C.bit address -17h .C . Program: ORG 00H SJMP 30h ORG 30h MOV R0.R0 .0FH ORL C.bit address -0Fh .RES location -7Fh HERE:SJMP HERE END Output: Run 1: Before Execution: RAM location: 20h=00h (NUM1) RAM location: 21h=FFh(NUM2) RAM location: 22h=FFh(NUM3) After Execution: RAM location: 20h=00h(NUM1) RAM location: 21h=FFh(NUM2) RAM location: 22h=FFh(NUM3) RAM location: 2Fh=80h (NUM2LSB AND NUM3LSB) Run 2: Before Execution: RAM location: 20h=01h (NUM1) RAM location: 21h=FFh(NUM2) RAM location: 22h=FFh(NUM3) After Execution: RAM location: 20h=01h(NUM1) RAM location: 21h=FFh(NUM2) RAM location: 22h=FFh(NUM3) RAM location: 2Fh=80h (NUM2MSB OR NUM3MSB) Run 3: Before Execution: Dept.#0.bit address -0Fh .CK1 MOV C.0FH SJMP LAST CK3:CLR C LAST:MOV 7Fh.bit address -08h .MSB of NUM3 (22H) . Go to step5. 4. Store the result at MSB bit of 7Fh location.17H SJMP LAST CK2:CJNE R0.LSB of NUM3 (22H) .Embedded Systems & MC lab 3. RVCE 26 .20H CJNE R0.bit address -10h .10H SJMP LAST CK1:CJNE R0. then complement MSB of 21h. then MSB of 21h (OR) MSB of 22h. Observations to be recorded for Experiment 2 1. Instruction execution time in terms of clock cycles. Effect of changing clock frequency on program execution time.Embedded Systems & MC lab RAM location: 20h=02h (NUM1) RAM location: 21h=FFh(NUM2) RAM location: 22h=FFh(NUM3) After Execution: RAM location: 20h=02h(NUM1) RAM location: 21h=7Fh(NUM2 MSB is complemented) RAM location: 22h=FFh(NUM3) RAM location: 2Fh=00h (NOT of NUM2MSB) The bit address 7Fh is MSB of RAM location 2Fh. Contents of data memory as seen in Keil memory window 7. RVCE 27 . Use of Byte level & Bit level instructions 5. Use call stack window 4. delay loops 3. Effect of clock frequency on timer delay 10. Use of peripheral window of to observe timer count sequence 9. Opcode for all ACALL instructions in a program 6. machine cycles & instruction cycle Dept. 2. ECE. Use of ASCII symbols 8. Pointer for program memory & data memory. Move the BCD data to be converted to accumulator.#0FH .#50H MOV A. Algorithm: 1.5 pin for 250 µSec and clear for another 250µSec.e. 4. Dept. Set P1. 3. Repeat step 2 and 3 indefinitely. Initialize Timer0 in mode-1. ECE. The given data is. duty cycle 0.Store the upper digit's ASCII code HERE: SJMP HERE END Output: Before Execution: Internal RAM location: 50H=28(BCD) Internal RAM location: 51H=00 Internal RAM location: 52H=00 After Execution: Internal RAM location: 50H=28(BCD) Internal RAM location: 51H=38(ASCII equivalent of 8) Internal RAM location: 52H=32(ASCII equivalent of 2) b) Write an ALP to generate a square wave of 2 KHz..A .Swap nibbles in A ANL A.@R1 .#30H .A .Store in R2 ANL A.5 by programming on-chip timer in mode-1.0592/12=0. 0-9 converted to 30-39h INC R1 MOV @R1. Store the converted ASCII value 4.Get the lower nibble ORL A.get BCD data byte from RAM location 50h MOV R2. 2.#30H . Load suitable values in to TH0 and TL0 registers.Convert to ASCII INC R1 MOV @R1.Store the lower digit's ASCII code MOV A. RVCE 28 .Embedded Systems & MC lab Experiment 3 a) Write an ALP to convert a BCD number stored at a location into its ASCII equivalent number. Algorithm 1.5 on P1.A .R2 .9216 MHz Let the number states of TL0 register required for 250 µSec be x. 2.Add/OR with 30h i. Get the higher nibble(tens BCD digit) & ADD (or ORL) with 30h 5. Store the converted ASCII value Program: ORG 0000H SJMP 30h ORG 30h MOV R1. Get the lower nibble(BCD digit) & ADD (or ORL) with 30h 3. Period=500 µSec Duty cycle=50% TON=250µSec TOFF= 250µSec Input clock frequency to Timer0= Oscillator frequency/12=11.Get back the number SWAP A .Get the upper BCD digit ORL A.#0FH . this opens up Setup Logic Analyzer window as shown below.TOFF period MOV TH0. The square wave is generated continuously as shown below. #1Ah . ECE. RVCE 29 . TON period MOV TH0.4 Therefore. Dept. the value to be loaded into TL0 register=256-230=26D=1AH For different duty cycles. Use time cursor to display time values.   Click on New icon and enter P1.9216 M)=>x=230. HERE TR0 TF0 .5 as shown in above figure and close.  Under View menu select Logic Analyzer window after start debugging option.5 ACALL DEL MOV TL0. Select Run option under debug menu. this is delay routine Output: To run this program in simulation mode follow the procedure given below. Program: ORG 0h SJMP 30h ORG 30h MOV TMOD. #0FFh CLR P1. #1Ah .5 ACALL DEL SJMP REP DEL: SETB HERE: JNB CLR CLR RET END TR0 TF0.  Select SetUp icon in Logic Analyzer window. Timer-0. load different values into TL0 register for TON & TOFF. #01H . mode-1 REP: MOV TL0.Embedded Systems & MC lab 250 µSec=x(1/0. #0FFh SETB P1. #209 MOV TL0. RVCE 30 .Start the timer0 .05 mSec) is generated.05 mSec be x. R1 & R0.0592/12=0. Update r1 & r0 8.05 mSec=x(1/0. in ISR remaining delay (1 sec -0.5 of AT89C51ED2 on ESA MCB 51 target board to display square wave. Enable timer & return from ISR From the given question it is understood that.#0 MOV R1. On interrupt. Load TH0 and TL0 with 208 to generate an interrupt every 0. Set up timer0 in mode 2 operation 2. the value to be loaded into TL0 register=256-47=209D Note that.#00 MOV R0. 5. ECE. Yes –increment accumulator a.05msec. Algorithm: 1.#209 MOV IE.4 . 4.05msec .#0 MOV TMOD.Disable timer0 Dept.TF0 vector . 0. Reset registers A.#82H SETB TCON. Check if 20000 interrupts (=1 sec) over.05 mSec. ISR at 000B location goes to step 6 6.08 Therefore. 9. timer0 overflow interrupt should be generated for every 0.9216 M)=>x=46. Program: ORG 0H SJMP 30H ORG 0BH SJMP ISR ORG 30H MOV a. Run the timer0. disable timer0 7.Set up timer 0 to overflow in 0.set timer0 in mode 2-auto reload .9216 MHz Let the number states of TL0 register required for 0.4 HERE: SJMP HERE ISR: CLR TCON. 3.Enable global & timer0 interrupt . c) Generate a 1second delay continuously using the on chip timer in interrupt mode. Input clock frequency to Timer0= Oscillator frequency/12=11.#02H MOV TH0.Embedded Systems & MC lab Connect CRO to P1. 4 .SKIP MOV r0. TL0 for generating 4KHz frequency with 75% duty cycle 5.#200.Embedded Systems & MC lab INC r1 CJNE r1. Advantage of generating delay using Timers 2. Dept.#00H INC A . Enable Timer RETI .SKIP MOV r1. ECE.#100. RVCE 31 . Observations to be recorded for Experiment 3 1. Methods to generate delay 3. Values of TH0.#00 INC r0 CJNE r0. Return from interrupt subroutine END Output: Observe the value of accumulator incrementing approximately for every 1 sec in watch and call stack window.05msec = 1sec SKIP: SETB TCON. Use of call stack window 4.r1*r2 = 100*200 = 20000 * 0. DIP switches can be used and to output can be displayed on LEDs. for(i=0. // masking MSB bits for full adder operation temp = P1 & 0x07. Logic Controller Interface: Logic controller interface consists of 8 TTL inputs connected to 8 DIP switches & 8 TTL outputs connected to 8 LEDs. switch 2 (SW2) on board for updating input changes]. 0x03}. Dept. temp. different logical operations can be performed. ECE. To give input.j. 0x01.h> void msdelay(unsigned int itime) { unsigned int i. } void main() { unsigned char arr[] = {0x00. So. 0x01. (Port 2 is not used) Program: #include<reg51. Another set of 8 LEDs used to indicate status of each DIP switch.j++) .i<1275. 0x01. Connection diagram: From the connection diagram. [Input port is P1 and the Output port is P0 for interfacing board.j<itime. // configuration input port while(1) { P0 = 0x03 & P0. Using this interface card.i++) for(j=0. it is observed that the DIP switches are connected to port 1(to be configured as input) output LEDs are connected to port 0(to be configured as output). 0x02.Embedded Systems & MC lab Experiment 4 a) Write an 8051 C program to interface Logic Controller card and perform various logical functions. the control word for above configurations is obtained as follows. 0x02. RVCE 32 . P0=0x00. 0x02. // output port P1 = 0xff. the stepper motor is used for position control. The stator poles are determined by the current sent through the wire coils. dot matrix printers. else if (temp ==6) P0 = arr[6]. XOR etc. } } Activity: Do 4 possible logical operations using the above program (full subtracter. The stepper motor is a widely used device that translates electrical pulses into mechanical movement. msdelay(50). else if (temp ==5) P0 = arr[5].. else if (temp ==3) P0 = arr[3]. the polarity is also changed causing motor rotate in opposite direction. and robotics. else if (temp ==4) P0 = arr[4]. In applications such as disk drives. As direction of current changed. This type of stepper motor is commonly called as a four-phase or unipolar stepper motor.) b) Write 8051 C program to interface stepper motor to rotate in clockwise/ anti clockwise directions & and to rotate the motor through predefined angle of rotation.Embedded Systems & MC lab if (temp ==0) P0 = arr[0]. RVCE 33 . else P0 = arr[7]. The stepper motor moves in fixed repeatable increment. ECE. As the Dept. Hence. which allows one to move it to a fixed precise position. logical OR. Stepper motors commonly have a central magnet called rotor or shaft surrounded by stator. else if (temp ==2) P0 = arr[2]. The direction of rotation is dictated by the stator poles. the unipolar stepper motors have 6 leads: 4 representing the four stator windings and 2 commons for the center tapped leads. else if (temp ==1) P0 = arr[1]. The most common stepper motors have four stator windings that are paired with center-tapped common as shown in figure below. in a stepper motor with 200 steps per revolution. a driver (Darlington pair formed by 2N3055 & SL100) is used. The curtain amount of minimum of current is required to energize the coils.1 is connected to coil D. the rotor will rotate. Note that. P0.Embedded Systems & MC lab sequence of power is applied to each stator winding.8o).8º. the steps per revolution is 200 (360o / 1. So.2 is connected to coil A. Interfacing diagram: Dept. There are several widely used sequences where each has a different degree of precision. 8051 lacks sufficient current to drive. Therefore. Step coil A coil B coil C coil D 1 0 0 0 1 2 1 0 0 0 Clockwise Anti clockwise 3 0 1 0 0 4 0 0 1 0 Anyone of these values forms the initial value. The step angle is minimum degree of rotation associated with a single step. The table below shows 1-phase. the rotor moves only by one tooth pitch.0 is connected to coil C.3 is connected to coil B. It must be noted that P0. after completing every four steps. This depends on number teeth on rotor and stator. It must be noted that although we can start with any of the sequences in table. ECE. once we start we must continue in the proper order. It is 1-phase because at any time only one coil is excited. P0. 4-step stepping sequence. P0. The step angle of motor using in lab is 1. the rotor has 50 teeth since 4 x 50=200 steps are needed to complete one revolution (Refer figure below). Since. RVCE 34 . P0=sequence4. the stepper motor moves in clockwise direction. delay(2500).i<delayvalue. direction=direction & 0x08. P0=sequence1. for(i=0. The program should monitor switch status and perform the following.i++).Embedded Systems & MC lab Write a program to rotate a motor continuously both in clockwise and anticlockwise direction. } else { P0=sequence4. delay(2500). RVCE 35 . Program: #include<reg51. void main() { unsigned char direction. } } } void delay(int delayvalue) { int i.h> #define sequence1 0x01 #define sequence2 0x08 #define sequence3 0x04 #define sequence4 0x02 void delay(int). i) If Switch is closed. delay(2500). if(direction==0x08) { P0=sequence1. while(1) { direction=P3. } Dept. delay(2500). delay(2500). ii) If switch is opened. P0=sequence2. delay(2500). P0=sequence2. delay(2500). Use switch connected to P3. ECE. delay(2500).3 in ESA MCB 51 target board. the stepper motor moves in anticlockwise direction. P0=sequence3. P0=sequence3. i++). } } } void delay(int delayvalue) { int i. EX0=1. void delay(int). ECE. delay(2500). } //ISR of interrupt 0 //Enable interrupt //Enable external interrupt 0 Dept.i<delayvalue. P0=sequence2. while(1) { if(dir) { P0=sequence1. P0=sequence3. } void main() { EA=1. P0=sequence2. delay(2500). P0=sequence1. delay(2500). delay(2500). delay(2500). delay(2500). P0=sequence3.h> #define sequence1 0x01 #define sequence2 0x08 #define sequence3 0x04 #define sequence4 0x02 bit dir=0. delay(2500). P0=sequence4.Embedded Systems & MC lab Alternate program using interrupts: #include<reg51. delay(2500). void change_dir()interrupt 0 { dir=~dir. RVCE 36 . } else { P0=sequence4. for(i=0. Embedded Systems & MC lab Write a program to rotate motor 180º in the clockwise direction. The motor step angle is 1.8º. Use the 4-step sequence. The given data is, Step angle=1.8º /step Therefore, for 4-step the angle of rotation= 4x1.8 =7.2º. For 180º, the 4-step sequence must be repeated for 25 times(180º / 7.2º) Program: #include <REG51.H> void delay (unsigned int x) { for(;x>0;x--); return; } main ( ) { unsigned char val; int x=0,i; P0=0x00; while(x<25) { val=0x11; for(i=0;i<4;i++) { P0=val; val=val>>1; //Perform << shift for other direction. delay(5000); } x++; } for(;;); } Alternate exam questions: 1. Write a program to rotate stepper motor 45 degrees in clockwise & 90 degrees in anti clockwise direction continuously. 2. Write a program to rotate stepper motor continuously in clockwise direction for 1 sec, halt for 0.5 sec and in anticlockwise direction for 1sec, halt for 2 sec and repeat. Observations to be recorded for Experiment 4 1. Use of micro stepping in stepper motor 2. Writing program in assembly and ‘C’[code size and program execution] 3. Memory location for Variables declared in ‘C’ Dept. ECE, RVCE 37 Embedded Systems & MC lab 4. Use of REG51.h header file 5. Purpose of using interrupts over polling mode 6. Contents of stack for function calls in C program 7. Use of flash as program memory 8. Logic high and logic low voltage levels of port pins 9. Stepper motor voltage & current ratings Dept. ECE, RVCE 38 Embedded Systems & MC lab Experiment 5 a) Write an ALP to convert a decimal number stored at a location 40H into its hexadecimal equivalent number. b) Write an 8051 C program to interface elevator card & simulate the operations of the elevator. Interfacing Diagram: The interface has four keys marked 0, 1, 2 and 3 representing the request buttons at the four floors. Pressing of a key causes corresponding flip-flop to be set. The outputs of the four flip flops can be read through port 1(P1.0, P1.1, P1.2 & P1.3). Also, the status of these signals is reflected by a set of 4 LEDs. The flip-flops can be reset through port 0(P0.4, P0.5, P0.6 & P0.7). The column of 10 LEDs representing the elevator can be controlled through port 0(P0.0,P0.1, P0.2 & P0.3). These lines are fed to the inputs of the decoder 7442 whose outputs are used to control the on/off states of the LEDs which simulate the motion of the elevator. Program: #include <REG51.H> #define CHECK(j) (j==0||j==3||j==6||j==9) unsigned char checkPort1(unsigned char); void delay(unsigned int); sbit Flr1=P1^0; sbit Flr2=P1^1; sbit Flr3=P1^2; sbit Flr4=P1^3; main() { unsigned char Flr[9] = {0xff,0x00,0x03,0xff,0x06,0xff,0xff,0xff,0x09}; unsigned char FClr[9] = {0xff,0x0E0,0x0D3,0xff,0x0B6,0xff,0xff,0xff,0x79}; unsigned char ReqFlr,CurFlr = 0x01,i,j,NewFlr; P0 = 0x0f0; Dept. ECE, RVCE 39 ECE. RVCE 40 . /* Clear Floor Indicator */ continue.i>0. } } else /* If Current floor is < request floor */ { i = Flr[ReqFlr] . continue. for(. j--. ReqFlr = P1 | 0x0f0. } /* Go up to read again */ else if(CurFlr > ReqFlr) /* If Current floor is > request floor */ { i = Flr[CurFlr] . for(. delay(15000).i--) /*Move the indicator down */ { if(CHECK(j)) { NewFlr=checkPort1(j). /* Get the no of floors to travel */ j = Flr[CurFlr].Embedded Systems & MC lab while(1) { P1 = 0x0f. if(NewFlr!=0) { P0 = FClr[NewFlr]. delay(65000). continue.Flr[ReqFlr]. j++.i>0. } } P0 = 0x0f0 | j. delay(65000). j--. ReqFlr = ~ReqFlr.i--) /* Move the indicator Up */ { if(CHECK(j)) { NewFlr=checkPort1(j). /* Get the no of floors to travel */ j = Flr[CurFlr]. while(ReqFlr == 0x0ff) ReqFlr = P1 | 0x0f0. if(NewFlr!=0) { P0 = FClr[NewFlr]. /* Read Request Floor from P1 */ if(CurFlr == ReqFlr) /* If Request floor is equal to Current Floor */ { P0 = FClr[CurFlr].Flr[CurFlr]. Dept. else return 0.Embedded Systems & MC lab } } P0 = 0x0f0 | j. else if(j==0 && Flr1==0) return 0x01. } unsigned char checkPort1(unsigned char j) { if(j==9 && Flr4==0) return 0x08. } Observations to be recorded for Experiment 5 1. ECE. Use of SBIT data type 3. else if(j==3 && Flr2==0) return 0x02. delay(15000). else if(j==6 && Flr3==0) return 0x04.x>0. Contents of disassembly window as seen in keil IDE for any one program. j++.x--). } } void delay(unsigned int x) { for(. Use of latched ports /* Update Current floor */ /* Clear the indicator */ /*End of while*/ 2. RVCE 41 . Dept. } } CurFlr = ReqFlr. P0 = FClr[CurFlr]. ECE. RVCE 42 . Use of max232 IC 8. Logic high and logic low current levels of port pins 5. Use of buffers to connect external devices 6. Fan in & Fan out of 8051 MCU 7.Embedded Systems & MC lab 4. Monitor 51 Program Dept. " This control line is used to tell the LCD that you are sending in data.). • When RS is high (1). • When the other lines are completely ready.  The RW line is the "Read/_Write" control line.  The EN line is called "Enable.  If a 4-bit data bus is used the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for the data bus). • To send data to the LCD.If an 8-bit data bus is used the LCD will require a total of 11 data lines (3 control lines plus the 8 lines for the data bus).  The three control lines are referred to as EN.  The LCD driver requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. • When RS is low (0). the data being sent is text data which should be displayed on the screen. • When R/W is low (0).  The RS line is the "Register Select" line. bring EN high (1) • High to low pulse is applied on this pin to latch in the data present at the data pins. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. • For example.Embedded Systems & MC lab Experiment 6 a) Write 8051 C program to interface 4 x4 keypad &display the key pressed on LCD Interfacing Diagram: LCD Interface: The LCD on ESA 51 MCB board is interfaced to 8051 as shown in diagram above. RS. Dept. The table below gives different pin descriptions. etc. RVCE 43 . the data is to be treated as a command or special instruction (such as clear screen. your program should make sure this line is low (0) • Set the other two control lines and/or put data on the data bus. the information on the data bus is being written to the LCD. ECE. to display the letter "T" on the screen you would set RS high. position cursor. and R/W. The LCD is 16x2(16 characters each in two rows) and has 16 pins. void scan(void). sbit busy=P2^7. The interfacing diagram shows 4x4 matrix connected to two ports. Pin 1 2 3 4 Symbol I/O Description VSS -. sbit en=P3^5. RVCE 44 . The busy flag(D7) combined R/W & RS is used to read LCD status.h> void get_key(void). sfr ldata=0XA0.+5 V Power supply VEE -.Power supply for back light(5 V) 16 VSS -. Only one instruction (reading LCD status) is a read command. void lcd_cmd(unsigned char value). void delay(unsigned int itime). When D7=0. The rows are connected to an output port and columns are connected to input port. one of the columns will have 0(zero) since the key pressed provides the path to ground.Power supply to control contrast(0 -5 V) RS I RS=0 to select command register. If no key is pressed. the LCD is ready to receive new information. sbit rw=P3^6. RS=1 to select data register 5 R/W I R/W=0 for write R/W=1 for read 6 E I/O Enable 7 D0 I/O 8 D1 I/O 9 ` D2 I/O 10 D3 I/O 8-bit data bus 11 D4 I/O 12 D5 I/O 13 D6 I/O 14 D7 I/O 15 VDD -.Ground Keyboard Interface: The keyboards are organized in a matrix of rows and columns. If all rows are grounded and a key is pressed.Embedded Systems & MC lab • • When R/W is high (1). Dept. Program: include<reg51. ECE. void display(void).RS =0 if D 7=1(busy flag=1) the LCD is busy taking care of internal operations and will not accept any new operation. the reading the input port will yield 1s for all columns since they are all connected to high (VCC). If R/W=1 . void lcd_data(unsigned char value). sbit rs=P3^7. It is the function of the microcontroller to scan the keyboard continuously to detect and identify the key pressed. the program is effectively querying (or reading) the LCD. It is recommended to check the busy flag before writing any data to the LCD. The controller accesses both rows and columns through ports.Ground VCC -. res1. display(). // DISPLAY ON. void main () { lcd_cmd(0x38). //CLEAR DISPLAY while(1) { get_key(). 5X7 DOT MATRIX lcd_cmd(0x0E).flag. } } void get_key(void) { flag =0x00. // 8 BIT DATA . else if(row==2) temp3=0xfb. NO BLINK lcd_cmd(0x01). idata temp2. scan().row++) { if(row==0) temp3=0xfe. 2LINE. delay(10). Dept. } if(flag==0xff) break. CURSOR ON.temp3.row. while(1) { for(row=0.Embedded Systems & MC lab void lcd_ready(). RVCE 45 .row<4. ECE. else if(row==3) temp3=0xf7. } } void scan(void) { unsigned char t. P0=0xff. else if(row==1) temp3=0xfd. P1=temp3. if(flag==0xff) break. delay(30). if(temp2!=0x0f) { flag=0xff. if(temp3==0xfb && res1==0x0e) res1='8'. temp2=P0. } else flag=0x00. if(temp3==0xfb && res1==0x0d) res1='9'. RVCE 46 . if(temp3==0xfd && res1==0x0e) res1='4'. if(temp3==0xfb && res1==0x07) res1='B'. if(temp3==0xfb && res1==0x0b) res1='A'. if(temp3==0xf7 && res1==0x0e) res1='C'. if(temp3==0xfd && res1==0x0b) res1='6'. if(temp3==0xfe && res1==0x0b) res1='2'. if(temp3==0xfe && res1==0x07) res1='3'. if(temp3==0xfd && res1==0x07) res1='7'. temp2=temp2&0x0f. res1=temp2. if(temp2!=0x0f) { delay(30). if(temp3==0xf7 && res1==0x07) res1='F'.Embedded Systems & MC lab temp2=P0. ECE. if(temp3==0xf7 && res1==0x0b) res1='E'. temp2=temp2&0x0f. if(temp3==0xfe && res1==0x0e) res1='0'. if(temp3==0xfd && res1==0x0d) res1='5'. if(temp3==0xfe && res1==0x0d) res1='1'. if(temp3==0xf7 && res1==0x0d) res1='D'. } } Dept. } void lcd_cmd(unsigned char value) { lcd_ready(). ECE. en=1. ldata=value. lcd_data(ldata).j++). return. return. RVCE 47 . lcd_cmd(0x80).i++) for(j=0. } Dept. ldata=value. rs=1.j<50. } return. rw=0. } void delay(unsigned int itime) { unsigned int i.Embedded Systems & MC lab void display(void) { lcd_cmd(0x01). delay(5). rs=0. en=0. en=1.i<itime. for(i=0. delay(5). ldata=res1. en=0. en=1. } void lcd_ready() { busy=1. rw=1. rw=0. } void lcd_data(unsigned char value) { lcd_ready(). delay(5).j. delay(5). rs=0. while(busy==1) { en=0. // FIRST LINE delay(5). row. SCON=0x50. } void get_key(void) { flag =0x00. t++) { get_key(). delay(100). t++) { send(arr[t]). TL1=-3. } while(1). t<4.temp3. void scan(void).Embedded Systems & MC lab b) Write 8051 C program to interface 4 x 4 keypad & accept 4 keys consecutively and send to serial port Program: #include<reg51.h> void get_key(void).res1. void send(unsigned char q). delay(150). idata temp2. arr[t]= res1.flag. for(t=0. ECE. t<4. void send_string(). void delay(unsigned int itime). send_string(). //serial communication settings TMOD=0x20. TH1=-3. RVCE 48 . arr[5]. TR1=1. Dept. } for(t=0. void main () { unsigned char t =0. res1=temp2. if(temp3==0xfe && res1==0x0b) res1='2'. ECE.row<4. temp2=P0. } if(flag==0xff) break. RVCE 49 . scan(). if(temp3==0xfe && res1==0x0e) res1='0'. else if(row==1) temp3=0xfd. else if(row==2) temp3=0xfb. if(temp3==0xfd && res1==0x0e) Dept. if(temp3==0xfe && res1==0x0d) res1='1'. } } void scan(void) { P0=0xff. delay(100). flag=0xff. if(temp2!=0x0f) { delay(100). if(temp3==0xfe && res1==0x07) res1='3'.Embedded Systems & MC lab while(1) { for(row=0. else if(row==3) temp3=0xf7. P1=temp3.row++) { if(row==0) temp3=0xfe. if(flag==0xff) break. temp2=temp2&0x0f. if(temp3==0xf7 && res1==0x0b) res1='E'. for(i=0. if(temp3==0xfb && res1==0x0d) res1='9'.j. if(temp3==0xf7 && res1==0x0e) res1='C'. if(temp3==0xfd && res1==0x0b) res1='6'. if(temp3==0xfd && res1==0x0d) res1='5'. } } Dept. ECE. } else flag=0x00.i<itime. } void delay(unsigned int itime) { unsigned int i. if(temp3==0xf7 && res1==0x07) res1='F'. i++. if(temp3==0xf7 && res1==0x0d) res1='D'. if(temp3==0xfb && res1==0x0e) res1='8'. while(temp[i]!='\0') { send(temp[i]).i++) for(j=0. if(temp3==0xfb && res1==0x07) res1='B'. RVCE 50 .Embedded Systems & MC lab res1='4'. char i=0. if(temp3==0xfb && res1==0x0b) res1='A'.j++).j<50. } void send_string() { unsigned char temp[20]={“\nKeys Pressed:”}. if(temp3==0xfd && res1==0x07) res1='7'. Observations to be recorded for Experiment 6 1. TI=0. Use SFR data type 6. Serial baud rate generation 7. RAM locations used for stack operations in C programs 5. Allocation of program memory for a program written in ‘C’ 2. while(!TI). Memory allocation for variables declared in C 3.Embedded Systems & MC lab void send(unsigned char q) { SBUF=q. Null modem connection Dept. Use of header files reg51. Types of LCDs 8. ECE. } Alternate exam question: Write a program to interface 3x8 keyboard and LCD to microcontroller. LCD command set 9. Baud rate Vs Bit rate 10. RVCE 51 .h 4. RVCE 52 . #50h . mode-2 MOV TH1. @A+DPTR JZ STOP ACALL SEND INC DPTR SJMP AGN STOP: SJMP STOP SEND: MOV SBUF. auto reload). 1-stop bit. Hence in the subroutine wait until TI is set. In serial asynchronous transmission. 8-bit data with 1-start bit & 1stop bit. HERE . In serial transmission as opposed to parallel transmission. Baud rate Calculation: Crystal freq/ (12*32) = (11. ECE.mode-1. After the transmission.e. MOV SCON. (The program can also be written in interrupt mode). The 8-bit character is transferred one bit at a time.Embedded Systems & MC lab Experiment 7 a) Write an ALP to transmit a message “RVCE IS MY COLLEGE” serially by programming the serial port with a baud of 9600. followed by 8 bits of data to be transmitted and finally the stop bit.. 8 bit data. The stop bit is transferred. one bit at a time is transmitted.baud rate of 9600. The speed of the serial transmission is set by the baud rate which is done with the help of timer 1. The byte character to be transmitted is written into the SBUF register. monitor TI flag for completion CLR TI RET MYDATA: DB "RVCE IS MY COLLEGE.0592MHz)/(12*32) = 28800 Serial communication circuitry divides the machine cycle frequency (11.0 END Dept.1-start bit.Timer-1.0592MHz)/(12) by 32 before it is being used by the timer to set the baud rate. #-3h . #20h . Later clear the TI flag and continue with transmission of the next byte by writing into the SBUF register. FF – 3 = FD) for further clock division. To get 9600.". Program: ORG 0 SJMP 30H ORG 30H MOV TMOD. It transmits the start bit. SETB TR1 MOV DPTR. the data consists of a Start bit (high). #MYDATA AGN: CLR A MOVC A. A HERE: JNB TI. the TI flag = 1 indicating the completion of transmission. 28800/3 is obtained by loading timer1 with -3 (i. Timer1 must be programmed in mode 2 (that is. For 2400 baud rate. 28800/12 => -12 = F4 in TH1. 8-bit. // FIRST LINE SCON=0x50. //serial communication settings TMOD=0x20. sbit rs=P3^7. after selecting DEBUG session in the main menu use View-> serial window #1. On running & halting the program. res1=SBUF. NO BLINK lcd_cmd(0x01). TR1=1. void display(). TL1=-3. lcd_cmd(0x38). EA=1. void main () { ES=1. sbit rw=P3^6. RI=0. } void receive()interrupt 4 { ES=0. unsigned char res1. 2LINE. sbit busy=P2^7. b) Write an 8051 C program to transmit characters – consecutively using internal serial interrupt and display the same on LCD interface. } void display(void) { Dept. #include<reg51. RI=0. void lcd_cmd(unsigned char value). RVCE 53 . 5X7 DOT MATRIX lcd_cmd(0x0E). // 8 BIT DATA . void lcd_ready(). ECE. the data is seen in the serial window. // DISPLAY ON. while(1). TH1=-3. //CLEAR DISPLAY //lcd_cmd(0x80). sbit en=P3^5.Embedded Systems & MC lab Output: To see the result of this program.h> sfr ldata=0XA0. void lcd_data(unsigned char value). display (). ES=1. void delay(unsigned int itime). CURSOR ON. RVCE 54 . return. } void delay(unsigned int itime) { unsigned int i. en=0. for(i=0. rs=1. while(busy==1) { en=0. delay(5). ECE.i<itime.j<50. lcd_data(res1). en=1. delay(5).i++) for(j=0. } void lcd_ready() { busy=1. ldata=value. en=1. rw=0. ldata=value. rs=0. rw=1.j. } Dept.Embedded Systems & MC lab lcd_cmd(0x01). } return.j++). rs=0. } void lcd_data(unsigned char value) { lcd_ready(). rw=0. return. en=1. delay(5). } void lcd_cmd(unsigned char value) { lcd_ready(). delay(5). delay(5). en=0. RVCE 55 . RJ-11 & DB-9 Connectors signal assignment 3. Synchronous & Asynchronous serial communication 4. Importance of receiving the data using serial interrupt 6. Use of LCD ready function in the above program 5. ECE. RS-232 data & Control signals 2.Embedded Systems & MC lab Activity: Write an C Program to Display 4 characters on 7 segment LED using MUX and Ports Observations to be recorded for Experiment 7 1. Functionality of MAX232 Dept. What is level converter 7. ECE. b) Write an 8051 C program to interface ADC in interrupt mode. ADC is governed by conversion time which is defined as time taken to convert the analog input to digital value. The 4 user programmable address lines (ADD A-ADD D) select among them any time.5 V and REF(-) =GND.5V(FFH).7 mv (2. If REF(+) =2.IN15). REF(+) & REF(-) set the reference voltage.Embedded Systems & MC lab Experiment 8 a) Write an 8051 C program to interface ADC in polled mode. In ADC 816. it is observed that there is an unavoidable uncertainty about the exact value of VIN for all digital output. This IC has 16-channels (IN0. If REF(+) =5 V and REF(-)=GND. Start(SOC) is for start of conversion. REF(+)=5 V and REF(-)=GND (can be changed also). If the full scale input voltage required to cause a digital output of all 1’s is VIFS. the step size is 19. The step size is also called as resolution some times. an ADC can detect. The A/D conversion is a quantizing process whereby an analog signal is converted into equivalent binary word. so that analog signals from 16 different sources can be given. The step size is defined as ratio of a change in value of input voltage needed to change a digital output by 1 LSB. of output bits Quantization Error The figure below shows transfer curve of 3 bit ADC. ADC0817 data acquisition component is a monolithic CMOS device with an 8-bit analog-to-digital converter. In the ADC target board of lab.Conversion time is 100µS. Its value is ± ½ LSB. the step size is 9. 16 or even 24 bits.5/256). 10. Resolution= VIFS / 2n Where. n=no. ADC 816 The ADC0816. This uncertainty is specified as quantization error. The input analog voltage can be varied between 0(00H) to 2. The 8-bit A/D converter uses successive approximation as the conversion technique. EOC(end of conversion) and OE(output enable) is to read the 8 bit digital value (Refer timing diagram). then resolution (step size) can be given as. 12. An ADC has n-bit resolution where n is 8. RVCE 56 . where step size is the smallest change in input analog voltage. We use ADD A-ADD D to select IN0 –IN15 and activate the ALE to latch in the address. The higher resolution ADC provides smaller step size. The input analog voltage can be varied between 0(00H) to 5V(FFH). From the figure.53 mv(5/256). Dept. RVCE 57 . Dept. A sample and hold circuit to acquire the input voltage (Vin).Embedded Systems & MC lab Successive Approximation Conversion Technique The successive approximation Analog to digital converter circuit typically consists of four chief sub circuits: 1. An analog voltage comparator that compares Vin to the output of the internal DAC (digital-to-analog converter) and outputs the result of the comparison to the successive approximation register (SAR). 4. An internal reference DAC that supplies the comparator with an analog voltage equivalent of the digital code output of the SAR for comparison with Vin. 2. A successive approximation register sub circuit designed to supply an approximate digital code of Vin to the internal DAC. ECE. 3. the comparator causes the SAR to clear MSB. ECE. To start a conversion cycle a three-bit digital register is first cleared. The search tree for an SAR search is illustrated below.Embedded Systems & MC lab Consider a three-bit conversion for simplicity. otherwise. Then the next bit is set to 1 and does the same test. and then loaded with the triplet 100(MSB set to1). continuing this binary search until every bit in the SAR has been tested. The register state provides the input to a DAC. if the analog voltage is lesser. This output is compared to the analog signal to be converted. Interfacing Diagram: Dept. RVCE 58 . The resulting code is the digital approximation of the sampled input voltage and is finally output by the DAC at the end of the conversion (EOC). and a decision is made whether the analog signal is greater than or less than the reference signal. the bit is left a 1. As the tree suggests. and that provides a reference output. sbit rd=P0^6. sbit soc=P0^5. } void convert(unsigned char y) { unsigned char q.'a'.' '. sbit ale=P0^4. while(temp[i]!='\0') { Dept.'u'.Embedded Systems & MC lab a) This program demonstrates polled mode of I/O support. sbit sel2=P0^2. send(y).':'.'i'. This program display converted digital value on serial window. TI=0. char i=0.'t'. while(!TI). the digital value is displayed continuously. sbit sel3=P0^3.'i'. if(y>0x09) y+=0x07. send(y). void delay(unsigned int i) { for(. } void send_string() { unsigned char temp[20]={'\n'.'D'. (as demonstrated in next program) #include<reg51.h> sbit sel0=P0^0.i--). y+=0x30.'l'.'e'. RVCE 59 .'l'. The above program can be made interrupt driven using any one external interrupt. } void send(unsigned char q) { SBUF=q. y+=0x30. return. y=q. ECE. Since the program run in polling mode.i>0. y=(y>>4)&0x0f.'v'. q=y.'a'. Mean while processor can be put in idle mode.'g'. if(y>0x09) y+=0x07.'\0'}. y=y&0x0F. sbit eoc=P2^0. sbit sel1=P0^1. TR1=1. while(eoc==0). RVCE 60 . delay(64000). sel1=0. sbit sel3=P0^3. unsigned char message[]="\nCPU is in IDLE mode. void delay(unsigned int i) Dept.Enable INT0 to continue". TMOD=0x20. //wait for EOC signal a=P1.'a'. convert(a). sbit sel2=P0^2. sbit eoc=P2^0. TL1=-3.'u'. rd=0. sbit ale=P0^4. } delay(10000). soc=0. TH1=-3.'a'. rd=1. i++. sel3=0. send_string(). P2=0xff.'i'. sbit sel1=P0^1. sel2=0.'i'.'e'. delay(10000).'v'. delay(1000).h> sbit sel0=P0^0. P1=0xff.'g'. sel0=0x0. } void main(void) { unsigned char a.'l'. } } b) Interrupt driven I/O support(reduces power consumption) #include<reg51. SCON=0x50.Embedded Systems & MC lab send(temp[i]). P0=0x00. sbit rd=P0^6.'l'.'D'.':'. ECE. while(1) { soc=1.' '. sbit soc=P0^5.'t'.'\0'}. unsigned char title[]={'\n'. while(temp[i]!='\0') { send(temp[i]). send(y). } void doNothing(void)interrupt 0 { //No code } void send_string(unsigned char temp[]) { char i=0.Embedded Systems & MC lab { for(. Dept. i++. sel1=0. } void send(unsigned char q) { SBUF=q. if(y>0x09) y+=0x07.i--).i>0. } } void main(void) { unsigned char a. TI=0. y+=0x30. q=y. while(!TI). RVCE 61 . P2=0xff. send(y). return. P0=0x00. if(y>0x09) y+=0x07. sel0=0x0. y=y&0x0F. ECE. } void convert(unsigned char y) { unsigned char q. y=(y>>4)&0x0f. y+=0x30. y=q. delay(1000). rd=1. send_string(message). Types of ADCs(Explain briefly) 5. send_string(title). convert(a). ECE. //After one conversion. TMOD=0x20. rd=0. soc=0. } } Observations to be recorded for Experiment 8 1. SCON=0x50. RVCE 62 . Resolution of ADC 2. while(eoc==0).Embedded Systems & MC lab sel2=0. //wait for EOC signal a=P1. P1=0xff. TL1=-3. TH1=-3. sel3=0. PCON=0x01. Quantization error of ADC 3. enable idle mode. Use of Sleep modes of MCU Dept. ADC control signals 4. //Enable external interrupt 0 while(1) { soc=1. TR1=1. IE=0x81. Methods to improve resolution of ADC 8.Embedded Systems & MC lab 6. Parallel Vs serial ADC 9. RVCE 63 . Idle mode of 8051 MCU 7. ADC selection criteria Dept. Use of serial window of Keil 10. ECE. although the voltage has fixed amplitude.Embedded Systems & MC lab EXPERIMENT 9 a) Generate PWM wave on pin P3. sbit eoc=P2^0. In this program. Speed varies linearly with analog voltage. Program: #include<reg51. By changing (modulating) the width of the pulse applied to DC motor we can increase or decrease the amount of power provided to the motor. Notice that. } void main(void) { unsigned char a. sbit sel1=P0^1. sel0=0x0. digital equivalent of analog input voltage is used to vary the duty cycle using timers.i>0. P0=0x00. Dept. RVCE 64 . sbit soc=P0^5. sbit sel3=P0^3. Control the duty cycle by analog input. it has variable duty cycle.i--). Interfacing Diagram: This program demonstrates the generation of pulse width modulated wave to control the speed of DC motor. sbit sel2=P0^2. sbit pwm=P3^1. P2=0xff. ECE. sbit ale=P0^4.1 to control speed of DC motor. thereby increasing or decreasing motor speed. return. sbit rd=P0^6.h> sbit sel0=P0^0. void delay(unsigned int i) { for(. TL1=a. ECE. while(1) { soc=1. pwm=1. TF1=0. rd=1. delay(1000). } } b) Write a program to generate sine wave using DAC. soc=0. TH1=0. TMOD=0x10. while(TF1==0). TF1=0.Embedded Systems & MC lab sel1=0. RVCE 65 . //wait for EOC signal a=P1. TR1=1. TH1=a. sel3=0. a=~a. pwm=0. sel2=0. while(TF1==0). Interfacing diagram: Dept. TL1=0. TL1=a. while(eoc==0). TR1=1. P1=0xff. Display the generated signal in logic analyzer window in simulation mode and in CRO in target mode. TH1=a. rd=0. D7 inputs of the DAC and reference current (Iref) and is given as.H> main() { Dept.6 because there are 256 steps in 10 volts.6 steps/ volt.4 139 d (8B H) 5. Therefore. ECE. To generate a sine wave. we assumed the full scale voltage of 10 V for DAC output.Embedded Systems & MC lab Circuit Diagram: In DAC 0800A digital inputs are converted to current (Iout) and by connecting a current to voltage converter output result in voltage.79 171 d (AB H) 7.0 to 1.0 for 0 to 360 degrees. 256 steps/ 10 V =25. To find the value sent to the DAC for various angles.6) 5 128 d (80 H) 5. The table below shows the angles. RVCE 66 .86 150 d (96 H) 6.5 192 d (C0 H) To generate the above table. the voltage magnitudes and integer values representing the voltage magnitude for each angle. Similar procedure is followed to calculate the integer values for all remaining angles. Iref is the current generated by 10 V power supply and 3 KΩ resistor. we first need table whose values represent the magnitude of the sine angles between 0 and 360 degrees.11 182 d (B6 H) 7. The values for the sine vary from -1. Program: #include <REG51xD2. Angle θ 0 5 10 15 20 25 30 Vout (Voltage Magnitude) Values sent to DAC 5 V+(5V x sin θ) (Vout x 25.29 161 d (A1 H) 6. Full scale output of the DAC is achieved when all the data inputs of the DAC are high. we simply multiply the Vout voltages by 25. the sine values. The total output current is function of the binary information D0. 0xf4.0x1d.0x11.0x04.0x2d.0x0a.0x5e.0xee.0xfe. RVCE 67 .0xc9.0xc0.0xd2.i++) P0=z[i].0xab.0xc9.0xfe.0x0a.0x36.0x25. Peace of code for generating square wave.0x8b.0x36. while(1) { for(i=0.0xe2. Observations to be recorded for Experiment 9 1.0xb6.0xd2.0x74.0x25.0x49.0x59.0 xa1.0xb6.0x1 1.0xf4.0x00.0x59.0x40. Use of dual DAC on Target board 3.0x80 }.0x40. What is reference voltage and current for DAC 5.0xda.0xe2.i<67.0xa1. Saw-tooth waveform 6.0x07.0x04. What is peak to peak voltage of sine wave generated 4.0xfb. What is the digital equivalent of 3V analog voltage for ADC0816 Dept.0xee.0x2d.0xab.0xff.0xc0. z[]={0x80.0x96.0x74.0x69.0x00.0x17.0x96.0xe8.0x07.0x80.0xf8.0x69.0xf8.0x8b.0x17. 0xfb.0xe8.0x5e.0x1d.Embedded Systems & MC lab unsigned char i. Use of I to V converter in DAC board //do it for ever 2.0 x49.0xda. ECE. } } Alternate exam question: Write a program to generate sine wave of given frequency. sbit rw=P3^6. void lcd_cmd(unsigned char value).H> sfr ldata=0XA0.393216.3276800. unsigned char countOverflow.'E'.'C'. void sendFreq(). void calFreq(). This program demonstrates use of counter to measure the frequency of TTL waveform connected to pin P3.'M'. The measured frequency in Hz is displayed on interfaced LCD in reverse order. sbit en=P3^5.'T'.4.131071. void lcd_data(unsigned char value).' '.'Y'. void delay(unsigned int itime). it is made to count for approximately for one second. void onCounterOverflow(void)interrupt 1 { Dept.Embedded Systems & MC lab EXPERIMENT 10 a) Write an 8051 C program to measure frequency of TTL waveform.'R'}.'R'. unsigned char string[]={'F'.262144. RVCE 68 . ECE. assembly instructions (inline assembly) are written in C program. To meet timing constraint.196608.After starting counter.458752}. unsigned long int freq. Interfacing Diagram: Program: #include <REG51.'E'.'N'. unsigned int count.'E'.65536. void sendString().'U'.'Q'. void lcd_ready(). sbit busy=P2^7. sbit rs=P3^7. unsigned long int frqOffset[]={0. A MOV TCON.A MOV TL0.#14 CLR A MOV TH1. } main() { IE=0x82. sendFreq().#50h Here:JNB TF1.#00h. RVCE 69 /* 10x5 dot matrix. lcd_data('H'). lcd_cmd(0x3C). 8 bit data line*/ /*clear */ . while(freq!=0) { temp=freq%10. countOverflow=0. ECE. sendString(). lcd_data('z'). freq/=10. } } void sendFreq() { unsigned char temp. #pragma asm MOV R0. countOverflow+=1.here CLR TR0 CLR TR1 #pragma endasm lcd_cmd(0x01).wait DJNZ R0. calFreq().A MOV TH0. while(1) { TH0=TL0=0. TMOD=0x15.#91 Wait:DEC R1 CJNE R1.Embedded Systems & MC lab TF0=0. Dept. 2 line dislay. lcd_cmd(0x0C0). count=0.Here CLR TF1 MOV R1.A MOV TL1. count=count<<8. } void sendString() { char i. lcd_data(temp). ldata=value. } void lcd_data(unsigned char value) { lcd_ready(). en=1. freq+=count. RVCE 70 . count=TH0. for(i=0. rs=1.Embedded Systems & MC lab temp=temp+(0x30). return. count+=TL0. en=0. rs=0. rw=1. rw=0.i<14. return. en=0. ECE. } } void lcd_cmd(unsigned char value) { lcd_ready(). en=1. } void lcd_ready() { busy=1. delay(5). Dept. ldata=value. } } void calFreq() { freq=frqOffset[countOverflow]. rw=0.i++) { lcd_data(string[i]). rs=0. delay(5). Situations demanding inline assembly 3. Keil optimization tools 4.i<itime. Inline Assembly 2. 6. RVCE 71 . delay(5). Observations to be recorded for Experiment 10 1. Compare IDLE mode with NOP instructions.j<50. for(i=0. } return. Select Generate Assembler SRC file & Assemble SRC file under options for source group1 and add C51S library file to project (path: source drive\Keil\C51\LIB). } void delay(unsigned int itime) { unsigned int i. en=1.Embedded Systems & MC lab while(busy==1) { en=0. ECE. Use of adding C51S library file to the program Dept.i++) for(j=0.j++). DAC 0800 5.j. } Note: Before compiling. 29. 18. 22. Mention the advantages of bit addressable locations with context to program memory. Mention variants of 8051 microcontroller. What is embedded system? Differentiate between hard & soft embedded systems with examples. 12. 23. 32. 6. 3. 26. Compare clock speeds of microprocessor & microcontroller. 72 Dept. 5. COLLEGE OF ENGINEERING. 19. 31. 34. 24. 21. 16. 2. 27. 7. 20. BANGALORE – 59. 9. Why the crystal oscillator used to drive MCUs? Why the machine cycle width of AT89C51ED2 is 12 clock cycles (probable reason)? Explain data memory organization of Intel’s 8051. ECE. 25.0592 MHz? Explain naming convention of AT89C51ED2. 4. 36. 11.V. 28. Differentiate between RISC & CISC. Mention different units of ports. Show interfacing of 4K x 8 ROM chip to 8051 microcontroller. Mention the advantages of bit addressable locations. 15. Write instruction to move the stack above 80h location. RVCE . What is the meaning of hardware support & software support for an instruction? Differentiate between microprocessor & microcontroller. machine cycle & clock cycle? Why AT89C51ED2 is operated at 11. Explain organization of the program memory in Intel’s 8051? What is the status of PSEN signal to access on chip ROM? What is the status of EA pin to access on chip data RAM? How microcontroller differentiates between on chip & off chip data memory access? Show the flag register status after execution of (23h-77h) operation. Explain interfacing of external data memory with timing diagram. 17. What is general purpose processor? Mention qualifying factors of microcontroller for an embedded system. What is hardwired control unit? What is micro programmed control unit? Mention different ways to implement processor register. 30. 13. What is real time embedded systems. Explain data memory organization of AT89C51ED2. 10. 39. Mention important constraints of embedded systems.Embedded Systems & MC lab DEPARTMENT OF ELECTRONICS AND COMMUNICATION R. 38. 8. What is instruction set compatibility? What is the driving capability of 8051 microcontroller ports? What is orthogonal instruction set? What is power on reset? How reset action of 8051 is initiated? What is minimum & maximum clock frequency of Intel’s 8051? Differentiate between instruction cycle. 35. 40. Why RISC processors are called load & store architectures? Differentiate between Von Neuman & Harvard architectures with examples. 33. Embedded systems & Microcontrollers Lab Viva –Voce Questions 1. 37. 14. Mention different ways to generate delay using 8051 microcontroller. What is read-modify-write instruction? 45. 42. Write instruction to configure a port as output. Differentiate between bidirectional & quasi bidirectional port with examples. 64. 73. What is the advantage of bit addressable registers? Explain with examples. What is the initial state for first counting sequence? 75. The ALE signal is generated twice/machine cycle. 48. What is advantage of fixed length instructions of RISC architectures? 56. then what is the TL0 counter frequency? 60. 47. The data memory of AT89C51ED2 is 256(00-FFh) bytes. Differentiate between QFP & DIP ICs. What is the maximum input frequency that can be accurately counted by an AT89C51ED2 controller counter at XTAL=16MHz ? 65. Explain port 0 pin structure. What is wake up time of 8051? Dept. 52. The timer 1 is programmed in mode 2. Differentiate between timer & counter with an example each.Embedded Systems & MC lab 41. 59. 51. Write a program to generate delay of 1sec using timer1 in any mode. Will the second byte is decoded? 46. How to test stack overflow? 43. If the input oscillator frequency is 11. Mention different ways to control timer/counter running. Mention different conditions which set overflow flag to 0. The value in TH0 register is F3h. How to control the running of timer 1 if timer 0 is set in mode 3? 69. 44. Explain auto reload counter mode of 8051. 63. What is watch dog timer? Mention some probable reasons causing hanging of system. 55. 66. 57. Differentiate between reading a latch & reading a pin with examples. Use directives. RVCE 73 . Write instructions to RAM locations & SFRs.0592 MHz. then what is the TH counter frequency in mode 0 & mode 1? 70. 50. Explain control logic of timer/counter. 72. Mention different ways to support I/O devices. If the input oscillator frequency is 11. Write an ISR of timer 1 to read a switch every 100ms. Explain mode 3 of timer 0. ECE. 68. Explain TMOD register. 62. Differentiate between directive & instruction. Write a program to read the status of switch & actuating LED continuously. What is the fan out of port pins of 8051microcontoller? 53. What is the application GATE bit of timer/counter? 71. Two bytes are fetched though an instruction is 1 byte which takes atleast 1MC to execute. 61. 67. 58. 74. Write a program to generate a square wave of 100 KHz &70% duty cycle using delay loop. The SFRs are also implemented in RAM locations 80-FFh. Why external pull up resistor is required for I/O operation of port 0? 54.0592 MHz. 49. To generate the baud timer 1 can be used or not? 96. 90. What is the baud rate of mode 0? 94. Explain the registers of 8051 used for serial communication. 78. What is multiprocessor communication mode? 97. Write a C program to transmit message “My best friend” serially. 83. 87. Write block diagram showing connection of controllers. Explain Null modem connection of RS-232. Dept. Explain power saving modes of 8051. ECE. RVCE 74 . Differentiate between edge triggered & level triggered interrupts. Explain 9 signals of RS-232. What is the minimum response time 8051 interrupt? 105. 106. Explain different actions performed by microcontroller upon arrival of interrupts. What is RS-232? Explain voltage levels RS-232. Explain how direction of data flow is controlled in this mode. half duplex & full duplex serial communication. 88. Explain data transmission formats of synchronous & asynchronous transmission. 98. Write an assembly program to generate square wave of 2 KHz square wave & 50% duty cycle using timer interrupts. Why? 104. 89. 99. Mention different priority levels among 8051 interrupts. What is framing error? Explain the support available in 8051 to detect framing error in serial mode 1. 77. 82. 102. Use sleep mode of 8051 to reduce power consumption. The mode 0 of serial interface is half duplex synchronous transmission. 92. Explain shift register mode of 8051. Design an 8051 based system to measure the pulse width. Explain interrupts of 8051. Explain simplex. Mention different methods to support serial communication with merits & demerits. It is learnt that the pulse to be measured is generated at random interval of times. 80. 109. 86. Write ALP for master for this communication. Mention advantages of high voltage levels of RS-232. 93. 100. Differentiate between synchronous & asynchronous serial communication with examples.Embedded Systems & MC lab 76. Why some time interrupts may have high response time? 108. 107. Differentiate between parallel & serial data transfer with examples. 91. It is learnt that master communicate with a salve every 10ms. What is block data transfer? 81. Explain how hardware single stepping is implemented using interrupts. 101. Select any one controller as a master and assign address to slaves. 79. What is UART? Explain how baud rate is generated in this mode. Design a scheme for connecting 3 8051 microcontrollers using full duplex serial communication with variable baud rate. Interrupt driven I/O support is better than polling. 84. What is master-slave configuration? 85. Use serial interrupt. What is baud rate? Compare with bps. How contention among multiples interrupts of same priorities is solved in 8051? 103. The timer 0 is configured in mode 3 & timer 1 in mode 1. 95. Why the statement Here: SJMP Here required in all programs? 121. 112. 113. Explain the following instruction. XCH A. 127.80h & MOV A. Write the instructions to do the following a) Complement the contents of RAM location 30H b) Mask upper four bits of A c) Set lower 4 bits of A 133. Which are the addressing modes supported by 8051.P0 131. Explain instruction formats of 8051. 129. What is the operation of following instructions? In_port equ p1 mov r1. Differentiate between MOVX & MOVC instructions.7 and LED to pin P2. Why all the programs are instructed to start at program memory locations above 30h? 119. What is EQU directive? Explain with an example. Write instruction to move content of any upper 128 bytes of RAM locations of AT89C51ED2.Embedded Systems & MC lab 110. Mybit mov r0. 115. A switch is connected to pin P1.obj & . What is listing file? 122.abs files? 123. Dept. RVCE 75 . Write a program to demonstrate the use of MOVC instruction. Write an instruction to push the accumulator on stack. 114. Differentiate between these two instructions with respect to assembling time. What is DB? Write program statements to store string “Microcontroller” at memory locations starting at 500h. What Intel hex file? Why these files are required? 125. Why END is the last statement of program? What is the machine code for the same? 120. Write a C program to send actuating signal to a bell for every 1 second. 118.P0 are the instructions doing same job. Explain internal RAM organization of AT89C51Ed2? How accessing of SFRs is differentiated compare to upper 128 bytes of RAM? 128. Show that set of XCH instructions executes faster than PUSH & POP when saving contents of A register. MOV A. 132. What is object to hex converter? 124.Explain with examples. Write program to copy the internal code byte at address 0300h to external RAM address 0300h.#Mybit 134.0 mov c.#In_port 135. 111. Write a program to get the status of the switch and send it to LED.In_port mov r0. 130. 117. What is the operation of following instructions? Mybit equ p1. Write a program to copy the value 55h into RAM locations 40h to 45h using a)Immediate addressing mode b)indirect addressing mode without a loop c) with a loop 126.0. ECE. Differentiate between . 116. Differentiate between call & Jump instructions. What is quantization error of ADC? Explain methods to reduce it. Explain some features of AT89C51ED2. Explain different units of Keil μVision. Explain DA instruction with an example. ECE. How the memory map to linker is given in the case of C programs? 165. 163. Differentiate between basic linker & extended linker of Keil. Dept. 164. 145. 146. Write a program to count number of 1’s in any number in register B and put the count in R5. 155. 156. Explain rotate instructions. What is In-System-Programming? What is boot loader or serial loader? 157. 150. 161. Which are the different code optimization techniques available in Keil IDE? 160. 149. 141. Explaining programming 8051 program memory with diagram. 151. Explain DB 9 & RJ 11 connector details. How DIV instruction indicates divide-by-zero error? 140. Explain SJMP. Why we must check serial interrupt of Keil Monitor-51 driver settings? 168. What is the difference between reset option given in Keil IDE & hardware reset of the MCU? 170. Compare MIPS. 159. Write a program to add 2 16-bit numbers FC45h and 02ECh. Write syntax instruction of unconditional jump instruction. 137. 144. Explain successive approximation method of analog to digital conversion. 167. What is step angle & pitch of stepper motor? 154. What are lock bits? Explain various options which could be obtained by programming lock bits.Embedded Systems & MC lab 136. Explain different stepper motors. 158. What is monitor program? 162. AJMP & LJMP instructions with examples. What is resolution of ADC? How resolution of ADC can be varied? 148. 142. 147. Write block diagram showing connection between Keil IDE running on host system & ESA MCB-51 target board. Write program to transfer accumulator contents serially to some peripheral connected to port pins. 166. What is Flash memory? Compare with EEPROM. What is resolution of DAC? 152. Why we must not check serial interrupt of Keil monitor-51 driver settings if the application is using serial interrupt? 169. Explain data types supported by 8051 C compiler of Keil. MFLOPS & MMACS. What is the digital equivalent of 3V analog voltage? Assume ADC is 0816 & reference voltage is 5V. 139. 143. RVCE 76 . Write C instruction to store string “Microcontroller” in code memory. 138. Compare IDLE mode with NOP instructions. What is code banking? Explain support provided by Keil IDE for code banking. 153.
Copyright © 2024 DOKUMEN.SITE Inc.