• 0
نورالدين

8051

سؤال

دلونا علي مرجع او شي من هدا القبيبل في intel 805 اتمني ان يكون بالعربيه

منتظر

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه

8 إجابة على هذا السؤال .

  • 0

Introduction

Today, after more than 20 years of continuous improvement, MCU 8051 is being manufactured across the world by various companies under many different trademarks. Of course, the latest models are by far more advanced than the original 8051. Many of these are labeled as "8051 compatible", "8051 compliant", or "8051 family" to emphasize their "noble heritage". These tags should imply that MCUs share common architecture and are programmed in a similar fashion, using the same instruction set. In practice, if you master one of the models, you will be able to handle any other from 8051 family which encompasses several hundreds of different controllers. This book covers the model named AT89S8252, manufactured by Atmel. Why this particular one? Because it is widespread, cheap and uses Flash memory. The latter makes it ideal for experimentation due to the fact that program can be loaded and erased a number of times. Also, thanks to the built-in SPI system (Serial Programming Interface), program can be loaded to the MCU even if the chip has already been mounted to the designated device.

MCU AT89S8252 ID Card

• Member of 8051 family.

• 8KB of Flash memory for storing the program.

o Program is loaded via SPI serial interface.

o Program may be written/erased up to 1.000 times.

• 2KB of EEPROM memory for data storage.

o Contents of EEPROM may be changed up to 100.000 times.

• Power Supply: 4 – 6V.

• Clock: 0 – 24MHz.

• 256 bytes of internal RAM for storing variables.

• 32 I/O lines.

• Three 16-bit timers / counters.

• 9 interrupt sources.

• 2 additional low-consumption modes.

• Programmable UART serial communication.

• Programmable Watch Dog timer.

Pins on the casing:

VCC

Power Supply (4 - 6V).

GND

Negative supply pole (ground).

Port 0 (P0.0 - P0.7)

If designated as output, each of these pins can be connected up to 8 TTL input circuits. If designated as input, they are high impedance inputs as their potential is undefined with respect to the ground. If external memory is used, these pins are used for alternate transfer of data and addresses (A0-A7) for accessing the extra memory chip. Signal on ALE pin determines the mode of transfer on port.

Port 1 (P1.0 - P1.7)

If designated as output, each of these pins can be connected up to 4 TTL inputs. If designated as input, these pins act like standard TTL inputs (that is, they have an internal resistor connected to the positive supply pole and a +5V voltage). Also, pins of Port 1 have alternate functions according to the following table:

Pin Alternate function

P1.0 T2 (Timer 2 input)

P1.1 T2EX (Timer 2 control input)

P1.4 SS (SPI control input)

P1.5 MOSI (I/O of SPI system)

P1.6 MISO (I/O of SPI system)

P1.7 SCK (SPI clock signal)

Each of the functions will be explained in details later in the chapter.

Port 2 (P2.0 - P2.7)

If designated as input or output, this port is identical to Port 1. If external memory is used, Port 2 stores the higher address byte (A8-A15) for addressing the extra memory chip.

Port 3 (P3.0 - P3.7)

Similar to Port 1, Port 3 can also be used as unviersal input or output, but pins of Port 3 also have alternate functions. Each of the functions will be explained in detail later in the chapter.

Pin Alternate function

P3.0 RXD (Serial input)

P3.1 TXD (Serial output)

P3.2 INT0 (External interrupt 0)

P3.3 INT1 (External interrupt 1)

P3.4 T0 (Timer 0 external input)

P3.5 T1 (Timer 1 external input)

P3.6 WR (Signal write to external memory)

P3.7 RD (Signal read from external memory)

RST

Positive voltage impulse on RST pin resets the MCU. In order to be detected, this impulse needs to have duration of at least two operating cycles (this cycle represents the time necessary to execute one instruction and lasts for 12 oscillator signals).

ALE/PROG

This pin emits an impulse sequence with a frequency equal to 1/6 of the frequency generated by the main oscillator. If external memory is used, signal from this pin controls the additional register for temporary storage of the lower address byte (A0 - A7). This pin also serves as a control input during the writing of program to MCU.

