Answer To Microcontroller QP
Answer To Microcontroller QP
In order to make Port 0 as input, the port must be programmed by writing 1 to all the bits.
Example 2.2.2:
Configure port 0 as input port by writing 1s to it and then receive data from the port 0 and
send to P1.
Solution:
MOV A, #FFH ; A = FFH
MOV P0, A ; make port 0 as input
START:
MOV A, P0 ; get data from port 0
MOV P1, A ; send register A to port 1
SJMP START ; repeat again from START
ORG 0000H
MOV R1, #0A ;R1 stores the count of total 6
bit numbers
MOV B, #0A ;B is used as divisor for average
MOV R0, #50H ;R0 acts as pointer to the data
MOV A, #00H ;Clear A
BACK : ADD A, @R0 ; Add the data to A
register
INC R0 ; Increment the pointer
DJNZ R1,BACK ; repeat addition until R1=0
DIV AB ; divide sum to get average ;quotient is
in A and remainder in B
MOV R6,A ;Ignore remainder and store
average result in 60h
HERE: SJMP HERE ; wait
END
Write a program to generate square wave of 5o% duty cycle on bit-5 of port-1
Assuming XTAL = 11.0592 MHz, write a program to generate a square wave of 50
Hz frequency on pin P2.3.
Solution:
Look at the following steps.
1. T — 1 / 50 Hz = 20 ms, the period of the square wave.
2. 1/2 of it for the high and low portions of the pulse = 10 ms
1. 10 ms / 1.085 us = 9216 and 65536 – 9216 = 56320 in decimal,
and in hex it is
DCOOH.
3. TL = 00 and TH = DC (hex)