페이지 정보작성자 키트 작성일2017-09-12 11:13 조회2,491회 댓글0건
Chapter 4 : AT89S8253 Microcontroller
It has been more than 20 years since the first version of the 8051 microcontroller was launched. During that time it has undergone various upgrades and improvements. Today, the 8051 microcontroller is being manufactured across the globe by many manufacturers and under different names. Of course, the latest versions are by far more advanced than the original one. Many of them has the label “8051 compatible”, “8051 compliant”or “8051 family” in order to emphasize their “noble heritage”. These tags imply that microcontrollers have similar architecture and are programmed in a similar way using the same instruction set. Practically, if you know how to handle one microcontroller belonging to this family, you will be able to handle any of them. In other words, several hundreds of different models are at your disposal.
This book covers one of them called the AT89S8253, manufactured by Atmel. Why this particular one? Because it is widely used, cheap and uses Flash memory for storing programs. The last feature mentioned makes it ideal for experimentation due to the fact that program can be loaded and erased from it for many times. Besides, thanks to the built-in SPI System (Serial Programing Interface), the program can be loaded to the microcontroller even after embedding the chip in the target device.
4.1 The AT89S8253 microcontroller ID
- Compatible with 8051 family.
- 12Kb of Flash Memory for storing programs.
- Program is loaded via SPI System (Serial Peripheral Interface).
- Program may be loaded/erased up to 1000 times.
- 2Kb of EEPROM Memory.
- Power supply voltage: 4-6V.
- Operating clock frequency: 0-24MHz.
- 256 bytes of internal RAM for storing variables.
- 32 input/output pins.
- Three 16-bit timers/counters.
- 9 interrupt sources.
- 2 additional power saving modes (low-power idle and power-down mode).
- Programmable UART serial communication.
- Programmable watchdog timer.
- Three-level program memory lock
The AT89S53 comes in the following packages:
4.2 Pinout Description
Power supply voltage (4-6V)
Ground ( Negative supply pole)
If configured as outputs, each of these pins can be connected to up to 8 TTL inputs. If configured as inputs, the pins can be used as high-impedance inputs as their potential is not defined relative to ground, i.e. they are floating. If additional (external) memory is used, these pins are used for accessing it. Signal on the ALE pin determines what and when will be transferred to this port.
If configured as outputs, each of these pins can be connected to up to 4 TTL inputs. When configured as inputs, these pins act as standard TTL inputs, that is, each of them is internally connected to the positive supply voltage via a resistor of relatively high impedance. Power supply voltage provided on these inputs is 5V. Also, the Port 1 pins have alternate functions as shown in the table below:
PORT PIN ALTERNATE FUNCTION P1.0 T2 (Timer 2 input) P1.1 T2EX (Timer 2 control input) P1.4 SS (SPI system control input) P1.5 MOSI (SPI system I/O) P1.6 MISO (SPI system I/O) P1.7 SCK (SPI system clock signal)
Whether configured as an input or an output, this port acts the same as Port 1. If external memory is used, the high byte of the address (A8-A15) comes out on the Port 2 which is thus used for addressing it.
Similar to P1, Port 3 pins can be used as general inputs or outputs. They also have additional functions to be explained later in the chapter.
PORT 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 (External data memory write signal) P3.7 RD (External data memory read signal)
Logic one (1) on this pin causes the microcontroller to be reset.
In normal operation, the ALE pin is activated at a constant rate of 1/16 the oscillator frequency and can be used for external clocking and timing purposes. When external memory is used, a signal from this pin is used to latch the low byte of an address (A0-A7) from P0. During the process of writing a program to the microcontroller, this pin also serves as a control input.
This pin provides a signal used for accessing external program memory (ROM).
When this pin is connected to ground, the microcontroller reads program instructions from external program memory. If internal program memory is used, which is the common case, this pin should be connected to the positive power supply voltage (VCC). During the process of programming internal Flash mamory, this pin is supplied with +12V.
This is internal oscillator input. It is used for the purpose of synchronizing the operation of the microcontroller with some other circuit or for connecting external oscillator when used.
This pin is connected to internal oscillator output. Therefore, it is out of use when using external oscillator.
4.3 The AT89S8253 Microcontroller Memory Organization
Program Memory (ROM)
Program memory (ROM) with a capacity of 12Kb is designed in FLASH technology, which enables programs to be loaded and erased a large number of times. It is programmed via embedded SPI module (Serial Peripheral Interface). If necessary, it is possible to add external ROM memory chip, although 12Kb of ROM is usually more than enough.
Random Access Memory (RAM)
RAM memory consists of 3 blocks containing 128 registers each. Its structure falls into the 8051 standard:
- 128 general-purpose registers;
- 128 memory locations reserved for SFRs. Even though only some of them are trully used, free locations shouldn’t be used for storing variables; and
- 128 additional registers available for use (have no special purpose). Since they have the same addresses as SFRs, they are accessed by indirect addressing.
EEPROM is a special type of memory having features of both RAM and ROM. The contents of the EEPROM may be changed during operation, but remains permanently saved even after the loss of power. The AT89S8253 microcontroller has in total of 2K of EEPROM, that is 2048 locations.
All mentioned above about ROM and RAM memory expansion remains in force when it comes to the AT89S8253 microcontroller as it is based on the 8051 core. In other words, both memories can be added as external chips with the capacity of up to 64Kb. The process of addressing is also the same as in the 8051 standard.
Types of addressing
Similar to all microcontrollers compatible with the 8051, there are two ways of addressing:
- Direct addressing (for example: MOV A,30h); and
- Indirect addressing (for example: MOV A,@R0).
4.4 Special Function Registers (SFRs)
The AT89S8253 microcontroller has in total of 40 Special Function Registers. For the sake of the compatibility with the previous 8051 models, the core registers (22 in total) are the same for all of them, while the others were added later for the purpose of controlling upgraded functions of the microcontroller.
As shown in the table above, each of these registers has its name and specific address in RAM. Unoccupied locations are intended for the future upgraded versions of the microcontroller and shouldn’t be used. As their name suggests, these registers are mostly in control of one specific circuit within the microcontroller such as timers or SPI etc. and they will be discussed later in the book. This chapter covers only those SFRs controlling more than one circuit within the microcontroller.
The accumulator, otherwise marked as ACC or A, belongs to the core registers of the 8051 microcontroller. Its contents is not modified.
The B register also belongs to the core registers of the 8051 microcontroller. Bits of this register are not modified. It is used during multiply and divide operations (MUL and DIV instructions) to store the operands upon which these operations are performed.
PSW register (Program Status Word Register)
The PSW register belongs to the core registers of the 8051 microcontroller. Bits of this register are not modified.
SP registar (Stack Pointer Register)
The SP register belongs to the core registers of the 8051 microcontroller. Bits of this register are not modified.
Registers P0, P1, P2, P3
Each bit of these registers corresponds to one of the port pins having the same name. These registers are therefore used for comminication with peripheral environment which is carried out by sending data from registers to the corresponding pins and vice versa. They belong to the core registers of the 8051 microcontroller and their bits are not modified.
R registers (R0 - R7)
They belong to the core registers of the 8051 microcontroller. Their bits are not modified.
AUXR register (Auxiliary register)
The AUXR register contains only two active bits:
- 0 - ALE is activated at a constant rate of 1/6 the oscillator frequency.
- 1 - ALE is active only during execution of MOVX or MOVC instructions.
- 0 - When the microcontroller is in Power Down mode, the program proceeds with execution on high-to-low transition (1-0).
- 1 - When the microcontroller is in Power Down mode, the program proceeds with execution on low-to-high transition (0-1).
CLKREG register (Clock Register) X2
- 0 - The oscillator frequency (the XTAL1 pin) is divided by 2 before used as a clock (machine cycle lasts for 6 such periods).
- 1 - Quartz oscillator is used as a clock generator. This enables the quartz crystal of two times lower frequency (for example 6MHz instead of 12MHz) to be used for the same operating rate of the microcontroller.
Data Pointers are not true registers as they don’t physically exist. They consist of two separate registers: DPH (Data Pointer High) and DPL (Data Pointer Low). All 16 bits are used for addressing external and internal EEPROM memory. The DPS bit of the EECON register determines the registers to be used as data pointers:
DPS=0 -> Data pointer consists of DP0L and DP0H registers and is marked as DPTR0.
DPS=1 -> Data pointer consists of DP1L and DP1H registers and is marked as DPTR1.
Handling EEPROM memory
2 Kb of on-chip EEPROM memory enables this microcontroller to store data created during operation which must be permanently saved. In other words, all data stored in this memory remains permanently saved even after the loss of power. Minimum 100 000 writing cycles can be executed. This memory is easily used since there are only a few control bits enabling it.
EEPROM write and read is under control of the EECON special function register. Since the process of programming EEPROM is relatively slow (write to one register takes approximately 4mS), a small hardware trick is done in order to speed it up. When the EELD bit of the EECON register is set, the data is not directly written to the EEPROM registers, but loaded in a small buffer (temporary memory) with a capacity of 32 bytes. When this bit is cleared, the first data following it will be normally written to the EEPROM (takes 4 mS) along with all registers currently loaded in the buffer. Thus, it takes only 4mS to write all 32 bytes instead of 128mS otherwise required in a single byte writing.
EEPROM memory is handled in the same way as external memory. For this reason, a special instruction for additional memory chip (MOVX) is also used for EEPROM write and read. The EEMEN bit of the EECON register determines whether the data is to be written/read from additional memory chip or on-chip EEPROM memory.
Bits of the EECON register controls the operation of EEPROM memory:
The WRTINH bit is read-only. When the power supply voltage is too low for programming EEPROM, hardware automatically clears this bit, which means that write to EEPROM cannot be completed or is aborted if in progress.
The RDY/BSY bit is read-only.
- 0 - Write in progress (takes approximately 4mS).
- 1 - Write complete (data is written to EEPROM).
- 0 - Address for EEPROM write/read is stored in the DP0H and DP0L registers.
- 1 - Address for EEPROM write/read is stored in the DP1H and DP1L registers.
- 0 - Instruction MOVX is used for accessing external memory chip.
- 1 - Instruction MOVX is used for accessing internal EEPROM memory. If the register address is larger than 2K, the microcontroller will access external memory chip.
When set, the EEMWE bit enables write to EEPROM using the MOVX instruction. After completing EEPROM write, the bit must be cleared from within the program.
When set, the EELD bit enables up to 32 bytes to be written simultaneously. The bit is set and the MOVX instruction writes data to EEPROM (buffer is loaded). The bit is cleared before writing the last data. When the last MOVX is executed, the entire buffer is automatically loaded to EEPROM for 4mS.
4.5 Watchdog Timer (WDT)
The watchdog timer uses pulses generated by the quartz oscillator for its operation. It is disabled after reset and during Power Down Mode, thus having no effect on the program execution. If enabled, every time it counts up to the program end, the microcontroller reset occurs and program execution starts from the first instruction. Reset condition indicates that the program doesn’t work properly for some reason. The point is to prevent this from happening by setting instruction to reset the watchdog timer at the appropriate program location. Practically, the whole this process is in control of several bits of the WDTCON register.
Three bits (PS2, PS1 and PS0), which are in control of the prescaler, determine the most important feature of the watchdog timer- nominal time, i.e. time required to count up a full cycle.
The values contained in the table below are applied only when the 12MHz quartz oscillator is used.
PRESCALER BITS NOMINAL TIME PS2 PS1 PS0 0 0 0 16ms 0 0 1 32ms 0 1 0 64ms 0 1 1 128ms 1
등록된 댓글이 없습니다.