SERIAL COMMUNICATION IN 8051 MICROCONTROLLER

•    The 8051 microcontroller has an internal serial port, which can be operated in four modes.

•    The baud rates for serial communication are programmable using internal Timer-1 of the 8051 controller.

•    The 8051 controller can be used as full duplex serial communication device.

•    A simple schematic for serial communication using 8051 is shown.




•    The system requires a 8x5x microcontroller with internal program memory and RS232 level converter like MAX 232.

•    A quartz crystal and a reset circuit should be connected to controller.

•    The program for serial communication can be stored permanently in internal ROM and so there is no need for external memory. In case if 8031 controller is used then an external EPROM has to be interfaced for program storage.

•    The serial bus is formed by using only three lines TxD, RxD and Vss (Ground).

•    The signals TxD and RxD will have TTL logic levels and they can be converted to standard RS232 logic levels using bidirectional level converter MAX 232.

•    The RS232 level serial port signal can be terminated on a standard 9-pin D-type connector, so that any standard serial device can be connected to 8051 controller for serial communication.

•    The parallel data transfer can be achieved through ports.

•    The parallel input data is received through port-2 and parallel output data is send through port-1.

•    The controller can receive parallel data from an ADC and convert it to serial and transmit via serial port to another serial device. Also the controller can receive a serial data from another serial device via serial port and convert to parallel, and then output through port-1 to a parallel device like DAC.

•    The 8051 controller supports full duplex communication and so the transmission and reception can be performed simultaneously.

SERIAL DATA COMMUNICATION IN 8051 MICROCONTROLLER

•    The fastest way of transmitting data, within a microcomputer is parallel data transfer.

•    For transferring data over long distances, however, parallel data transmission requires too many wires.

•    For long distance transmission, data is usually converted from parallel form to serial form so that it can be sent on a single wire or pair of wires.

•    Serial data received from a distant source is converted to parallel form and it can be easily transferred on the microcomputer buses.

•    The types of communication systems are,

1.    Simplex   2.  Half-duplex    3.  Full-duplex
  •    In simplex communication, data can be transmitted only in one direction, ie. data from sensors to processor. Eg : commercial radio stations.
  •     In half-duplex transmission, data can be transmitted in either direction between two systems, but can occur only in one direction at a time. Eg : two-way radio system, where one user always listens while the other talks because the receiver circuitry is turned off during transmit.
  •   In full duplex, the data can be send and received at the same time. Eg : A normal phone conversation.

·         Serial data can be sent by two ways.
They are,
1.      Synchronous communication    
  
2.      2. Asynchronous communication

  In synchronous transmission, data are transmitted in block at a constant rate.

  The start and end of a block are identified with specific bytes or bit patterns.

  In asynchronous transmission, data is transmitted one by one.

  The beginning of a data character is indicated by the line going low for 1 bit time. This bit is called a start bit.

  The data bits are then sent out on the line one after the other. Note that the least-significant bit is sent out first. Depending on the system, the data word may consist of 5, 6, 7 or 8 bits.

 Following the data bits is a parity bit, which is used to check for errors in received data.

The line is returned high for at least 1-bit time to identify the end of the character. This always-high bit is referred to as a stop bit. Some systems may use 2 stop bits.


    The bit format for asynchronous data transmission is,







•    The term baud rate is used to indicate the rate at which serial data is being transferred.
Baud rate = 1/ time for a bit cell

•    A device such as INTEL 8251A, which can be programmed to do either asynchronous or synchronous communication, is often called USART (Universal Synchronous Asynchronous Receiver Transmitter).

•    A device such as the National 1NS8250, which can only do asynchronous communication, is often referred to as a Universal Asynchronous Receiver Transmitter (UART).

•    For sending serial data over long distances the standard telephone system is a convenient path, because the wiring and connections are already in place.

•    Standard phone lines often referred to as switched lines because any two points can be connected together through a series of switches and have a bandwidth of about 300 to 3000 Hz.

•    But digital signals require very large bandwidth (typically 5 MHz). Therefore, digital signals cannot be sent directly over standard phone lines. So, the digital signals are converted to audio-frequency tones, which are in the frequency range.

•    The device used to do this conversion and to convert transmitted tones back to digital information is called a MODEM.

•    Modems and other equipment used to send serial data over long distances are known as data communication equipment or DCE. The terminals and computers that are sending or receiving the serial data are referred to as data terminal equipment or DTE.

 RS-232C serial data standard:

•    In serial I/O, data can be transmitted as either current or voltage.

•    When data are transmitted as voltage, the commonly used standard is known as RS-232C.

•    This standard, proposes a maximum of 25 signals for the bus used for serial data transfer.

•    The 25 signals of RS-232C are,






•    In practice the first 9-signals are sufficient for most of the serial data transmission scheme and so the RS-232C bus signals are terminated on a D-type 9-pin connector.


•    When all the 25 signals are used, then RS-232C serial bus is terminated on a 25-pin connector.



•    The RS-232C signal levels are not compatible with TTL logic levels. Hence for interfacing TTL devices, level converters or RS-232C line drivers are employed.

•    The popularly used level converters are,

1.    MC1488 - TTL to RS-232C level converter.

2.    MC1489 - RS-232C to TTL level converter.

3.    MAX 232 - Bidirectional level converter.

(Max 232 is equivalent to a combination of MC 1488 and MCI 489 in single IC)

•    The pin diagram of MAX 232 is,



•    For MAX 232 all capacitor should be 1µF.

•    The voltage rating of all capacitor should above 10V.

