Sie sind auf Seite 1von 7

Single-Bit Instructions and Programs

ECE473/573 Microprocessor System Design, Dr. Shiue

Example
Pentium I/O port byte addressable bit addressable
Change one bit, you must access the entire 8 bits.

8051 microcontroller Single-bit instructions

128B RAM, registers, I/O ports, etc. in SFR. SETB bit CLR bit CPL bit (1s complement) JB bit, target (Jump if bit =1) JNB bit, target (Jump if bit=0) JBC bit, target (Jump if bit =1, then clear)

ECE473/573 Microprocessor System Design, Dr. Shiue

Example
Q1: Create a square wave of 50% duty cycle on bit 0 of port 1.
x

P1.0 y x=y 50% duty cycle

ECE473/573 Microprocessor System Design, Dr. Shiue

JNB and JB
JNB and JB
Used to monitor a bit and make a decision depending on whether it is 0 or 1.

Q2: Assume bit P2.3 is an input and represents the condition of an oven. If it goes high, it means that the oven is hot. Monitor the bit continuously, whenever it goes high, send a high-to-low pulse to port P1.5 to turn on a buzzer.

ECE473/573 Microprocessor System Design, Dr. Shiue

Bit Addressable
Bit Addressable
Registers B, PSW, IP, IE, ACC, SCON, TCON, and etc

Q3: Write a program to see if the ACC contains an even number. If so, divide it by 2. If not, make it even and then divide by 2. Q4: Write a program to see if bits 0 and 5 of B are 1. If they are not, make them so and save it in R0. Q5: Write a program to save the ACC in R7 of Bank 2. Q6: There are no such instructions for OV. How would you write code to check OV? Q7: The status of bits P1.2 and P1.3 of port P1 must be saved before they are changed. Write a program to save the status of P1.2 in bit location 06 and the status of P1.3 in bit location 07.
5

ECE473/573 Microprocessor System Design, Dr. Shiue

Single-bit Operations with CY


SETB C CY=1 CLR C CY=0 CPL C complement of CY MOV bit, C MOV C, bit JNC target Jump if CY=0 JC target Jump if CY=1 ANL C, bit AND CY with bit and save it on CY AND C, /bit AND CY with inverted bit and save it on CY ORL C, bit OR CY with bit and save it on CY.
6

ECE473/573 Microprocessor System Design, Dr. Shiue

Single-bit Operations with CY


Q8: Write a program to save the status of bits P1.2 and P1.3 on RAM bit locations 6 and 7, respectively. Q9: Assume that RAM bit location 12H holds the status of whether there has been a phone call or not. If it is high, it means there has been a new call since it was checked the last time. Write a program to display New Message on an LCD if bit RAM 12H is high. If it is low, the LCD should say No New Message. Q10: Assume that the bit P2.2 is used to control the outdoor light and bit P2.5 to control the light inside a building. Show how to turn on the outside light and turn off the inside one.

ECE473/573 Microprocessor System Design, Dr. Shiue

Das könnte Ihnen auch gefallen