PSEN

Signal of this pin is used for reading from external program memory (ROM).

EA/VPP

When this pin is connected to the ground, MCU gets program instructions from external program memory. In case that internal program memory is used (common case), this pin should be connected to the positive supply pole (VCC). During the loading of program to internal Flash memory, this pin is at +12V.

XTAL 1

This is the input part of internal oscillator. It is used for synchronizing the MCU with another circuit. Also, if there is need to use an external oscillator, it connects to this pin.

XTAL 2

Input of internal oscillator connects to this pin. In case external oscillator is used, this pin is without a function.

SFR Registers (Special Function Registers)

MCU AT89S8252 has total of 33 Special Function Registers. For the sake of compatibility with earlier 8051 models, basic group of registers (22 of them) kept their function and addresses, while the rest were added to manage new functions.

As shown in the following table, each of the registers has its name and specific address in RAM. Locations not shaded are planned for future expansions and new MCU models, and are generally not available. This chapter covers "general" SFR registers; specialized registers such as the ones controlling the timer, or SPI, will be covered in the following chapters.

Accumulator

Accumulator is a general purpose register which stores runtime results. Before performing any operation upon an operand, operand has to be stored in the accumulator. Results of arithmetical operations (performed by ALU) are also stored in the accumulator. When transferring data from one register to another, it has to go through the accumulator. Due to its verastile role, this is the most frequently used register, essential part of every MCU.

"R" registers (R0 – R7)

Although not true SFR registers, "R" registers deserve to be mentioned at this point. They are located within one of the 4 banks in RAM, and like the accumulator, serve for temporary storage of variables and runtime results. Two bits of PSW register are in command which bank will hold "R" registers.

Note: Since registers are called upon by the name during the writing of program, programmer needs not to know their exact addresses. When compiled (translated into hex code comprehensible to the controller), program will automatically replace register names with the appropriate addresses.

B register

Instructions of multiplication and division can be applied only to operands located in registers A and B. Other instructions can use this register as a secondary accumulator (a).

P0, P1, P2, P3 - I/O Ports

If external memory and system for serial communication are not used, user has 4 ports (32 I/O lines) at disposal for communicating to the environs. Every port bit corresponds to one of the pins on the casing, thus controlling the voltage on output (0 or 5V). Vice versa, while reading, voltage on input pins is interpreted into bit logic on port. At the same time, state of port bit designates the pin as input or output: zero for output, one for input.

After reset, all port bits are set, designating all corresponding pins as input.

Stack Pointer (SP)

The number in Stack Pointer points to the location of the last "valid" address within the Stack. With the beginning of every new routine, Stack Pointer increases by 1; upon return from routine, SP decreases by 1. After reset (or turning the power on), this register contains number 7, meaning that the amount of RAM allocated to Stack begins from this memory location. If another value is written to SP, entire Stack moves to the new specified location.

Program Status Word (PSW)

Program Status Word is one of the most important SFR registers, and is used for managing program during the runtime. ALU automatically makes changes to certain bits of this register.

P (bit 0) - Parity bit. If numeral in accumulator is even, bit is automatically set (1), otherwise it's cleared (0). It is commonly used in data transfers via serial connection.

- (bit 1) - This bit is intended for the upcoming MCU models and shouldn't be used.

OV (bit 2) - Overflow bit. If result of arithmetical operation exceeds 255 (decimal), OV is set (1), otherwise it's cleared (0).

• RS1, RS0 (bits 3 and 4) - Register select. Masking these bits stores registers R0 - R7 into one of the 4 banks in RAM, according to the following table.

RS1 RS2 Location in RAM

0 0 Bank 0 00h-07h

0 1 Bank 1 08h-0Fh

1 0 Bank 2 10h-17h

1 1 Bank 3 18h-1Fh

F0 (bit 5) - Flag 0. An all-purpose flag.

AC (bit 6) - Auxiliary Carry Flag, used only for operations with BCD (Binary Coded Decimals).