WHAT HAPPENS WHEN AN INTERRUPT ENDS?

An interrupt ends when the program executes the RETI (Return from Interrupt) instruction. 

When the RETI instruction is executed the following actions are taken by the microcontroller:


•    Two bytes are popped off the stack into the Program Counter to restore normal program execution.


•    Interrupt status is restored to its pre-interrupt status.




WHAT HAPPENS WHEN AN INTERRUPT OCCURS?

When an interrupt is triggered, the following actions are taken automatically by the

•    The current Program Counter is saved on the stack, low-byte first.


•    Interrupts of the same and lower priority are blocked.


•    In the case of Timer and External interrupts, the corresponding interrupt flag is set.


•    Program execution transfers to the corresponding interrupt handler vector address.


•    The Interrupt Handler Routine executes.




ADDRESSING MODES OF 8051/8031 MICROCONTROLLER

--> •    Every instruction of a program has to operate on a data.

•    The method of specifying the data to be operated by the instruction is called addressing.

•    The 8031 has the following types of addressing.

1.    Immediate Addressing

2.    Direct Addressing

3.    Register Addressing

4.    Register Indirect Addressing

5.    Implied Addressing


6.    Relative Addressing

1. IMMEDIATE ADDRESSING :

In immediate addressing mode, an 8/16 bit immediate data / constant is specified in the instruction itself.

MOV A, #6CH  :- Move the immediate data 6CH given in the instruction to A-register.

MOV DPTR, #0100H   :- Load the immediate 16-bit constant given in the instruction in DPTR (Data pointer). This constant will be an address of data memory location.


2. DIRECT ADDRESSING    :

In direct addressing mode, the address of the data is directly specified in the instruction.
The direct address can be the address of an internal data RAM location (00H to 7FH) or address of special function register (80H to FFH).

MOV A, 07 H  :- The address of R7 register of bank-0 is 07. This instruction will move the content of R7 register to A-register (Accumulator).

3.REGISTER ADDRESSING :

In register addressing mode, the instruction will specify the name of register in which data available.

MOV R2,A   :- The content of A-register (accumulator) is moved to register R2.


4. REGISTER INDIRECT ADDRESSING :

In this mode, the instruction specifies the name of the register in which the address of the data is available. The internal data RAM locations (00H to 7FH) can be addressed indirectly through registers R1 and R0. The external RAM can be addressed indirectly through DPTR.

MOV A, @R0  :- The internal RAM Location R0 holds the address of data. The content of RAM location addressed by R0 is moved to A-register (Accumulator).

5. IMPLIED ADDRESSING :

In implied addressing mode, the instruction itself specifies the data to be operated by the instruction.
CPL C   :- Complement carry flag.


6. RELATIVE ADDRESSING:

In relative addressing mode, the instruction specifies the address relative to program counter.
The instruction will carry an offset whose range is -l2810 to +l2710 .
The offset is added to PC to generate 16-bit physical address.

JC Offset :- If carry is one then the program control jump to an address obtained by adding the content of program counter and offset value in the instruction.

BOOLEAN INSTRUCTIONS OF 8051/8031 MICROCONTROLLER

•    The Boolean variable instructions operate on a particular bit of a data.

•    These instructions perform clear, complement or move a particular bit of bit addressable RAM/SFR or carry flag.

•    If a particular bit is set or cleared then this instruction will transfer the PC address to new address.

•    The Boolean instructions are CLR, SETB, CPL, ANL, ORL, MOV, JC and JNC.



BRANCHING INSTRUCTIONS FOR 8051/8031 MICROCONTROLLER

•    The branching instructions will modify the content of PC so that the program execution sequence is changed to new address.

•    There are two types of branching instructions like condition and unconditional instructions.

•    In conditional branching the content of PC is changed only if the condition specified is true.

•    In unconditional branching the PC is always modified.

•    The program branching instructions are ACALL, LCALL, RET, AJMP, LJMP, SJMP, JMP, JZ, JNZ, CJNE, DJNZ and NOP.


LOGICAL INSTRUCTIONS FOR 8051/8031 MICROCONTROLLER

•    The logical instructions are used to perform logical AND, OR, Exclusive-OR, Complement and rotate left and right.

•    The various mnemonics used for logical instructions are ANL, ORL, XRL, CLR, CPL, RL, RLC, RR and RRC AND SWAP.

•    Only the rotate through the carry instruction will affect the flag.

•    In most of the result of logical instruction is stored in accumulator and in some instructions the result is stored in RAM/SFR.


ARITHMETIC INSTRUCTIONS IN 8051/8031 MICROCONTROLLER


•    The arithmetic instructions are used to performing addition, subtraction, multiplication, division, and increment and decrement operation on binary data.

•    The mnemonic used in arithmetic instructions are ADD, ADDC, SUBB, INC, DEC, MUL, DIV and DA.

•    The result of most of the arithmetic operation is stored in accumulator except a few decrement and increment operations.

•    The arithmetic instructions except increment and decrement instructions modify the flags of 8031/8051

 



DATA TRANSFER INSTRUCTIONS IN 8051/8031 MICROCONTROLLER

Data transfer between registers and memory locations are done by data transfer instructions.
The various mnemonics used for data transfer instructions are MOV, MOVC, MOVX, PUSH, POP, XCH and XCHD, and they perform any one of the following operations.

•    Copy the content of a SFR to internal memory or vice-versa.

•    Load an immediate operand to SFR/internal memory.

•    Exchange the content of SFR internal memory with accumulator.

•    Copy the content of program memory to accumulator.

