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.
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.
|Serial Port Receive||RI||SCON.0|
|Serial Port Transmit||TI||SCON.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
When an interrupt occurs the address of the ISR is loaded into PC. This address is known as Interrupt Vectors.
|External Interrupt 0||IE0||0003H|
|External Interrupt 1||IE1||0013H|
|Serial Port||RI or TI||0023H|
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.
On power up or RST all interrupts are disabled. To enable interrupts, set the appropriate bits in the interrupt enable SFR(Special Function Registers).
|EA||7||Enable/Disable all interrupts.|
|ES||4||Enable/Disable serial port interrupts.|
|ET1||3||Enable/Disable timer 1 interrupt.|
|EX1||2||Enable/Disable external 1 interrupt.|
|ET0||1||Enable/Disable timer 0 interrupt.|
|EX0||0||Enable/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.
ORG 000H ;starting address
SJMP LABEL ;jumps to the LABEL
ORG 003H ; starting address for the ISR(INT0)
ACALL ISRL ; calls the ISR (interrupt service routine)
RETI ; returns from the interrupt
ORG 013H ; starting address for the ISR(INT1)
ACALL ISRR ;
LABEL: MOV R1,#001H ; sets the initial stage of the LEDs
MAIN: ; main function that sets the interrupt parameters in a loop
;SETB P3.2 ; sets highest priority for the interrupt INT0
SETB IT0 ; interrupt generated by a falling edge signal at INT0 (P3.2)
SETB EX0 ; enables the external interrupt
SETB EA ; enables the global interrupt control
SJMP MAIN ; jumps back to the MAIN subroutine
ISRL: ; interrupt service routine
RET ; jumps to RETI
RET ; jumps to RETI