Upload
griffin1946
View
18
Download
2
Embed Size (px)
DESCRIPTION
experiment to display traffic lights
Citation preview
Experiment 1
BT-40
Deboleena Roy 09EC3203 Shruti Khatri 09EC1057
Experiment 1: Familiarization with 8051 kit
Objective:Study about the kit components and its interface with the PC. Write the following programs in the assembly language of 8051.
1. Find the second largest of an array of 100 numbers stored in external memory from location 9000H onwards. The number be stored at location 9500H. Show the contents of memory locations before and after running the program to establish correctness of it
2. Compute the LCM of two numbers. Assume the numbers to be stored at location 9000H and 9001H. Store the result at 9002H.
3. Check whether a NULL-terminated string stored from location 9000H is a palindrome or not. If the string is a palindrome, store 1 at location 9500H, else clear the location.
Apparatus and Software1. ESA51E 8051 Trainer Board2. Compiler – Kiel µVision43. Driver – Win51E
Design (Hardware)ESA51E is trainer kit that is interfaced with PC through RS-232-C serial port connection. It is provided external power supply of +5V. The compiler converts the assembly code into a .hex file which is then loaded on the code space of 8051 using driver Win51E
Design (Software)
Part 1: Obtain second largest number from an array of 100 numbers
Design1. For the first number, read it and store it in R1.2. Now, input the next number in R3.3. Copy content of R1 at some random location, say 60H.4. If R3 = value at 60H, R2= R3.5. If R3 > value at 60H, R1 = R3; R2 = value at 60h.6. If R3 < value at 60H, and R3 > R2; R2 = R3.7. Loop8. End
Experiment 1
BT-40
Deboleena Roy 09EC3203 Shruti Khatri 09EC1057
Software Code
ORG 8100HMOV DPTR,#9000HMOV R0,#99
MOVX A,@DPTRMOV R1,A
INC DPTRMOVX A,@DPTR
MOV 60H,R1CJNE A,60H,NEXTMOV R2,ASJMP LOOP
NEXT: JNC SHIFTMOV R2,ASJMP LOOP
SHIFT: MOV R3,AMOV A,R1
MOV R2,AMOV A,R3
MOV R1,A
LOOP: DJNZ R0,MAINSJMP FINISH
MAIN: INC DPTRMOVX A,@DPTRMOV 60H,R1CJNE A,60H,NEXT2MOV R2,ASJMP LOOP
NEXT2: JNC SHIFTMOV 60H,R2CJNE A,60H,NEXT3SJMP LOOP
NEXT3: JNC MOVR2ASJMP LOOP
MOVR2A: MOV R2,ASJMP LOOP
Experiment 1
BT-40
Deboleena Roy 09EC3203 Shruti Khatri 09EC1057
FINISH: MOV DPTR,#9500HMOV A,R2MOVX @DPTR,A
HERE: SJMP HEREEND
Part 2: Find the LCM of 2 given numbers
Design1. Input the numbers in R1 and R2.2. If R1 < R2, interchange the values.3. Store A = R1, B = R2.4. Perform the following until B = 0 is satisfied.
a. Store B at some location say 60hb. Divide A by B.c. Store B’s value in A, and store the remainder in B.d. Loop
5. GCD = value at 60H.
6. Obtain LCM by using the formula, LCM=R1×R2GCD
.
7. END
Software Code
ORG 8100H
MOV DPTR,#9000H MOVX A,@DPTRMOV R1,A INC DPTRMOVX A,@DPTRMOV R2,A MOV 60H,R1CJNE A,60H, NEXT1 SJMP LEAVE
NEXT1: JNC SWITCH MOV A,R1MOV B,R2 SJMP LOOP
SWITCH: MOV A,R1
Experiment 1
BT-40
Deboleena Roy 09EC3203 Shruti Khatri 09EC1057
MOV R3,A MOV A,R2MOV R1,AMOV A,R3MOV R2,A MOV A,R1MOV B,R2
LOOP: MOV R4,BDIV ABMOV A,BJZ GCDOUTMOV A,R4 SJMP LOOP
GCDOUT: MOV A,R1 MOV B,R4DIV AB MOV B,R2MUL AB
LEAVE: INC DPTRMOVX @DPTR,AINC DPTRMOV A,BMOVX @DPTR,A
HERE: SJMP HEREEND
Part 3: Find out whether a given string is a palindrome
Design1. Obtain the string length by reading till NULL is obtained, and running a counter alongside.2. Start reading character by character.3. Store 1st character at location 70H and corresponding mirror image in A. Compare and if
same, continue to next character. If not, exit loop. Go to step 54. If the entire string is scanned (R1=0), then exit loop. Move #1 to 9500H.5. END
Experiment 1
BT-40
Deboleena Roy 09EC3203 Shruti Khatri 09EC1057
Software Code
ORG 8100HMOV R2,#0HMOV DPTR,#8FFFH ;1 less than starting value
STRING:INC R2INC DPTRMOVX A,@DPTRCJNE A,#0H,STRINGDEC DPLMOV R0,DPL
MOV A,R2MOV B,#2HDIV ABMOV R2,A
MOV DPTR,#9000H
LOOP:MOVX A,@DPTRMOV R4,DPLMOV 70H,AMOV DPL,R0MOVX A,@DPTRCJNE A,70H,LEAVEDEC DPLMOV R0,DPLMOV DPL,R4INC DPTRDJNZ R2,LOOP
MOV DPTR,#9500HMOV A,#01HMOVX @DPTR,ALJMP NEXT
LEAVE: MOV DPTR,#9500HMOV A,#0HMOVX @DPTR,A
NEXT: SJMP NEXTEND
Experiment 1
BT-40
Deboleena Roy 09EC3203 Shruti Khatri 09EC1057
ObservationTo work with user given data, and to verify the functionality of the code, we can use the software package to view and edit the registers of the microcontroller. Next, by running the program over the inserted values we can validate the code.
Part 1:
User InputAddress Value9000H 00H9001H 50H9002H 60H9003H 70H9004H 00H … . … . … .9063H 00H
OutputAddress Value9500H 60H
Part 2:
User InputAddress Value9000H 06H (6)9001H 0AH (10)
OutputAddress Value9002H 1EH (30)
Experiment 1
BT-40
Deboleena Roy 09EC3203 Shruti Khatri 09EC1057
Part 3:
Case 1
User InputAddress Value9000H 03H9001H 02H9002H 01H9003H 02H9004H 03H9005H 00H
OutputAddress Value9500H 01H (it is a palindrome)
Case 2
User InputAddress Value9000H 03H9001H 02H9002H 00H9003H 02H9004H 03H9005H 00H
OutputAddress Value9500H 00H (it is not palindrome)
The program reads the string up to 9001H as it encounters the null character at 9002H. So it sees the string as ‘03’ ‘02’ which is not a palindrome
Experiment 1
BT-40
Deboleena Roy 09EC3203 Shruti Khatri 09EC1057
Discussion
Deboleena Roy 09EC32031. The program is written in assembly language. Usual conditional constructs like if … else, for,
do … while are replaced by intuitive register transfers and jumps.2. Mathematical operations, transfer of values with external RAM (MOVX), comparisons are
restricted to Register Accumulator (A)3. Each program is executed by first setting the program counter to start of the location of the
code in code space. In our case it is 8100H4. Each program terminates with an infinite loop of the type
NEXT: JUMP NEXTso that the PC remains stuck there and no further instructions in other parts of the code space gets executed.
5. CJNE function was abundantly used in all 3 parts. The syntax is CJNE value#1, value#2. Value#1 must always be A (accumulator). Carry bit is set to 1 if A < value#2 else it is set to zero.
Shruti Khatri 09EC10571. In this experiment, we wrote and burned basic programs on the 8051 micro-controller.2. Syntax used in assembly language is not very intuitive. Most operations don't work on
registers and the accumulator has to be used during the operation and the result needs to be copied in the register. Same is the case with operations like compare which doesn't work on registers.
3. When writing the program we should always make sure that the program ends with an infinite loop otherwise on running the code some instructions that are already present at memory locations that we haven't re-written might be executed. We should press break to stop the execution of the infinite loop and see the results.
4. When performing compare operation the value of carry varies depending on whether greater than or less than is true and this can be used in the program.
5. The program counter should be set in the WIN51E environment at the location from which we want the program to execute.