•    Copy the content of data memory to accumulator or vice-versa.


INSTRUCTION SET - ASSEMBLY LANGUAGE PROGRAMMING FOR 8051/8031 MICROCONTROLLER

The 8031/8051 instructions can be classified into the following five groups.




3.Logical instructions

4.Branching instructions

5.Boolean instructions

INPUT/OUTPUT PINS, PORTS & CIRCUITS OF 8051/8031 MICROCONTROLLER

•    The 8051 has 32 I/O pins configured as four eight-bit parallel ports (P0, P1, P2, and P3).

•    All four ports are bi-directional.

•    Each port consists of a latch, an output driver, and an input buffer.

•    The output drives of Ports 0 and 2 and the input buffers of Port 0, are used in access to external memory.

•    Port 0 outputs the low order byte of the external memory address, time multiplexed with the data being written or read.

•    Port 2 outputs the high order byte of the external memory address when the address is 16 bits wide. Otherwise Port 2 gives the contents of special function register.

•    All port pins of Port 3 are multifunctional.

•    They have special functions including two external interrupts, two counter inputs, two special data lines and two timing control strobes.

P3-Alternate Special Function of port3

I/O Configuration:




Port 0 bit

Port 0 bit

Port 2 bit

Port 3 bit

•    The bit latch is nothing but the one bit in the port’s SFR. It is represented as a D flip-flop.

•    “Write to latch” acts as clock input for D flip-flop. The data from the internal bus is clock-in in response to a “write to latch” signal from the CPU. The Q (active low) output or Q output after inversion from D flip-flop is connected at the gate input of the drive FET.

•    The On and OFF state of the drive FET due to the data available at the output of latch decides the status of the output pin.

•     It is possible to read Q output of latch by activating “read latch” signal from the CPU.

•    The actual port status can he read by activating “read pin” signal.

•    For Port 0 and Port 2 drivers are switchable to internal ADDR/DATA and ADDR bus, respectively, by internal CONTROL signal.

•    The switching is required to access external memory. During external memory accesses, the P2 SFR remains unchanged, but P0 SFR gets 1s written to it.

•    Port 3 has multifunction pins. Therefore, each pin of Port 3 can be programmed to use as I/O or as one of the alternate function. This is achieved by another control input, “Alternate output function’.

•    When latch bit of Port 3 contains 1, the output level is controlled by control input, “alternate output function.”

•    The port pin can be configured as an input by writing 1 in the latch bit of the corresponding pin. It turns OFF the output driver FET. Then for, Ports 1,2 and 3, the pin is pulled high by the internal pull-up, but can be pulled low by an external source. There is no internal pull-up for port 0. Therefore, its output pin floats when 1 is written in the latch bit, and pin can be used as a high impedance input.

•     The port 0 is said to be “true bidirectional”, because when configured as an input it floats.

•    The output of Ports 1, 2 and 3 are pulled high with pull-up registers, when configured as an input. Thus they are sometimes called “quasi bidirectional” ports.

MEMORY INTERFACING OF Of 8051/8031 MICROCONTROLLER

Q.) An 8031 microcontroller based system requires 8kb program memory and 8kb external data memory. Also it requires 8279 for keyboard/display interface and 8255 for additional I/O ports. Develop a schematic to interface the memories, 8279 and 8255 to 8031 microcontroller, and allocate addresses to all the devices.

•    The 8kb program memory can be provided by using one number of 8kb EPROM 2764. The 8kb EPROM require 13 address lines and so the address lines A0 – A12 are connected to EPROM address pins to select its internal locations.

•    The remaining address lines A13, A14 and A15 are logically ORed and used as chip select signal for EPROM.

•    The signal PSEN(low) is used as read control signal for EPROM and so the EPROM can be accessed only as program memory. Here the EPROM is mapped in the first 8kb of program memory address space with address range 0000H to 1FFFH. (Here the remaining 56kb program memory address space is not utilized).

•    The 8031 provide a separate 64kb external data memory address space.

•    The RAM memory, 8279 and 8255 can be interfaced to 8031 as data memory

•    The 8kb RAM can be provided by using one number of 8kb RAM 6264. The 8kb RAM requires 13 address lines and so the address lines A0 – A12 are connected to address pins of RAM to select its internal location.

•    The 8255 require two address lines to select its internal devices port-A, port-B, port-C and control register. Hence the address lines A0 and A1 of controller are connected to A0 and A1 of 8255 respectively.

•    The 8279 require one address line to select its data register and control register. Hence the address line A0 of 8031 is connected to A0 of 8279.

•    A 2-to-4 decoder is employed in the system to generate the chip select signals required for the RAM, 8255 and 8279. The address lines A13 and A14 are connected to input of decoder to generate four chip select signals. The address line A15 is used as logic low chip enable for decoder.

•    In 8031 based system, the pin of 8031 is permanently grounded.

•    The 8031 provides separate read and write control signals RD(low) and WR(low) for reading and writing with devices interfaced as data memory.

•    The 8031 has a separate 256 bytes internal data memory address space allotted to internal RAM and SFR.




Address allocation for interfacing of 8031

Q.) An 8051 microcontroller based systems require 32 kb program memory and 16kb data memory. The system should also utilize the internal 4kb RAM. Also the system should include a keyboard/display controller 8279 and an 8255 I/O port device. Draw the interface diagram and allocate addresses to memory and I/O devices.

•    The 8051 has 4kb internal ROM which is mapped in the beginning of program memory address space with address in the range 0000H to 0FFFH.

