Академический Документы
Профессиональный Документы
Культура Документы
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Figure 41
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
PORT 0
Pin 32-39 Each pin must be connected to a 10K resistor
Due to the nature of open-drain for MOS chips
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Port 0 as Input
;Get a byte from P0 and send it to P1 MOV A,#0FFH MOV P0,A BACK: MOV A,P0 MOV P1,A SJMP BACK
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay 2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Port 1
Pin 1 to 8 Do not need pull-up resistros Set as input upon RESET
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
MOV MOV MOV MOV ACALL MOV MOV ACALL MOV MOV
A,#0FFH P1,A A,P1 R7,A DELAY A,P1 R6,A DELAY A,P1 R5,A
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Port 2
Pin 21-28 Set as input upon RESET Also as A8-A15 : addresses for external memory
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Port 3
Pin 10 to 17
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 4-1
Write a test program for a 8051 chip to toggle all the bits of P0, P1, and P2 every of a second. Assume a crystal frequency of 11.0592 MHz
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Solution ( part of )
ORG 0 BACK: MOV A,#55H MOV P0,A MOV P1,A MOV P2,A CALL QSDELAY
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
MOV A,#0AAH MOV P0,A MOV P1,A MOV P2,A CALL QSDELAY SJMP BACK
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Table 42
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
One-bit toggle
BACK: CPL P1.2 CALL DELAY SJMP BACK
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Table 43
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 4-2
Create a square wave of 50% duty cycle on bit 0 of port 1 Create a square wave of 66% duty cycle on bit 3 of port 1 The 66% duty cycle means :
H : 66%, L : 33%
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Table 44
Single-Bit Instructions
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Checking An Input-Bit
JNB ( jump if bit=0 ) and JB ( jump if bit=1 )
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 4-3
Write a program to
(a) keep monitoring the p1.2 bit until it becomes high (b) when P1.2 becomes high, write value 45H to port 0 (c) send high-to-low (H-to-L) pule to P2.3
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Solution
SETB MOV JNB MOV SETB CLR P1.2 A,#45H P1.2,AGAIN P0,A P2.3 P2.3
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
AGAIN:
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 4-4
Assume that 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.
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Solution
HERE: JNB SETB CLR SJMP P2.3, HERE P1.5 P1.5 HERE
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Ex. 4-5
A switch is connected to pin P1.7. Write a program to check the status of SW and perform the following
(a) If SW=0, send letter N to P2. (b) If SW=1, send letter Y to P2
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Solution
AGAIN:
OVER:
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
OVER:
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Ex. 4-7
A switch is connected to pin P1.0 and an LED to pin P2.7. Write a program to get the status of the switch and send it to the LED. Solution : SETB P1.0 AGAIN: MOV C,P1.0 MOV P2.7,C SJMP AGAIN
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay 2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
This arises when we want to read the external pin AFTER we configure the port as input
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay 2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
ANL
P1,A
Get the internal latch of the port P1 and bring it into the CPU This data is ANDed with data in A The result is rewritten back to the port latch The port pin data is changed and now has the same value as the port latch
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
Table 46
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458
Read-Modify-Write
MOV AGAIN: XLR ACALL SJMP P1,#55H P1,#0FFH DELAY AGAIN
The 8051 Microcontroller and Embedded Systems, 2e By Muhammad Ali Mazidi, Janice Gillispie Mazidi, and Rolin D. McKinlay
2006 Pearson Education, Inc. Pearson Prentice Hall Upper Saddle River, NJ 07458