Microcontroller C Language Tutorial Lesson 2 - Preliminary Understanding of the 51 Chip

Publisher:电竞狂人Latest update time:2023-05-24 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Our first project in the previous lesson was completed. Friends who know C language may say, "This is not much different from the C language on PC." There is really not much difference. C language is just a general term for a programming language. There will be some detailed changes in C language related to different processors. When writing a C program for a PC, if you want to program the hardware, you must have a certain understanding of the hardware. This is especially true for 51 microcontroller programming, because its development and application cannot be separated from the hardware, so we must first make a preliminary Get to know the structure and pin functions of the 51 rim chip. There are many types of MSC51 architecture chips, with different specific features and functions (a data list of some commonly used 51 chips will be added to the appendix written in the future). In the following tutorials, Atmel's AT89C51 and AT89C2051 will be used as the central objects. For learning, both are typical representatives of the AT89 series. They are widely used among enthusiasts. They have a lot of application materials and are cheap. They are the first choice chips for beginners to learn 51. Hehe, the saliva is a bit like selling advertising.
Lesson 2: A preliminary understanding of the 51 chip
Figure 2-1 AT89C51 and AT89C2051 pin function diagram
 

AT89C51

AT89C2051

4KB programmable Flash memory (can be erased and written 1000 times)


2KB programmable Flash memory (can be erased and written 1000 times)



Level 3 program memory confidentiality



Two-level program memory security



Static operating frequency: 0Hz-24MHz



Static operating frequency: 0Hz-24MHz



128 bytes internal RAM



128 bytes internal RAM



2 16-bit timers/counters



2 16-bit timers/counters



a serial communication port



a serial communication port



6 interrupt sources



6 interrupt sources



32 I/O leads



15 I/O leads



On-chip clock oscillator



1 on-chip analog comparator



Table 2-1 Main performance table of AT89C51 and AT89C2051


Figure 2-1 is the pin function diagram of AT89C51 and AT89C2051. Table 2-1 is their main performance table. It can be seen from the above that they are roughly the same. Since AT89C2051 has very few IO lines, it cannot add RAM and program ROM, and there is also less on-chip Flash memory. However, its size is much smaller than AT89C51. You can customize it according to actual needs in the future. Select. They each have their own characteristics but their core is the same. Let’s take a look at the specific pin functions of AT89C51.

1. Power supply pin
Vcc 40 Power supply terminal
GND 20 Ground terminal
* The working voltage is 5V, and the working voltage of AT89LV51 is 2.7-6V. The pin functions are the same.


2. External crystal pins
Lesson 2: A preliminary understanding of the 51 chip
Figure 2-2 External crystal pins

XTAL1 19
XTAL2 18
XTAL1 is the inverting amplifier input terminal of the on-chip oscillator, and XTAL2 is the output terminal. When using an external oscillator, the external oscillation signal should be directly added to XTAL1, while XTAL2 is left floating. In internal mode, the clock generator divides the oscillation pulse by two. For example, if the crystal oscillator is 12MHz, the clock frequency is 6MHz. The frequency of the crystal oscillator can be selected from 1MHz to 24MHz. The capacitance is about 30PF.

*The chip model is also AT89C51, and there is a frequency number behind it, which is available in 12, 16, 20, and 24MHz. Everyone should pay attention when purchasing and selecting. For example, AT89C51 24PC is an ordinary commercial chip with a maximum oscillation frequency of 24MHz and a 40P6 package.   


3. Reset RST 9
When the oscillator is running, when a high level of more than two machine cycles (24 oscillation cycles) appears on this pin, it will reset the microcontroller. As long as this pin remains high, the 51 chip will Cycle reset. After reset, the P0-P3 ports are all set to 1 and the pins show high level, and the program counter and special function register SFR are all cleared. When the reset pin changes from high level to low level, the chip starts running the program at 00H of ROM. A commonly used reset circuit is shown in Figure 2-3.

*The reset operation will not affect the internal RAM.
Lesson 2: A preliminary understanding of the 51 chip
Figure 2-3 Common reset circuit
4. Input and output pins

(1) P0 port [P0.0-P0.7] P0 is an 8-bit open-drain bidirectional I/O port. When the port is set to 1 (write 1 to the port), it acts as a high-impedance input terminal. When used as an output port, it can drive 8 TTL.

When programming the internal Flash program memory, the instruction byte is received; when verifying the program, the instruction byte is output, requiring an external pull-up resistor.

When accessing external programs and external data memory, P0 port is the address (lower 8 bits)/data bus of time-sharing conversion, and the internal pull-up resistor works during the access.