•    Hence for a total requirement of 32kb, we have to provide 28kb external memory. Therefore one number 32kb EPROM 27256 can be interfaced to microcontroller in which the first 4kb will not be accessed by the controller if pin EA(low) is tied to Vcc or +5V.

•    The 32kb EPROM require 15 address lines and so the address lines A0 to A14 are connected to the address pins of EPROM to select its internal locations.

•    The address line A15 is used as chip s signal.

•    The EPROM is selected for program memory addresses when A0 = 0.

•    The signal PSEN(low) is used as read control signal for EPROM and so the EPROM can be
             accessed only as program memory.   

•    The 16kb RAM memory can be implemented by using two numbers of 8kb RAM 6264.

•    The RAM memories, 8255 and 8279 can be interfaced to 8051 controllers as data memory.

•    The 8kb RAM require 13 address lines and so the address lines A0 – A12 are connected to address pins of RAM to select its internal locations.

•    The address line A0 and A1 are connected to 8255 and the address line A0 is connected to 8279 to select their internal devices.

•    A 2-to-4 decoder is employed in the system to generate the chip select signals required for RAM, 8255 and 8279. The address lines A13 and A14 are connected to input of decoder to generate four chip select signals. The address line A15 is used as logic low chip enable for decoder.

•    Since the internal ROM is used in the system, the pin EA(low) should be tied to Vcc or +5V.

•    The 8051 provides separate read and write control signals RD(low) and WR(low) for reading and writing with devices interfaced as data memory.

•    The 8051 has a separate 256 bytes internal data memory address space allotted to internal RAM and SFR.








Registers Of 8051/8031 Microcontroller

 Timer Control Register (TCON):

•    The TCON register consists of timer overflow flags, timer run control bits, external interrupt flags and external interrupt type control bits.
•    The format of TCON register is,



•    When clock signal is applied, after reaching maximum value (i.e., the content of counter is all 1’s), the content of counter will become zero (i.e., all 0s). This condition is called timer overflow and this is also the end of timing maintain by using the timer.

•    The TCON register has a 1-bit flag, TF for each timer to indicate the timer overflow or end of timing.

•    Whenever the timer/counter overflows, the TF flag is set to one.

•    The TF flag is also used as an interrupt signal to initiate the execution of a subroutine. When the controller executes a subroutine, the TF flag is cleared.

•    The TR bit is used to start/stop the timer/counter. When TR bit is set to one, the timer/ counter will start counting and continue the counting as long as TR bit is one. The timer/counter will stop counting when TR bit is cleared to zero.

•    When a valid external interrupt signal is detected the IE flag is set to one. When the controller accepts the external interrupt and start processing it, the IE flag is cleared to zero.

•    The IT = 1, when it recognize falling edge triggered external interrupt and IT = 0, when it recognize logic low level external interrupt.


Interrupt Enable Register (IE):


•    The IE register is used to enable/disable the interrupts of 8051.

•    The interrupts are recognized by the controller only if they are enabled.

•    The format of IE register is,






•    If EA = 0, then it disable all the five interrupts of 8051.

•    If EA = 1, then it enable the interrupts. The EA bit is also called global enable.



Interrupt Priority Register (IP):


•    The 8051 has five interrupts.

•    The normal priority of these interrupts from highest to lowest are external interrupt-0, Timer-0 interrupt, External interrupt- 1, Timer-1 interrupt and serial Port interrupt.

•    The IP register can be programmed to make the priority of any of the interrupt as highest.

•    When the priority bit of a particular bit is programmed as one then its priority will be highest.

•    The format of IP register is,



Serial Port Control Register (SCON) Of 8051/8031 Microcontroller

•    The format of SCON register is shown.


•    Mode 0:

o    In this mode the serial port function as half duplex serial port with fixed baud rate.

o    The 8- bit serial data is received and transmitted through RxD pin and the controller output the shift clock through TxD pin during reception and transmission.

o    The baud rate is fixed at 1 / 12 of the oscillator frequency.

•    Mode 1:

o    In this mode the serial port function as full duplex serial port with variable baud rate.

o    In this mode one data consists of 10 bits, which includes one start bit, eight data bit and one stop bit. During reception the stop bit is stored as RB8 in SCON register.

o    Baud rate in mode-1 depends on the value of SMOD bit in PCON register and the timer-1overflow rate.

•    Mode 2:

o    In this mode the serial port function as full duplex serial port with a baud rate of either 1/32 or 1/64 of the oscillator frequency.

o    In this mode one data consists of 11 bits which includes one start bit, eight data bit, a programmable 9th data bit and one stop bit.

o    During transmission the TB8 of SCON register is added as 9th data bit and during reception the 9th data bit is stored as RB8 in SCON register.

o    The baud rate depends on the value of SMOD bit in PCON register.

•    Mode 3:

o    The mode-3 is same as mode-2, except the baud rate.

o     In mode-3, the baud rate is variable. The baud rate depends on the value of SMOD bit in PCON register and the timer- 1 overflow rate.

•       The serial mode bit-2 (SM2) has no effect in mode-0 and when programmed for mode-0, the SM2 should be equal to zero.


•    In mode-1, SM2 is used to check a valid stop bit during reception. In mode-1, if SM2 = 1, then receive interrupt (RI) is activated only when a valid stop bit is received.

•       In mode-2 and mode-3 the SM2 bit is used to enable multiprocessor communication.

•       In multiprocessor communication the serial port of a number of microcontrollers can be connected to a common serial bus. One controller will act as a master and all other controller will act as slave.

•       A unique 8-bit address is assigned to each slave and the SM2 bit in all the slaves is set to 1.