CY (bit 7) - Carry Flag. Auxiliary (ninth) bit for arithmetical and shift operations.

Data Pointer

Data Pointer actually consists of two registers: DPH (Data Pointer High) and DPL (Data Pointer Low). Data Pointer's 16 bits are used for addressing external memory. Since this is the only 16-bit register available to programmer, it is commonly used for temporary storage of data and runtime results not related to memory locations.

Counters and Timers

It was mentioned in previous chapters that MCU clock employs quartz crystal. As this frequency is highly stable and accurate, it is ideal for time measuring (similar oscillators can be found in watches). To determine the amount of time past between two occurrences, all you need to do is count the generated impulses. This is where the timer takes part; properly programmed, value of timer register will increase or decrease with every MCU clock impulse. Since one instruction takes 12 oscillator cycles to complete, the math is easy. For example, if quartz oscillator works at 12 MHz, timer register will increase/decrease every microsecond (million times per second).

AT89S8252 has three timers/counters marked as T0, T1, and T2. Two of them are from the "first lineup" shared by all models from 8051 family, while the third (T2) was added in the process of developing the basic model. Their purpose is to measure time and count external occurrences, but can also be used as clock in serial connection, Baud Rate.

Timer T0

As shown in the image below, T0 consists of two registers - TH0 and TL0, for storing higher and lower byte of a 16-bit binary numeral.

For example, if T0 = 0, both registers will have value of zero. If T0 has value of 1000 (decimal), TH0 (higher byte) will hold decimal value of 3, and TL0 (lower byte) will hold decimal value of 232. See the image below.

Formula for calculating the value of 16-bit register is simple:

TH0 * 256 + TL0 = T

On our previous example:

3 * 256 + 232 = 1000

Timers are technically 16-bit registers, thus the maximal value they can hold is 65.535. If this number is exceeded, timer will automatically reset and start from zero. This situation is known as overflow.

Two registers tightly connected to Timer T0 are TMOD and TCON.

TMOD - Timer Mode

This register sets mode for timers T0 and T1. As shown in the image below, lower 4 bits (bit 0 - bit 3) are associated with T0, while the higher 4 bits (bit4 - bit7) are associated with T1.

The following table gives details on bits 0 - 7 :

Bit Bit Name Purpose Timer

7 GATE1 1 Timer works only if INT1 (P3.3) is set

0 Timer works regardless of INT1 (P3.3) T1

6 C/T1 1 Timer counts impulses on T1 (P3.5)

0 Timer counts impulses of internal oscillator T1

5 T1M1 Timer mode T1

4 T1M0 Timer mode T1

3 GATE0 1 Timer works only if INT0 (P3.2) is set

0 Timer works regardless of INT0 (P3.2) T0

2 C/T0 1 Timer counts impulses on T0 (P3.4)

0 Timer counts impulses of internal oscillator T0

1 T0M1 Timer mode T0

0 T0M0 Timer mode T0

Four bits from the previous table determine the operating mode of timers T0 and T1. There are 4 of these modes, and each will be covered in details.

T0M1 T0M0 Mode Description

0 0 0 13-bit Timer

0 1 1 16-bit Timer

1 0 2 8-bit auto-reload

1 1 3 Split mode

Mode 0 (13-bit Timer)

This mode is an antiquity kept just for the sake of compatibility with older MCUs. When activated, whole higher byte TH0 and only the first 5 bits of lower byte TL0 are accessible. Thus, with Mode 0, Timer T0 uses only 13 of its 16 bits. How does it work? On each impulse, lower register is changed (the "trimmed" one). When TL0 is filled after 32 impulses, it is automatically reset, and TH0 is increased by one. This process repeats itself until 8192 impulses are registered, upon which both registers are reset to zero.

Mode 1 (16-bit Timer)

Mode 1 uses all bits of registers TH0 and TL0, and is commonly used. Counting process is same as with Mode 0, except the timer reaches value of 65.536 (max for 16 bits) before reset.

Mode 2 (8-bit "auto reload" Timer)