(2) P1 port [P1.0-P1.7] P1 is an 8-bit bidirectional I/0 port with internal pull-up resistor. Can drive 4 TTL on output. When the port is set to 1, the internal pull-up resistor pulls the port to a high level for input.

When programming the internal Flash program memory, the lower 8-bit address information is received.

(3) P2 port [P2.0-P2.7] P2 is an 8-bit bidirectional I/0 port with internal pull-up resistor. Can drive 4 TTL on output. When the port is set to 1, the internal pull-up resistor pulls the port to a high level for input.

When programming the internal Flash program memory, the upper 8 bits of address and control information are received.


When accessing external programs and 16-bit external data memory, the P2 port sends the high 8-bit address. When accessing an external data memory with an 8-bit address, the contents of its pins will not change during this period.

(4) P3 port [P3.0-P3.7] P2 is an 8-bit bidirectional I/0 port with internal pull-up resistor. Can drive 4 TTL on output. When the port is set to 1, the internal pull-up resistor pulls the port to a high level for input.

When programming the internal Flash program memory, control information is received. In addition, the P3 port is also used for some specialized functions. Please see Table 2-2 for details.

*When the P1-3 port is used as input, due to the internal connected resistor, the pin that is externally pulled low will output a certain current.


P3 pin

Combined functions

P3.0

Serial communication input (RXD)

P3.1

Serial communication output (TXD)

P3.2

External Interrupt 0 (INT0)

P3.3

External interrupt 1 (INT1)

P3.4

Timer 0 input (T0)

P3.5

Timer 1 input (T1)

P3.6

External data memory write strobe WR

P3.7

External data memory write strobe RD

Table 2-2 P3 port pin-shared function table


call! I’ve said so much in one breath, let’s stop for a moment. Well, what? What is a pull-up resistor? Simply speaking, the pull-up resistor pulls the level high, usually a 4.7-10K resistor is connected to the Vcc power supply, while the pull-down resistor pulls the level low, and the resistor is connected to the GND ground line. The specific explanation is not what is discussed here. Let’s look at other pin functions next.

5. Other control or multiplexing pins

(1) ALE/PROG 30 When accessing external memory, the output of ALE (Address Latch Enable) is used to latch the low-order byte of the address. Even if the external memory is not accessed, the ALE terminal still outputs a pulse signal at a constant frequency (this frequency is 1/6 of the oscillator frequency). When accessing external data memory, an ALE pulse occurs. When programming the Flash memory, this pin is used to input the programming pulse PROG

(2) PSEN 29 This pin is the strobe signal output terminal of the external program memory. When the AT89C51 fetches instructions or constants from the external program memory, it outputs 2 pulses per machine cycle, which is effective twice. But when accessing external data memory, there will be no pulse output.

(3) EA/Vpp 31 External access permission end. When this pin accesses external program memory, it should be input low. To enable the AT89C51 to only access the external program memory (address 0000H-FFFFH), this pin must remain low, and when the on-chip program memory is to be used, this pin must remain high. When programming the Flash memory, this pin is used to apply the Vpp programming voltage. There are two types of Vpp voltages. Similar to the chip, the maximum frequency value is determined based on the attached number or the characteristic word in the chip. The details are listed in Table 2-3.



Vpp = 12V



Vpp = 5V




Model number printed on the chip surface



AT89C51



xxxx



YYW



AT89LV51



xxxx



YYW



AT89C51



xxxx-5



YYW



AT89LV51



xxxx-5



YYW




Feature words in the film



030H=1EH



030H=1EH



030H=1EH



030H=1EH



031H=51H



031H=61H



031H=51H



031H=61H



032H=FFH



032H=FFH



032H=05H



032H=05H



Table 2-3 The relationship between Vpp, chip model and on-chip signature words


Seeing this, you should have a certain understanding of the functions of the AT89C51 pins. We will not discuss the timing of the pins in programming and verification in detail here. Under normal circumstances, we do not need to hold it. Unless you want to develop your own programmer. In the following course, we will start to use some simple examples to explain the syntax and writing methods of C programs, interspersed with related hardware knowledge such as serial ports, interrupt usage, etc.


    Reference address:Microcontroller C Language Tutorial Lesson 2 - Preliminary Understanding of the 51 Chip

    Previous article:How to use Keil to verify how many bytes a microcontroller variable occupies
    Next article:ISD4004 voice chip C51 driver source code

    Latest Microcontroller Articles
    • Download from the Internet--ARM Getting Started Notes
      A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
    • Learn ARM development(22)
      Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
    • Learn ARM development(21)
      First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
    • Learn ARM development(20)
      With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
    • Learn ARM development(19)
      After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
    • Learn ARM development(14)
    • Learn ARM development(15)
    • Learn ARM development(16)
    • Learn ARM development(17)
    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号