•       When SM2 bit is one, the slaves will consider the received byte as address and when SM2 bit is zero the slaves will consider the received byte as data.

•       For communication with a slave the master will first send as address byte and then a data byte.

•    The master initiates communication with a slave by sending the address of the slave on the bus. All the slaves will receive the address byte. Since SM2 = 1 initially in all the slaves, the received byte will be considered as address and the slaves will verify whether the received address matches with assigned address. The slave whose assigned address matches with received address will clear its SM2 bit. Now SM2 bit of only one of the slave will be zero.

•    Next the master will send a data byte which is also received by all the slave, but the data byte is accepted by the slave whose SM2 = 0 and so the receive interrupt is activated only in one of the slave whose SM2 = 0.

•    After reading the received data from SBUF register, the SM2 bit of the slave should be set to one again to receive next data.

•    The REN bit of SCON register can be used to enable or disable the serial reception. When REN = 1, the serial reception is enabled and when REN = 0, the serial reception is disabled.

•    The bits TI and RI of SCON register are transmitting interrupt flag and receive interrupt flag respectively.

•    The controller will set the TI bit during the transmission of stop bit of a data character in mode 1 to 3 and during the transmission 0 bit of a data character in mode-0.

•    The controller will set the RI bit during the reception of stop bit of a data character in mode 1 to 3 and during the reception of 8th bit of a data character in mode- 0.

Timer Mode Control Register (TMOD) Of 8051/8031 Microcontroller

•    The TMOD register is used to select the operating mode and the timer/counter operation of the timers.

•     The format of TMOD register is,




•    The lower four bits of TMOD register is used to control timer-0 and the upper four bits are used to control timer-1.

•    The two timers can be independently program to operate in various modes.

•    The TMOD register has two separate two bit field M0 and Ml to program the operating mode of timers. The operating modes of timers are mode-0, mode-1, mode-2 and mode-3. In all these operating modes the oscillator clock is divided by 12 and applied as input clock to timer.

MODE-0
o    In mode-0 the timer register is configured as 13-bit register.

o    For timer-1 the 8 bits of TH1 and lower 5 bits of TL1 are used to form 13-bit register.

o    For timer-0 the 8-bit of TH0 and lower 5 bits of TL0 are used to form 13-bit register.

o    The upper three bits of TL registers are ignored.

o     For every clock input to timer the 13-bit timer register is incremented by one When the timer count rolls over from all 1’s to all 0’s, (i.e., 1 1111 1111 1111 to 0 0000 0000 0000) the timer interrupt flag in TCON register is set to one.

Mode-1

o    The mode-1 is same as mode-0 except the size of the timer register. In mode-1 the TH and TL registers are cascaded to form 16-bit timer register.

MODE-2

o    In mode-2, the timers function as 8-bit timer with automatic reload feature. The TL register will function as 8-bit timer count register and the TH register will hold an initial count value.

o    When the timer is started, the initial value in TH is loaded to TL and for each clock input to timer the 8-bit timer count register is incremented by one.

o    When the timer count rolls over from all 1’s to all 0’s (i.e., 1111 1111 to 0000 0000), the timer interrupt flag in TCON register is set to one and the content of TH register is reloaded in TL register and the count process starts again from this initial value.

Mode-3

o    In mode-3, the timer-0 is configured as two separate 8-bit timers and the timer-1 is stopped.

o    In mode-3 the TL0 will function as 8-bit timer controlled by standard timer-0 control bits and the TH0 will function as 8-bit timer controlled by timer-1 control bits.

o    While timer-0 is programmed in mode-3, the timer-0 can be programmed in mode-0, 1 or 2 and can be used for an application that does not require an interrupt.

o    The C/T(Low) bit of TMOD register is used to program the counter or timer operation of the timer. When C/T bit is set to one, the timer will function as event counter. The C/T(Low) bit is programmed to zero for timer operation.

o    The timer will run only if clock input is allowed.

o    When GATE = 1, the clock input to timer is allowed only if the signal at pin is high and when GATE =0 the signal at INT (low) pin is ignored.

SPECIAL FUNCTION REGISTERS (SFR) OF 8051/8031 MICROCONTROLLER

•    The SFRs include 21 internal registers listed in table.
•    Each register of SFR has one byte address. Some of the registers are both byte and bit addressable (The registers whose address ends with 0H or 8H are bit addressable).
•    The 8031/8051 has a separate 256 bytes internal RAM accessed by using 8-bit address.
•    In this 256 bytes address space, first 128 byte addresses are allotted to internal RAM (00H to 7FH) and the next 128 bytes are allotted to SFR (80H to FFH).
•    Using MOV instructions SFR can access.



A and B Registers:

•    The A and B registers are called CPU registers.

•    They are used to hold the data for most of the CPU (ALU) operations.

•    The size of A and B registers are 8-bit.

•    In ALU operation, the result is stored in A-register and so it is also known as accumulator.


Data Pointer (DPTR):

•    The data pointer is a 16-bit register used to hold the 16-bit address of data memory.

•    This can also be used as two numbers of 8-bit data pointer namely DPH and DPL.

•    The 8-bit data pointers are used for accessing internal RAM and SFR.

•    The 16-bit data pointer is used for accessing external data memory.

•    The contents of data pointer are programmable using instructions.

Program Status Word (PSW):


•    The PSW is also known as flag register.

•    The flags are useful for the programmer to test the condition of the result and make decisions.

•    The format of PSW of 8031/8051 microcontroller is shown in fig.






