Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help building this program using assembly. I am stuck on this one to

ID: 3349014 • Letter: I

Question

I need some help building this program using assembly. I am stuck on this one to get it to work correctly.

Flash all LEDs in one Hz frequency when running your program in the EVB mode (also called debug mode). In EVB mode, the clock frequency for instructions is 24MHz. You must write a subroutine that consumes exactly one second of CPU time. To achieve the flashing effect, in your main program, you need to turn on all the LEDs, then, call this subroutine. Turn off all LEDs, then, call this subroutine. Your program must flash LEDs continuously in one Hz frequency until a Reset.

Explanation / Answer

In order to generate delay between LED on/off, a delay subroutine is called that generates delay of 24,000,000 times 1 cycle of CPU clock which makes 1 second delay. This will generate LED flash program with 1Hz frequency.

Connect LED to Port 2.0 of micro controller and run below assembly program.

ORG 0000H

LOOP:

                CLR P2.0

                CALL DELAY

                SETB P2.0

                CALL DELAY

                JMP LOOP

DELAY:

MOV R4,#10

L2_DELAY:

MOV R5,#100

L3_DELAY:

                MOV R6,#100

L4_DELAY

MOV R7,#240

L5_DELAY:

                DJNZ R7,L5_DELAY

                DJNZ R6,L4_DELAY

                DJNZ R5,L3_DELAY

                DJNZ R4,L2_DELAY

As CPU is having 24 MHz frequency clock, in order to generate 1 sec delay between LED ON/OFF we need to make the CPU busy doing other tasks for 1 second.

So we need to create a delay subroutine and call the subroutine after switching on LED and switching OFF the LED.

Total time took by Delay subrouting in the above program is 240*100*100*10 times of one time cycle of CPU. Total delay will become 1 sec.