What is "auto reload" ? Simply, only one of two registers is used for counting; however, it does not start from zero, but from a specified value stored in the other register (0-255).

Advantages of this mode will be illustrated on the following example: suppose that there is a need to report every 55th impulse of the clock. If Mode 0 or Mode 1 was used, you would need to store 200 (decimal) into T0, and then continually check for the overflow (exceeding 255 decimal). Upon hit, value of 200 would need to be written to T0 again. In Mode 2, MCU performs this task automatically. Namely, TL0 works as an 8-bit timer, while TH0 stores the starting value, specifically 200 in our example. When TL0 is filled, instead of reset, it will load value from TH0. Thus, to register every 55th impulse, all you need to do is write 200 to TH0, and set the Timer Mode 2.

Mode 3 ("Split" Timer)

When Timer T0 is configured to Mode 3, you actually get an additional timer. In this mode, registers TH0 and TL0 act as separate 8-bit timers: TH0 substitutes Timer 0, while TL0 substitutes Timer 1. Consequently, all control bits associated with the original Timer 1 (16-bit register consisting of TH1 and TL1) are now in control of newly created "Timer 1". This means that, although it can be set to any mode (Mode 1, 2, or 3), the original Timer 1 cannot be stopped anymore, because there is simply no control bit to do it. In this mode, it will be constantly active in the background.

TCON - Timer Control

TCON is another register in direct control of the timers.

Of the 8 bits, TCON uses only 4 bits for controlling the timers, while the other 4 are associated with interrupts.

Bit Bit Name Purpose Timer

7 TF1 This bit is automatically set in case of overflow in Timer T1 T1

6 TR1 1 Timer T1 is on

0 Timer T1 is off T1

5 TF0 This bit is automatically set in case of overflow in Timer T0 T0

4 TR0 1 Timer T0 is on

0 Timer T0 is off T0

Starting Timer T0

Select this timer and set the desired mode.

This sets the Timer T0 to operate in Mode 1, and count the impulses of internal source with frequency equal to 1/12 of the quartz oscillator's frequency.

Right after the command for setting the bit TR0, Timer is operational. Assuming that 12MHz quartz crystal is installed, value in T0 will increase every microsecond. After passing of 65.536 microseconds, both registers of the Timer will be full. MCU automatically resets them and the Timer continues the loop, as long as the bit TR0 is set.

Reading Timer

Depending on the application, you need either the value written in Timer registers, or the exact point of time at which the Timer is reset.

If you need to read the value of the Timer which uses only one register for counting (Mode 3, for example) just read the value of that register.

If the Timer works in Mode 2, reading is a bit more complicated. For example, you might have obtained values of the lower and the higher byte, respectively:

TH0=15, TL0=255.

Seemingly, the results are valid, but the true state of registers at the moment of reading was:

TH0=14, TL0=255.

This widely inaccurate reading (255 impulses) may happen due to not so obvious, yet perfectly logical reason. Lower byte was read ok (255), but while the Program Counter was "loading" your new instruction for reading TH0, overflow occurred, changing both registers (TH0: 14 -> 15, TL0: 255 -> 0). Solution to the problem is simple: you need to read the higher byte first, then the lower byte, and then the higher byte again. If two readings of higher byte do not match, the sequence has to be repeated (this is a mini-loop in the program, not more than 3 instructions).

There is also another solution: just turn off the Timer for the time of reading (clear the bit TR0 in TCON), and turn it on afterwards.

Detection of Overflow

Usually, there is no need to continually read the Timer registers; it is sufficient to detect the moment at which they are reset, the so-called Overflow. When it happens, bit TF0 in TCON will be automatically set. This moment can be "awaited", by writing a small loop for testing the bit continually, or by enabling an interrupt. Suppose that there is a need to suspend a program for duration of 0.05 seconds (5000 cycles):

First, you need to calculate a number to be written to Timer registers:

This value should be stored to Timer registers TH0 and TL0:

After that, when started (bit TR0 = 1), Timer will continue the counting up from our written value. Now a program instruction can be used to test if the bit TF0 was set, which should take place after exactly 50.000 cycles, i.e. 0.05 seconds.

Measuring Impulse Duration

Measuring time past between two events is a common task in electronics; for example, measuring for how long has device been active. Note the bit named GATE0 (in TMOD Register) in the Timer schematics. If this bit is cleared, pin P3.2 has no effect on the Timer. But, if GATE0 = 1, Timer will work only for as long as the pin P3.2 is set. This means that, by bringing 5V externally to this bit, simultaneously with turning the power on, Timer can measure the active period of the device, which was the original idea.

Counting Impulses

The answer is in bit C/T0 in TCON Register. Similar to the previous example, C/T0 "brings in" an external signal: if bit is cleared, Timer measures the time, i.e. impulses generated by MCU clock. If bit is set, impulses from P3.4 (T0) are conducted to Timer's input. Having no predetermined order or sequence, these impulses cannot be used for measuring time, effectively turning the Timer into Counter. The highest frequency this Counter can record equals 1/24 of frequency of used quartz-crystal.

Timer T1

This is the "twin brother" of Timer T0. It can fulfill same roles, it is also controlled by TMOD and TCON, and has 4 different modes of work.

Timer T2

This is the third 16-bit timer/counter, installed only in newer MCU models. Unlike T0 and T1, this timer comprises 4 registers. TH2 and TL2 are connected serially, forming a 16-bit counting register. Other two registers, RCAP2H and RCAP2L are also conected serially, and their purpose is to "capture" the contents of the counting register.

Main advantage of this organization lies in the fact that all reading and swapping take place concurrently, by means of single instruction, with no need for programming acrobatics. T2, like its older relatives, T0 and T1, has several different modes of work that will be explained in this chapter.

بالستفلدة من أحد المواقع الاجنبية

8051.pdf

تم تعديل بواسطه ammar7lb
0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه
  • 0

الاخ ammar اشكرك علي الاجابه وعفوا للتاخير لكن كما تعلم اخي انا ضعيف في الانجليزيه حبذا ان تكتب توضيح بالعربيه اذا كان فيه وقت

بالنسبه للملف بعد ان حملته بيفتح معي في الورد بصوره غريبه غير قابله للقرائه كما هو الحال لملفات اخري ؟

والمشكله اعتقد من الورد عندي اذا في عندك حل لا تبخل به علي؟ الورد من نوع اكس بي عربي

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه
  • 0

السلام عليكم ورحمة الله وبركاته

أخي نور عذراً منك,فبسبب ضيق الوقت (كما تعلم نحن في فترة الامتحانات)

لن أكون قادراً حالياً على تنسيق موضوع حول ال 8051

لكني أعدك بذلك في أسرع وقت ممكن

أما بالنسبة للملف المرفق في مشاركتي السابقة فهو من نوع PDF

وليس من نوع Word

أي أنك بحاجة لبرنامج Adobe Acrobat حتى تتمكن من قراءة الملف

والله ولي التوفيق

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه
  • 0

السلام عليكم,

هناك العديد من المواقع تمكنك من تحميل Acrobat Reader وهو برنامج مجاني. على سبيل المثال ادخل إلى www.download.com وقم ببحث على Acrobat Reader وستحصل على ما تريده .

إلى اللقاء.

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه
  • 0

أنا عملت فترة على 8051

و كنت أعمل على kiel software - for micro control

و كان به مميزات كثيرة منها المحاكى بالأضافة الى أنه يدعم السي و الأسيمبلي لأكثر من 500 نوع من المتحكمات

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه
  • 0

على فكرة

دار شعاع للنشر

كانت منزله كتاب للميكروكونترول بس للاأسف أنا مش فاكر أسمه

0

شارك هذا الرد


رابط المشاركة
شارك الرد من خلال المواقع ادناه
زوار
This topic is now closed to further replies.

  • يستعرض القسم حالياً   0 members

    لا يوجد أعضاء مسجلين يشاهدون هذه الصفحة .