VJ MP2m
VJ MP2m
ORG 0000H
MOV A, #05H ; Load the number (e.g., 5) into accumulator
MOV B, A ; Copy the number to register B
MUL AB ; A = A * B (Square)
MOV R0, A ; Store square in R0
MOV A, B ; Reload the original number
MOV B, R0 ; Move square to B
MUL AB ; A = A * B (Cube)
MOV R1, A ; Store cube in R1
END
START:
MOV P1, #0FFH ; Set Port 1 high (5V)
ACALL DELAY ; Call delay subroutine
MOV P1, #00H ; Set Port 1 low (0V)
ACALL DELAY ; Call delay subroutine
SJMP START ; Repeat indefinitely
DELAY:
MOV R0, #0FFH ; Delay loop
DJNZ R0, $
RET
END
; Initialize LCD
MOV A, #38H ; 2 lines, 5x7 matrix, 8-bit mode
ACALL COMMAND ; Send command to LCD
MOV A, #0CH ; Display ON, cursor OFF
ACALL COMMAND
MOV A, #01H ; Clear display
ACALL COMMAND
END
9. Time Duration for One State and One Machine Cycle with 6
MHz Crystal
One State Duration:
Time=1 / 6MHz=0.1667 μs
One Machine Cycle:
The 8051 takes 12 states for one machine cycle.
Time=12×0.1667 μs=2
START:
MOV A, #00H ; Start with 0
MOV P1, A ; Output to DAC (connected to Port 1)
ACALL DELAY ; Call delay subroutine
ADD A, #20H ; Increment by 20H (next step)
CJNE A, #0FFH, START ; Repeat until A reaches FFH
SJMP START ; Repeat indefinitely
DELAY:
MOV R2, #0FFH ; Delay loop
DJNZ R2, $
RET
END
11. C18 Program to Set Bit RB0 and Send Inverted to RC7
#include <p18f4550.h>
void main() {
TRISBbits.TRISB0 = 0; // Set RB0 as output
TRISCbits.TRISC7 = 0; // Set RC7 as output