Monday, March 9, 2009

AT89C51 Description

Now let us talk about this popular 8051 chip. It has on chip ROM in the form of flash memory. This is ideal for fast development since flash memory can be erased in seconds compared to the twenty minutes or more needed for the 8751. For this reason the AT89C51 is used in place of the 8751 to eliminate the waiting time needed to erase the chip and thereby speed up the development time. To use the AT89C51 to develop a microcontroller-based system requires a ROM burner that supports flash memory; however, a ROM eraser is not needed. Notice that in flash memory you must erase the entire contents of ROM in order to program it again. This erasing of flash is done by the PROM burner itself . See the following table for its specs

The block diagram shows the internal structure of the microcontroller AT89C51;

Pin description of this MCU can be seen in the following diagram;

Port 0; is a dual-purpose port on pins 32-39 of the 8051 1C. In minimum – component designs, it is used as a general purpose I/O Port. For larger designs with external memory, it becomes a multiplexed address and data bus.

Port 1; is a dedicated I/O port on pins 1-8. The pins, designated as P1.0. P1.1. P1.2 etc. are available for interfacing to external devices as required. No alternate functions are as signed for Port 1 pins; thus they are used solely for interfacing to external devices. Exceptions are the 8032/8052 ICs. Which use P1.0 and P1.1 either as I/O lines or as external in outs to the third timer.

Port 2; (pints 21-28) is a dual – purpose port serving as general purpose I/O, or as the high byte of the address bus for designs with external code memory or more than 256 bytes of external data memory.

Port 3;is a dual – purpose port on pins 10-17. As well as general – purpose I/O, these pins are multifunctional with each having an alternate purpose related to special features of the 8051).

Now coming to the other pin functions.

PSEN;This is an output pin. PSEN stands for “program store enable.” In an 8031-based system in which an external ROM holds the program code, this pin is connected to the OE pin of the ROM.

VCC;Pin 40 provides supply voltage to the chip. The voltage source is +5V.

GND; Pin 20 is the Ground pin.

XTAL1 and XTAL2;The 8051 has an on-chip oscillator but requires an external clock to run it. Most often a quartz crystal oscillator is connected to inputs XTALI (pin 19) and XTAL2 (pin 18). The quartz crystal oscillator connected to XTAL1 AND XTAL2 also needs two capacitors of 30 pF value. One side of each capacitor is connected to the ground as shown in this figure;


EA; The 8051 family members, such as the 8751, 89C51, or DS5000. All come with on-chip ROM to store programs. In such cases, the EA pin is connected to VCC for giving power to save and erase program from the memory.

RST(RESET);The RST input on pin 9 is the master rest for the 8051. When this signal is brought high for a least two machine cycles, the 8051 internal registers are loaded with appropriate values for an orderly system start-up. For normal operation, RST is low. Figure shows permanent connections of Reset Pin.

ALE; (address latch enable) is an output pin a nd is active high. When connecting an 8031 to external memory, port 0 provides both address and data. In other words, the 8031 multiplexes address and data through port 0 to save pins. The ALE pin is used for de-multiplexing the address and data by connecting to the G pin of the 74LS373 chip.Now we will talk about what other things are inside an AT89C51 MCU;

Registers;In the CPU, registers are used to store information temporarily. That information could be a byte of data to be processed, or an address pointing to the data to be fetched. The vast majority of 89C51 register an address pointing to the data to be fetched. The vast majority of 89C51 registers are 8-bit registers. In the 8051 there is only one data type: 8 bits. The 8 bits of a register are shown in the diagram from the MSB (most significant bit) D7 to the LSB (least significant bit) D0. With an 8-bit data type, any data larger than 8 bits must be broken into 8-bit chunks before it is processed. The most widely used registers of the 89C51 are A (accumulator), B, R0, R1, R2, R3, R4, R5, R6, R7, DPTR (data pointer), and PC (program counter). All of the above registers are 8-bits, except DPTR and the program counter. The accumulator, register A, is used for all arithmetic and logic instructions.

All the registers of 89C51 are;

Timers;Both timer 0 and timer 1 are 16 bits wide. Since the 89C51 has an 8-bit architecture, each 16-bit timer is accessed as two separate registers of low byte and high byte. Each timer is discussed separately.

Timer 0 Register;The 16-bit register of time 0 is accesses as low byte and high byte. The low byte register is called TL0 (timer 0 low byte) and the high byte register is referred to as th0 (timer 0 high byte). These registers can be accesse d like any other register, such as A,B, R0, R1, R2 etc. For example, the instruction “TLO= 20” moves the value 500 into TL0, the low byte of timer 0. These registers can also be read like any other register.

Timer 1 Register;Timer 1 is also 16 bits, and its 16- bit register is split into two bytes, referred to as TL1 (timer 1 low byte) and TH1 (timer 1 high byte). These registers are accessible in the same way as the registers of timer 0.

