AT89S51 – The 8051 Micro-controller

The AT89S51 is part of the Intel MCS-51 and for many is considered to be the fundamentals for how an Operating System functions. Of course the 8051 micro-controller has all the necessary components which a micro-processor possesses and regularly it poses ROM, RAM, Interrupts, Serial Ports, I/O and Timers. Moreover, the AT89S51 chip uses the Harvard Architecture rather than the standard x86. Therefore it can only execute code fetched from program memory and has no instruction to write into program memory.

A deep explanation on the basics and architecture : Head over to electronicshub

More importantly would be managing interrupts in 8051 micro-controller. It is crucial for any OS since actual tasks carried out must be placed into a halt for some time – it takes that prioritized action – and it must return to where it left off. For example, a slight movement to your cursor mouse triggers a flag to the ISR(Interrupt Service Routine) indicating that any main task must be halted and to carry out the movement of the mouse before returning to the main task.

8051 Interrupts

The 8051 has five interrupt sources. Two EXTERNAL are provided through pins INT0 and INT1, alternate functions of P3.2 and P3.3, respectively. Two INTERNAL are generated by timer 0 and 1 overflow. Serial port on 8051 can generate an interrupt when a byte has been transmitted/received.

InterruptFlagLocation
External 0IE0TCON.1
External 1IE1TCON.3
Timer 0TF0TCON.5
Timer 1TF1TCON.7
Serial Port ReceiveRISCON.0
Serial Port TransmitTISCON.1

Brief notes when an interrupt occurs:

  • The current instruction completes current execution.
  • The PC (Program Counter) is saved and loaded on to stack (address of the next instruction)
  • The address of the ISR for the interrupt is then loaded into PC

Interrupt Vectors

When an interrupt occurs the address of the ISR is loaded into PC. This address is known as Interrupt Vectors.

InterruptFlagVector
System ResetRST0000H
External Interrupt 0IE00003H
Timer 0TF0000BH
External Interrupt 1IE10013H
Timer 1TF1001BH
Serial PortRI or TI0023H

A system reset is a special type of interrupt because it interrupts the running program and loads PC with the vector address 0000H. This address is used in the initialization of the micro-controller (power up). Gist is that reset is similar to powering down and powering up the system.


Enable/Disable Interrupts

On power up or RST all interrupts are disabled. To enable interrupts, set the appropriate bits in the interrupt enable SFR(Special Function Registers).

SymbolBit NumberDescription
EA7Enable/Disable all interrupts.
6
5
ES4Enable/Disable serial port interrupts.
ET13Enable/Disable timer 1 interrupt.
EX12Enable/Disable external 1 interrupt.
ET01Enable/Disable timer 0 interrupt.
EX00Enable/Disable external 0 interrupt.

Running LED Assembly Program

This program uses two external interrupts and is attached to a button/switch. The button acts as the LED shifter, whenever a button is pressed – either the LED shifts to the left or right.