•    The PSW consists of four math flags and two register bank select bits. The math flags are Carry, Auxiliary Carry, and Overflow and Parity flags.

•    The flags are altered after arithmetic and logical operations depending on the result.

•    The carry flag is set when the result has a carry.

•    When there is a carry from lower nibble to upper nibble the auxiliary carry is set.

•    When the result has even parity, the parity flag is set.

•    In certain mathematical operations if the size of the result exceeds the size of destination register then overflow flag is set.

•    The register bank select bits RS1 and RS0 are used to select any one of the four register banks of the internal RAM. At any one time the microcontroller can work with (or access) only one register bank selected by these bits.

•    The bank select bits are programmable and after reset the controller defaults to bank-0. The selection of register bank using the RS1 and RS0 bits are listed in table.


Stack Pointer (SP):
•    The stack pointer always holds the 8-bit address of the top of stack.
•    The programmer can reserve any portion of RAM as stack.
•    After a reset the stack pointer is initialized to 07H.
•    The stack can be accessed using PUSH and POP instructions.
•    During PUSH operation the stack pointer is automatically incremented by one and during POP operation the stack pointer is automatically decremented by one.

Power Control Register (PCON):
•    The PCON register is used for power control and baud rate selection.
•    It also consists of general-purpose user flags. The format of PCON is shown in figure.
•    The controller can be driven to idle mode by setting IDL bit of PCON register.
•    In idle mode the clock signal is stopped to CPU(ALU), but the clock signal is supplied to interrupt, timer and serial port blocks.
•    The idle mode can be terminated either by an interrupt or by hardware reset.
•    The power 12V can be reduced to 2V by setting PD bit.
•    During power down mode the internal oscillator is stopped.


•    The power down mode can be terminated only by a hardware reset.

•    The SMOD bit is used to decide the baud rate in serial port operating modes 1, 2 or 3.

•    In mode 2,

if SMOD =0, then the baud rate is 1/64 of oscillator frequency

if SMOD = 1, then the baud rate is 1/32 of oscillator frequency.

•    In mode 1 and 3, the baud rate depends on SMOD and timer-1 overflow rate.

The baud rate in mode 1 or 3 = (2SMOD/32) x (Timer-1 Overflow Rate).

•    The programmer, to indicate the status of certain events during program execution can use the general-purpose flag bits GF1 and GF.

Serial Data Buffer Register (SBUF):

•    The SBUF register is used to hold the parallel data during transmission and reception.

•    During serial reception, the serial data is received via RxD pin and converted to parallel data and stored in receive buffer.

•    During serial transmission, the parallel data is stored in transmit buffer and then converted to serial data to transmit via TxD pin.

•    The transmit and receive buffers are assigned the same internal address 99H but transmit buffer can be accessed only for write operation and receive buffer can be accessed only for read operation.

•    When data is written to SBUF if goes to transmit buffer and when data is read from SBUF it comes from receive buffer.

Data Memory Of 8031/8051 Microcontroller

•    In 8031/8051 microcontroller the entire 64kb data memory space is external.

•    The address range of external data memory is 0000H to FFFFH.

•    Apart from external data memory the 8031/8051 has 256 bytes of internal data memory in which the first 128 bytes are called RAM and next 128 byte is called SFR.

•    The address range of SFRs and internal RAM are 00H to FFH

•    The “MOVX” instruction is used to access the external data memory.

•    The internal data memory space for 8051 is divided into three blocks: Lower 128bytes, Upper 128 bytes and SFRs.

•    The upper addresses and SFRs occupy the same block of address space, 80H through FFH, and they are physically separate entities.

•    The upper address is accessible by indirect addressing only and SFRS are accessible by direct addressing only.

•    Lower address space can be accessed either by direct addressing or by indirect addressing.


The 8051 Data Memory



•    The circuit diagram for connecting external data memory is shown. The multiplexed address / data bus is provided by port 0.

•    Port 2 gives the higher order address bus.

•     The RD (Low) and WR (Low) signals from 8051 selects the memory read and memory write operation, respectively.

Accessing External Data Memory



ARCHITECTURE OF 8031/8051 MICROCONTROLLER

ARCHITECTURE OF 8031/8051

CPU - Central processing Unit:

1. ALU:

•    It performs the arithmetic operations such as addition, subtraction, multiplication and division.

•    The unit can perform logical operations such as AND, OR; and Exclusive-OR, as well as rotate, clear, and complement.

•    The ALU can also manipulate one bit as well as eight-bit data types.

•    Individual bits may be set, cleared, complemented, tested, and used in logic computation.
   
2. Accumulator:

•    It is an 8-bit register.

•    It holds a data and receives the result of the arithmetic instructions.

3. B register: 

  An 8-bit general-purpose register.

4. Program Status Word:

•    Many instructions implicitly or explicitly affect (or are affected by) several status flags, which are grouped together to form the Program Status Word.

•    It also used to select the memory bank.


5. Stack Pointer (SP):

•    The stack pointer register is 8 bit wide.

•    It is incremented before data is stored during PUSH and CALL instructions.

•    After reset the value of SP is 07H.

6. Data Pointer (DPTR):

•    The data pointer is a 16-bit register used to hold the 16-bit address of data memory.

•    This can also be used as two numbers of 8-bit data pointer namely DPH and DPL.

•    The 8-bit data pointers are used for accessing internal RAM and SFR.

•    The 16-bit data pointer is used for accessing external data memory.

•    The contents of data pointer are programmable using instructions.

7. Program Counter (PC):

•    It is a 16 bit register.

