51 MCU Exercises

Publisher:幸福时刻Latest update time:2015-10-12 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Fill in the blanks

1.1. In the MCS-51 system, when the PSEN signal is valid, it means that the CPU wants to read information from the (external program memory) memory.

1.2. When RS1RS0=10 in PSW, the address of R2 is (12H); when RS1RS0=11, the address of R2 is (1AH).

1.3. One machine cycle = 12 (oscillation cycles) = 6 (state cycles/clock cycles).

1.4. In the MCS-51 microcontroller, if a 9MHz crystal oscillator is used, one machine cycle is (1.5)us.

1.5. If (DPTR) = 2000H, (A) = 50H, after executing the instruction "MOVC A, @A + DPTR", the content of the program memory (2050H) unit is sent to A.

1.6. Assuming that the accumulator (A) = 50H, after executing the instruction "MOVC A, @A+PC" at the unit 2000H of the program memory, the content of the unit (2051H) of the program memory is sent to A.

1.7. To access the internal RAM, use the MOV instruction, to access the external RAM, use the (MOVX) instruction, to access the internal ROM, use the (MOVC) instruction, to access the external ROM, use the (MOVC) instruction.

1.8. The instruction "ORL A, #0F0H" sets the high 4 bits of A to 1, while the low 4 bits remain unchanged.

1.9. After executing the "ANL A, #0FH" instruction, the upper 4 bits of accumulator A = (0000B).

1.10. If the instruction opcode address of "SJMP rel" is 1000H, rel=50H, then its transfer target address is (1052H).

1.11. Assume that (A) = 54. After executing the instruction "ADD A, #65", the content of accumulator A is (01110111B) and the content of CY is (0).

1.12. The MCS-51 single-chip microcomputer system with a main frequency of 12MHz uses T0 mode 1 for timing of 1ms, so the time constant should be (64536).

1.13. Assume that (A) = 86H.   After executing the instruction "ADD A, #8DH", the content of accumulator A is (03H), the content of CY is (1), the content of AC is (1), and the content of OV is (1).

 

2. Multiple choice questions

2.1. When MCS-51 is reset, the correct statement is (A).
  A. PC = 0000H;   B. SP = 00H;   C. SBUF = 00H;   D. P0 = 00H;
2.2. When PSW = 01H, the current working register is (B).
  A. Group 0;        B. Group 1;      C. Group 2;        D. Group 3;

2.3. The ALE pin of the single-chip microcomputer 8031 ​​is (C).
  A. Output high level;                C. Output rectangular pulse with a frequency of 1/6 of fosc;
  B. Output low level;                D. Output rectangular pulse with a frequency of 1/2 of fosc;

2.4. If PSW.4=0, PSW.3=1, to push the contents of register R0 onto the stack, use the (D) instruction.
  A. PUSH R0;     B. PUSH @R0;  C. PUSH 00H;     D. PUSH 08H;

 

3. Short answer questions

3.1. Briefly describe the control signals used to read external ROM and read and write external RAM.

Answer: ①ALE: When the CPU accesses external program or data memory, this signal serves as the control signal to latch the lower 8-bit address.

    ②PSEN: External program memory selection control signal, low level is valid.
    ③EA: When this pin is low level, only the external program memory is selected; when this pin is high level, the internal program memory is selected first, and then the external program memory is selected.
    ④RD: External RAM read control signal.
    ⑤WR: External RAM write control signal.

3.2. Briefly describe the four modes of 89C51 serial communication and their characteristics.
Answer: Mode 0: Synchronous shift register input/output mode, often used to expand I/O ports. The baud rate is fixed to 1/12 of the oscillation frequency and is not affected by the SMOD bit in the PCON register.
    Mode 1: Used for serial transmission or reception, it is a 10-bit universal asynchronous interface. TXD and RXD are used to send and receive data respectively. The format of sending and receiving a frame of data is 1 start bit, 8 data bits (low bit first), 1 stop bit, a total of 10 bits. The baud rate is determined by the overflow rate of timer T1 and the SMOD value.
    Mode 2: Used for serial transmission or reception, it is an 11-bit universal asynchronous interface. TXD and RXD are used to send and receive data respectively. The format of sending and receiving a frame of data is 1 start bit, 8 data bits (low bit first), 1 programmable 9th data bit and 1 stop bit, a total of 11 bits. The baud rate depends on the value of the SMOD bit in PCON: when SMOD = 0, the baud rate is 1/64; when SMOD = 1, the baud rate is 1/32.
    Mode 3: used for serial transmission or reception, it is an 11-bit universal asynchronous interface. TXD and RXD are used to send and receive data respectively. The frame format is the same as mode 2, and the baud rate is the same as mode 1.

 

4. Programming and Application

4.1、Programming to implement c=a*a+b*b. Assume that a and b are both less than 10, a is stored in unit 31H, b is stored in unit 32H, and c is stored in unit 33H.

4.2. Combine the two half-byte numbers into a one-byte number. Combine the lower 4 bits of the contents in the on-chip RAM 50H and 51H addresses, and store the result in the on-chip RAM 52H address.

4.3. D1 and K1 are connected as shown in the attached figure.

[Reprint] 51 MCU Exercises
① Try programming to implement the following control: D1 lights up initially, and then D1 changes state once each time the switch is pressed.

② Try programming to implement the following control: D1 lights up initially, and then when the switch is closed, D1 changes its state every 250 milliseconds, and when the switch is opened, D1 maintains the last state without changing (assuming the crystal oscillator frequency = 3MHz).

Reference address:51 MCU Exercises

Previous article:Calculation of initial value of timer/counter in 51 single chip microcomputer
Next article:51 single chip microcomputer system application

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号