TMOD(Timer Mode) Register;Both timers 0 and 1 uses the same register, called TMOD, to set the various timer operation modes. TMOD is an 8-bit register in which the lower 4 bits are set aside for timer 0 and the upper 4 bits are set aside for timer 1. In each case, the lower 2 bits are used to set the timer mode and the upper 2 bits to specify the operation.

Mode 2 Programming;The following are the characteristics and operations of mode 2.

1-It is an 8-bit timer; therefore, it allows only values of 00 to FFH to be loaded into the timer’s register TH.

2-After TH is loaded with the 8-bit value, the 8051 gives a copy of it to TL. Then the timer must be started. This is done by the instruction “SETB TR0” for timer 0 and “SETB TR1” for timer 1. This is just like mode 1.

3-After the timer is started, it starts to count up by incrementing the TL register. It counts up until it reaches its limit of FFH. When it rolls over from FFH to 00, it sets high the TF (timer flag). If we are using timer 0, TF0 goes high; if we are using timer 1, TF1 is raised.

4-When the TL registers rolls from FFH to 0 and TF is set to 1, TL is reloaded automatically with the original value kept by the TH register. To repeat the process, we must simply clear TF and let it go without any need by the programmer to reload the original value. This makes mode 2 and auto-reload, in contrast with mode 1 in which the programmer has to reload TH and TL.

It must be emphasized that mode 2 is an 8-bit timer. However, it has an auto-reloading capability in auto reload. TH is loaded with the initial count and a copy of it is given to TL. This reloading leaves TH unchanged, still holding a copy of original value. This mode has many applications, including setting the baud rate in serial communication.

SBUF (Serial Buffer) Register; SBUF is an 8-bit register used solely for serial communication in the 89C51. For a byte of data to be transferred via the TxD line, it must be placed in the SBUF register. Similarly, SBUF holds the byte of data when it is received by the 89C51 RxD line. SBUF can be accessed like any other register in the 89C51.The moment a byte is written into SBUF, it is framed with the start and stop bits and transferred serially via the TxD pin. Similarly, when the bits are received serially via RxD, the 89C51 deframes it by eliminating the stop and start bits, making a byte out of the data received, and then placing it in the SBUF. Some baud rates are shown below:

Baud Rate= 9600 TH1(Decimal)=-3 TH1(HEX)=FD
Baud Rate= 4800 TH1(Decimal)=-6 TH1(HEX)=FA
Baud Rate= 2400 TH1(Decimal)=-12 TH1(HEX)=F4
Baud Rate= 1200 TH1(Decimal)=-24 TH1(HEX)=E8


SCON(Serial Control) Register;The SCON register is an 8-bit register used to program the start bit, stop bit, and data bits of data framing, among other things. Following SCON bits are explained; SMO SCON.7 Serial port mode specifier
SM1/ SCON.6= Serial port mode specifier
SM2/ SCON.5= Used for multiprocessor communication (Make it 0)
REN/ SCON.4= Set / cleared by software to enable / disable reception.
TB8/ SCON.3= Not widely used.
RB8/ SCON.2= Not widely used.
T1/ SCON.1= Transmit interrupt flag. Set by hardware at the beginning of the stop
bit in mode1. Must by cleared by software.
R1/ SCON.0= Receive interrupt flag. Set by hardware halfway through the stop bit
time in mode1. Must be cleared by software.

Bit-Addressable RAM; Of the 128-byts internal RAM of the 8051, only 16 bytes of it are bit addressable. The rest must be accessed in byte format. The bit – addressable RAM locations are 20H to 2FH. These 16 bytes provide 128 bits of RAM bit – address ability since 16 x 8 = 128. They are addressed as 0 to 127 (in decimal) or 00 to 7FH. Therefore, the bit addresses 0 to 7 are for the first byte of internal RAM location 20H, and 8 to 0FH are the bit addresses of the second byte, RAM location 21H, and so on. The last byte of 2FH has bit address byte of 2FH has bit addresses of 78H to 7FH. Note that internal RAM locations 20-2FH are both byte-addressable and bit addressable. Notice from figure that bit addresses 00 – 7FH belong to RAM byte addresses 20 – 2FH, and bit addresses 80 – F7H belong to SFR P0, P1 etc.

Please refer to the following documents for detailed insight of AT89C51 MCU;

Data Sheet;

www.atmel.com/atmel/acrobat/doc0265.pdf
http://www.filedropper.com/at89c51datasheet
http://www.filedropper.com/flashmcumemorytorg

Tutorials;

http://www.filedropper.com/best8051tutorial
http://www.filedropper.com/8051tutorial

Hardware Manual;

http://www.filedropper.com/atmel8051microcontrollershardwaremanual



3 comments:

  1. hi, your blog's helped me in my understanding of 8051 ucontrollers. However, your links for the tutorials no longer work. Could you pls upload them again?
    thanks

    ReplyDelete
  2. thank ,,, for help me it's really nice one and full information about the 8051.... it's really super up

    ReplyDelete

Search This Blog