20-day 89C51 microcontroller summary

Publisher:DreamySunsetLatest update time:2012-10-17 Source: 21IC Keywords:89C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I have been looking at single-chip microcomputers for a long time, so I want to make a summary. In fact, single-chip microcomputers are not as complicated as imagined in terms of chips! 89C51 has only 40 pins. Among them, P0~P3 ports occupy 32 pins. One is connected to the ground and the other is connected to the power supply, two oscillation pins. An EA pin is the starting address selection terminal of the ROM. An ALE/Vpp off-chip address latch serves as the pin/line programming power input terminal. PSEN is the off-chip ROM enable terminal. Of course, there is also a reset REST pin. Among them, all P3 ports have a second function multiplexing: timer interrupt serial port interrupt. When the P0~P3 port writes #FFH, the on-chip latch is set to 1. This is a single port for bidirectional input and output. This is from the outside of the chip.

From the inside of the chip, there are two main independent memories, ROM and RAM. One is for program indication, and the other is for data processing and storage. ROM and RAM are distinguished by addressing mode during programming. They both have a capacity of 64KB. The ROM has a 4KB storage space on the chip. EA indicates whether the program is executed from outside the chip or from inside the chip. The RAM on the chip is 256 bytes, that is, FFH is divided into 4 parts. 00H~1FH is the working register group. 20H~2FH is the addressing space. 30H~7FH is the user RAM area. 80H~FFH is the special register area. There are 22 SFRs (not introduced here).

Let's talk about the instruction system. MOV, MOVX, MOVC are the three transfer instructions, and the off-chip memory cannot be directly transferred. The three call instructions AJMP, LJMP, SJMP are used for different call ranges. The logic arithmetic instructions ANL, ORL, XRL, as well as ADD, SUBB, MUL, and DIV. There are also many instructions such as exchange, jump, loop, bit addressing, Boolean processing instructions, etc.

For example, the following loop-jump instruction

MOV R0,#00H
MOV R1,#AAH
MOV R7#0BH
loop:  MOV A ,@R0
MOV   @R1,A
INC R0
INC R1
DJNZ  R7,loop
END

This program is used to perform the on-chip transfer function.

Let's talk about the general flow of a program. It can be divided into sequence, branching, looping, and combined nesting. The example above is a type of loop.

Write a branching program example

MOV A,R1
RL    A
MOV DPTR,#data
JMP  @A +DPTR
data:     AJMP  KK1
AJMP  KK2
.
.
AJMP KKn

This instruction is a branch transfer with data as the starting address and R1 as the offset. Because AJMP is a two-byte instruction, RLA must be executed.

Let's talk about interrupts and timing.

The registers involved in the interrupt are TCON, IE, IP, and SCOM.

The interrupt request is executed by setting the interrupt flag bit. The interrupt has 5 entry addresses: 03H 0BH 13H 1BH 23H.

For example, the entry of external interrupt 1 is set to the highest priority in default mode

SETB PX1

STEB  EX1

STEB EA

It's very simple, a bit like a level-breaking game where you have to complete every step before you can execute the interrupt.

Below is the timer, which is widely used in microcontrollers. There are 4 working modes: 0, 1, 2, and 3.

I will use the typical timer 0 mode 2 at 12MHZ to program a sine wave output XXMS at P1.0. The initial value is replaced by KKH.

MOV P1 ,#FFH
MAIN: MOV TMOD , #02H
MOV TH0 ,#KKH
MOV LHO ,#KKH
STEB ET0
STEB TRO
STEB EA
AJMP $


Interrupt procedure TIME0: CLR TF0
CPL P1.0
RETI.

There is also serial port transmission. 89C51 has 4 modes of transmission, among which the baud rate setting is particularly important.

The registers involved are TCOM TDOM SCOM SDOM PCON.

In fact, 89C51 can also use software to simulate bus interfaces, such as SPI, I2C, etc. There are too many external expansions for key program settings. I will write and post them later when I have time.

Keywords:89C51 Reference address:20-day 89C51 microcontroller summary

Previous article:What is 51 MCU addressing
Next article:MCU decoding 315M pt2262 encoded c51 program

Recommended ReadingLatest update time:2024-11-16 16:43

The software and hardware design of digital voltmeter realized by single chip microcomputer
  The circuit for realizing digital voltmeter generally uses many components and is not very convenient to adjust. This article introduces the use of digital potentiometer and single-chip microcomputer to realize it, which is much simpler and more convenient than the general A/D-NC-D/A method, and can automate the adju
[Microcontroller]
The software and hardware design of digital voltmeter realized by single chip microcomputer
89C51 reset circuit principle, conditions, schematic diagram and clock concept
1. reset condition The 89C51 microcontroller needs a high level for 24 clock cycles to reset. The function of reset is to make the program pointer point to address 0. Each program starts executing from address 0, so the concept of reset is to start the program from the beginning. implement. 2. Reset circuit schemati
[Microcontroller]
89C51 reset circuit principle, conditions, schematic diagram and clock concept
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号