Question

In: Electrical Engineering

How would I code the following in assembly language? Use the Keil programming environment to code...

How would I code the following in assembly language?

Use the Keil programming environment to code the C8051F330 SiLabs 8051 micro controller. All the documentation is available on efundi. The program shall be done in assembler and you shall use the DJNZ instruction to generate a delay time to flash the LED. The LED shall flash in the following sequence:

1. On for 50mS,

2. Off for 400mS,

3. On for 50mS,

4. Off for 1.5S,

5. Repeat the sequence from step 1.

Solutions

Expert Solution

Answer :- Assuming LED is connected at port1 pin zero. Write 10111100 = 0xBC at SFR address 0xE3 to set 72 kHz with divider 8 i.e. 9 kHz frequency.

T = 1/9 ms. For 50 ms delay, count = 50*9 = 450
For 400 ms delay, count = 400*9 = 3600 and for 1.2 s, count = 1200*9 = 10800.
In 8051 MC we have 8-bit GPR, so max count can be 256 only i.e. 0 to 255. The code can be written as-

-------------------------------------------------------------------------------------

P1 EQU 90H

OSCLCN EQU E3H

MOV OSCLCN, #BCH ;set controller frequency to work at 9 kHz
LoopInf : infinite loop starts here
MOV P1, #01H ;make LED on
CALL Delay1 ;keep On for 50 ms
MOV P1, #00H ;make LEd off
CALL Delay2 ;keep LED off for 400 ms
MOV P1, #01H ;make LED on
CALL Delay3 ;Keep LED on for 1.2 s
SJMP LoopInf ;go to label LoopInf to repeat

Delay1: ;delay loop for 50 ms
MOV R1, #10 ;register R1 = 10
Loop1:
MOV R2, #45 ;register R2 = 45
Loop2:
DJNZ R2, Loop2 ;decrease R2 and goto label Loop2 if not zero
DJNZ R1, Loop1 ;decrease R1 and goto label Loop1 if not zero
RET

Delay2: ;delay loop for 400 ms
MOV R1, #36 ;register R1 = 36
Loop3:
MOV R2, #100 ;register R2 = 100
Loop4:
DJNZ R2, Loop4 ;decrease R2 and goto label Loop4 if not zero
DJNZ R1, Loop3 ;decrease R1 and goto label Loop3 if not zero
RET

Delay3: ;delay loop for 1.2 s
MOV R1, #100 ;register R1 = 100
Loop5:
MOV R2, #108 ;register R2 = 108
Loop6:
DJNZ R2, Loop6 ;decrease R2 and goto label Loop6 if not zero
DJNZ R1, Loop5 ;decrease R1 and goto label Loop5 if not zero
RET

Note:- Dear student, while creating the project in keil, please select the above mentioned MCU. Also be sure that port and register address defind in first two lines are defined for the MCU. For this you can see the datasheet of C8051F330.


Related Solutions

Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
Translate the following C code into M4K assembly language. You do not have to use the...
Translate the following C code into M4K assembly language. You do not have to use the frame pointer, just use $sp if you need to use the stack. You do not have to show the stack initialization nor stack cleanup. If you need a specific value for an address, just make an assumption. int A; main() { int B = 5; B = A+B }; // main //Disassembly starts here !main() { //stack and frame pointer init // you do...
I need a program(code) in any programming language that performs the following operations: union, concatenation and...
I need a program(code) in any programming language that performs the following operations: union, concatenation and conversion DFA-NDFA.
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++)...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++) sum = sum + I; printf(“sum=%d”, sum); 2) int i, v[10]; int min, k; for(i=0; i < 10; i++) scanf(“%d”, &v[i]); min = v[0] for(i=1; I < 10; i++) if(min > v[i]){ min = v[i] k = I; } printf(“%d=>%d”, k, min);
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Use a loop with indirect or indexed addressing to reverse the elements of an integer array in place. Do not copy the elements to any other array. Use the SIZEOF, TYPE, and LENGTHOF operators to make the program as flexible as possible if the array size and type should be changed in the future. .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your...
The programming language that is being used here is JAVA, below I have my code that...
The programming language that is being used here is JAVA, below I have my code that is supposed to fulfill the TO-DO's of each segment. This code in particular has not passed 3 specific tests. Below the code, the tests that failed will be written in bold with what was expected and what was outputted. Please correct the mistakes that I seem to be making if you can. Thank you kindly. OverView: For this project, you will develop a game...
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
Use R programming language to answer and please so show the code as well. A paper...
Use R programming language to answer and please so show the code as well. A paper manufacturer studied the effect of three vat pressures on the strength of one of its products. Three batches of cellulose were selected at random from the inventory. The company made two production runs for each pressure setting from each batch. As a result, each batch produced a total of six production runs. The data follow. Perform the appropriate analysis. Table is below Batch Pressure...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
The language is Assembly Language. Thank you! Assignment 3: Run the following code. Record what each...
The language is Assembly Language. Thank you! Assignment 3: Run the following code. Record what each of the flag changes are for each command. INCLUDE Irvine32.inc .data .code main PROC mov al,255 add al,1 call DumpRegs sub al,1 call DumpRegs sub al,1 call DumpRegs exit main ENDP END main
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT