PowerElectronics Class6
PowerElectronics Class6
PowerElectronics Class6
Classifications
• Bit Addressable Instructions
• Data Movement Instructions
• Arithmetic Instructions
• Logic and Shift Instructions
• Control Instructions
• Subroutine Instructions
• Stack Instructions
128 Bit addressable RAM memory
Locations
Ex: to set bit 67H
Solution: (in Microcontroller)
SETB 67H
MOV A, @2CH
ORL A, #10000000B
MOV @2CH, A
21 special function registers
Boolean Variable Instructions
Instructions Functions Example Instructions
SETB bit Set the bit (bit=1) SETB 42H
CLR bit Clear the bit (bit=0) CLR 67H
CPL bit Complement the bit (bit= NOT bit) CPL P0.0
JB bit, target Jump to target if bit=1 JB PSW.2, TARGET
JNB bit, target Jump to target if bit=0 JNB P2.3, TARGET
JBC bit, target Jump to target if bit =1, clear bit JBC P2.3, TARGET
ORG 0400H
DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH
END
Loop and JUMP instructions (Control
Transfer)
• Repeating a sequence of instructions a certain
number of times is called a loop.
• Example: DJNZ reg, label ; reg is decremented, if it is not zero, it
jumps to the target address referred to by the label
Note: Generally machine cycles for each instruction of a specific microcontroller can
be found in data sheet.
Answer: 1630.755 microseconds
I/O Ports
• 4 8-bit ports P0, P1, P2, and P3
• Upon RESET all ports are configured as INPUT
• PORT 0 requires external pull-up resistors
• PORT 1,2, and 3 have inbuilt internal pull up
resisters
• By programming, each pin of the port can be
configured as either input or output
Structure of P1,P2, and P3
Pin Configuration
• By default all pins are configured as input
• When the first ‘0’ is written to a port, it becomes
an output
• To configure any port as input we have to write
‘1’ to it.
MOV A, #0FFH
MOV P1, A ; make P0 as input
BACK: MOV A, P0 ; get data from P0
MOV P1, A ; send it to P1
SJMP BACK
PORT Operation
• One has to be careful in connecting external
Vcc to the input pin
• Reading the Pin status
• Reading the Latch
• Port 0 does not have internal pull-up resister
• One should not leave a pin to float
Instructions to read the status of Input
Port
Mnemonics Examples
MOV A, PX MOV A, P1
JNB PX.Y, Target JNB P1.2, Target
JB PX.Y JB P1.3, Target
MOV C, PX.Y MOV C, P1.4
CJNE A, PX, Target CJNE A, P2, Target
Read-Modify-Write Instructions
Mnemonics Example
ANL ANL P1, A
ORL ORL P1, A
XRL XRL P1, A
JBC PX.Y, Target JBC P1.3, Target
CPL CPL P1.2
INC INR P1
DEC DEC P1
DJNZ DJNZ P1, Target
MOV PX.Y, C MOV P1.2, C
CLR PX.Y CLR P1.3
SETB PX.Y SETB P1.4
• Program: Create a square wave of 50% duty
cycle on bit 0 of port 1
HERE: SETB P1.0
LCALL DELAY
CLR P1.0
LCALL DELAY
SJMP HERE
• Another way
HERE: CPL P1.0
LCALL DELAY
SJMP HERE
• Hardware Schematic Diagram
• Write a program to perform the following;
(a) keep monitoring pin P0.1 until it becomes high
(b) when P0.1 becomes high, read in the data from P1
(c) send a low-to-high pulse on P0.2 to indicate that the data has
been read
Solution:
SETB P0.1
MOV P1, #0FFH
AGAIN: JNB P0.1, AGAIN
MOV A, P1
CLR P0.2
SETB P0.2