•    PC is used, as address pointer to access program instructions and it is automatically incremented after every byte of instruction fetch.

I/O Devices:

•    The 8051 has four numbers of 8-bit ports namely port-0, port- 1, port-2 and port-3.

•    Each port has a latch and driver (or buffer).

•    When external memory is employed the port-0 lines will function as multiplexed low byte address/data lines and port-2 lines will function as high byte address lines.

•    Also the port pins P3.7 and P3.6 are used to output read and write control signals respectively.

•    The port-1 is dedicated I/O port and does not have any alternate function.

•    The ports are also mapped as internal memory in the controller and so they can be addressed as memory locations for 8-bit operation.

Instruction Register (IR) & timing and control unit:

•    The 8051 has 8-bit ALU, which performs arithmetic and logical operations on binary data.

•    The A and B registers are used to hold the input data and the result of ALU operation.

•    The controller will fetch the instructions one by one, starting from the address stored in PC and store in IR, which decodes the instructions and give information to timing and control unit.

•    Using the information supplied by the IR unit the control signals necessary for internal and external operations are generated by the timing and control unit.

Timer/Counter & Serial port:

•    The 8031/8051 has two 16-bit programmable timer/counter namely timer-1 and timer 0.

•    In the counter mode of operation they can count the number of high to low transitions of the signal applied to the timer pins.

•    In timer mode of operation they can be independently programmed to work in any one of the four operation modes. They are called mode-0, mode-1, mode-2 and mode-3.

•    In mode-0 the serial port can either receive or transmit at fixed baud rate.

•    In mode-2 it can simultaneously transmit and receive at any one of the two selectable baud rate.

•    In mode-1 and mode-3 it can work as full duplex serial port with variable baud rate, which is programmed using timer-1.

 Memory Organization:

•    Since the size of address pointers are 16-bit they can address up to 216 = 64kb memory locations.

•    A microcontroller based system requires both EPROM and RAM. The EPROM is required for permanent program and permanent data storage. The RAM is required for temporary data storage and stack. The 8031/8051 has 64kb program memory address space and 64kb data memory address space.

•    The microcontroller can only read from program memory such as ROM/EPROM/ EEPROM and the signal PSEN (Low) is used as read control for reading program memory.

•    The microcontroller can read and write with data memory RAM. It has separate read control signal RD(Low), and write control signal WR(Low) for reading and writing with data memory respectively.

•    In 8031/8051 based system only memory mapped I/O is possible.
  

Program Memory:

•    In 8031 there is no internal ROM/EPROM and so the entire 64 kb program memory space in the range 0000H to FFFFH is external. Therefore in 8031 based systems the pin EA(Low) is always tied low or grounded (0V).

•    The 8051 has 4kb internal ROM which can be mapped to first 4kb address space of program memory.

•    If EA(Low) pin is tied high or tied to VCC (+5V), then the internal 4kb ROM be mapped as program memory in the address range 0000H to 0FFFH and the external program memory 60kb will have the address range l000H to FFFFH.

•    If EA(Low) pin is tied low or grounded (0V), then the internal ROM is ignored or cannot be accessed. The entire 64 kb program memory address space is external with address range 0000H to FFFFH.


The 8051 Program Memory





•    The PSEN (Low) signal is used to activate output enable signal to access the external ROM/EPROM, as shown.

Accessing External Program Memory

•    The port 0 is used as a multiplexed address/bus. It gives lower order 8-bit address in the initial T-cycle and later it is used as a data bus.

•    The 8-bit address is latched using external latch and ALE signal generated by 8051.

•    The port 2 provides the higher order 8-bit address.

•    The lower part of program memory stores the vector addresses for various interrupt service routines.

•    Each interrupt is assigned with a fixed location in program memory.

Interrupt/Vector location


Labels

PROJECTS 8086 PIN CONFIGURATION 80X86 PROCESSORS TRANSDUCERS 8086 – ARCHITECTURE Hall-Effect Transducers INTEL 8085 OPTICAL MATERIALS BIPOLAR TRANSISTORS INTEL 8255 Optoelectronic Devices Thermistors thevenin's theorem MAXIMUM MODE CONFIGURATION OF 8086 SYSTEM ASSEMBLY LANGUAGE PROGRAMME OF 80X86 PROCESSORS POWER PLANT ENGINEERING PRIME MOVERS 8279 with 8085 MINIMUM MODE CONFIGURATION OF 8086 SYSTEM MISCELLANEOUS DEVICES MODERN ENGINEERING MATERIALS 8085 Processor- Q and A-1 BASIC CONCEPTS OF FLUID MECHANICS OSCILLATORS 8085 Processor- Q and A-2 Features of 8086 PUMPS AND TURBINES 8031/8051 MICROCONTROLLER Chemfet Transducers DIODES FIRST LAW OF THERMODYNAMICS METHOD OF STATEMENTS 8279 with 8086 HIGH VOLTAGE ENGINEERING OVERVOLATGES AND INSULATION COORDINATION Thermocouples 8251A to 8086 ARCHITECTURE OF 8031/8051 Angle-Beam Transducers DATA TRANSFER INSTRUCTIONS IN 8051/8031 INSTRUCTION SET FOR 8051/8031 INTEL 8279 KEYBOARD AND DISPLAY INTERFACES USING 8279 LOGICAL INSTRUCTIONS FOR 8051/8031 Photonic Transducers TECHNOLOGICAL TIPS THREE POINT STARTER 8257 with 8085 ARITHMETIC INSTRUCTIONS IN 8051/8031 LIGHTNING PHENOMENA Photoelectric Detectors Physical Strain Gage Transducers 8259 PROCESSOR APPLICATIONS OF HALL EFFECT BRANCHING INSTRUCTIONS FOR 8051/8031 CPU OF 8031/8051 Capacitive Transducers DECODER Electromagnetic Transducer Hall voltage INTEL 8051 MICROCONTROLLER INTEL 8251A Insulation Resistance Test PINS AND SIGNALS OF 8031/8051 Physical Transducers Resistive Transducer STARTERS Thermocouple Vacuum Gages USART-INTEL 8251A APPLICATIONs OF 8085 MICROPROCESSOR CAPACITANCE Data Transfer Instructions In 8086 Processors EARTH FAULT RELAY ELECTRIC MOTORS ELECTRICAL AND ELECTRONIC INSTRUMENTS ELECTRICAL BREAKDOWN IN GASES FIELD EFFECT TRANSISTOR (FET) INTEL 8257 IONIZATION AND DECAY PROCESSES Inductive Transducers Microprocessor and Microcontroller OVER CURRENT RELAY OVER CURRENT RELAY TESTING METHODS PhotoConductive Detectors PhotoVoltaic Detectors Registers Of 8051/8031 Microcontroller Testing Methods ADC INTERFACE AMPLIFIERS APPLICATIONS OF 8259 EARTH ELECTRODE RESISTANCE MEASUREMENT TESTING METHODS EARTH FAULT RELAY TESTING METHODS Electricity Ferrodynamic Wattmeter Fiber-Optic Transducers IC TESTER IC TESTER part-2 INTERRUPTS Intravascular imaging transducer LIGHTNING ARRESTERS MEASUREMENT SYSTEM Mechanical imaging transducers Mesh Current-2 Millman's Theorem NEGATIVE FEEDBACK Norton's Polarity Test Potentiometric transducers Ratio Test SERIAL DATA COMMUNICATION SFR OF 8051/8031 SOLIDS AND LIQUIDS Speed Control System 8085 Stepper Motor Control System Winding Resistance Test 20 MVA 6-digits 6-digits 7-segment LEDs 7-segment A-to-D A/D ADC ADVANTAGES OF CORONA ALTERNATOR BY POTIER & ASA METHOD ANALOG TO DIGITAL CONVERTER AUXILIARY TRANSFORMER AUXILIARY TRANSFORMER TESTING AUXILIARY TRANSFORMER TESTING METHODS Analog Devices A–D BERNOULLI’S PRINCIPLE BUS BAR BUS BAR TESTING Basic measuring circuits Bernoulli's Equation Bit Manipulation Instruction Buchholz relay test CORONA POWER LOSS CURRENT TRANSFORMER CURRENT TRANSFORMER TESTING Contact resistance test Current to voltage converter DAC INTERFACE DESCRIBE MULTIPLY-EXCITED Digital Storage Oscilloscope Display Driver Circuit E PROMER ELPLUS NT-111 EPROM AND STATIC RAM EXCITED MAGNETIC FIELD Electrical Machines II- Exp NO.1 Energy Meters FACTORS AFFECTING CORONA FLIP FLOPS Fluid Dynamics and Bernoulli's Equation Fluorescence Chemical Transducers Foil Strain Gages HALL EFFECT HIGH VOLTAGE ENGG HV test HYSTERESIS MOTOR Hall co-efficient Hall voltage and Hall Co-efficient High Voltage Insulator Coating Hot-wire anemometer How to Read a Capacitor? IC TESTER part-1 INSTRUMENT TRANSFORMERS Importance of Hall Effect Insulation resistance check Insulator Coating Knee point Test LEDs LEDs Display Driver LEDs Display Driver Circuit LM35 LOGIC CONTROLLER LPT LPT PORT LPT PORT EXPANDER LPT PORT LPT PORT EXTENDER Life Gone? MAGNETIC FIELD MAGNETIC FIELD SYSTEMS METHOD OF STATEMENT FOR TRANSFORMER STABILITY TEST METHODS OF REDUCING CORONA EFFECT MULTIPLY-EXCITED MULTIPLY-EXCITED MAGNETIC FIELD SYSTEMS Mesh Current Mesh Current-1 Moving Iron Instruments Multiplexing Network Theorems Node Voltage Method On-No Load And On Load Condition PLC PORT EXTENDER POTIER & ASA METHOD POWER TRANSFORMER POWER TRANSFORMER TESTING POWER TRANSFORMER TESTING METHODS PROGRAMMABLE LOGIC PROGRAMMABLE LOGIC CONTROLLER Parallel Port EXPANDER Paschen's law Piezoelectric Wave-Propagation Transducers Potential Transformer RADIO INTERFERENCE RECTIFIERS REGULATION OF ALTERNATOR REGULATION OF THREE PHASE ALTERNATOR Read a Capacitor SINGLY-EXCITED SOLIDS AND LIQUIDS Classical gas laws Secondary effects Semiconductor strain gages Speaker Driver Strain Gages Streamer theory Superposition Superposition theorem Swinburne’s Test TMOD TRANSFORMER TESTING METHODS Tape Recorder Three-Phase Wattmeter Transformer Tap Changer Transformer Testing Vector group test Virus Activity Voltage Insulator Coating Voltage To Frequency Converter Voltage to current converter What is analog-to-digital conversion Windows work for Nokia capacitor labels excitation current test magnetic balance voltage to frequency converter wiki electronic frequency converter testing voltage with a multimeter 50 hz voltages voltmeter

Search More Posts

Followers