Unit - 4
Interrupt structure of 8051
An interrupt is an event that occurs randomly in the flow of continuity. 8051 architecture handles 5 interrupt sources,
Figure 1. Interrupt structure
Interrupt Enable (IE), Register
This register can be used to enable or disable interrupts programmatically. This register is an SFR. The address is A8H. This byte is a bit addressable. So it can be programmed by the user.
Bit Address | AF
| AE | AD | AC | AB | AA | A9 | A8 |
Bit Details | EA | X | x | ES | ET1 | EX1 | ET0 | EX0 |
Figure 2. IE Register
Bit Details | High Value(1) | Low Value(0) |
EA | The least significant 5 bits can decide to enable or disable these five interrupts | Disable all five interrupts. It just ignores the rest five bits |
ES | Enable Serial Port Interrupt | Disable Serial Port Interrupt |
ET1 | Enable Timer1 Interrupt | Disable Timer1 Interrupt |
EX1 | Enable external interrupt1 | Disable external interrupt1 |
ET0 | Enable Timer0 interrupt | Disable Timer0 Interrupt |
EX0 | Enable external interrupt 0 | Disable external interrupt 0 |
External Interrupt
The external interrupts of 8051 are INT0and. INT1 These interrupts can be programmed to either edge-triggered or level-triggered. The TCON register can be used to top program external interrupts to the edge or level triggered. The TCON isTimer Control. TCON is another bit addressable SFR. Here the address is 88H.
Bit Address | 8F | 8E | 8D | 8C | 8B | 8A | 89 | 88 |
Bit Details | TF1 | TR1 | TF0 | TR0 | IE1 | IT1 | IE0 | IT0 |
Figure 3. TCON register
Bit Details | High Value(1) | Low Value(0) |
IT0 | Set INT0 as a negative edge triggered input | Set INT0 as active low level triggered input. |
IT1 | Set INT1 as a negative edge triggered input | Set INT1 as active low level triggered input. |
IE0 | This will be 1. When INT0 is activated as level triggered | This will be 0 when INT0 is activated as edge-triggered |
IE1 | This will be 1. When INT1 is activated as level triggered | This will be 0 when INT1 is activated as edge-triggered |
TR0 | Set Timer0 as a run mode | Set Timer0 as stop mode. |
TR1 | Set Timer1 as a run mode | Set Timer1 as stop mode |
TF0 | High when Timer0 overflow occurs | After resetting the timer 0 this will also be changed to 0 state |
TF1 | High when Timer1 overflow occurs | After resetting the timer T1 this will also be changed to 0 state |
Serial Port Interrupt
The serial ports can be used in either Transmitting mode or reception mode. The interrupt status for the Transmission is provided by TI, and the status for Reception is provided by RI. These are two bits of SCON(Serial Control). This is also a bit addressable SFR. The address is98H
Bit Address | 9F | 9E | 9D | 9C | 9B | 9A | 99 | 98 |
Bit Details | SM0 | SM1 | SM2 | REN | TB8 | RB8 | TI | RI |
Figure 4. SCON register
Bit Details | Description |
SM0 | This is Serial Port Mode0 shift register |
SM1 | This is Serial Port Mode 1 (8-bit UAR + variable) |
SM2 | Enable multiprocessor communication in mode 2 or 3 |
REN | Set or reset by the software to enable or disable the Reception |
TB8 | It indicates the 9th bit that will be transmitted in mode 2 or 3. It can be set or reset by software |
RB8 | In mode 2 or 3 the 9th bit was received in mode 1. |
TI | The transmission interrupts the flag. It can be set by hardware |
RI | The receiver interrupts the flag. It can be set by hardware |
Figure 5. Serial Interrupt
Key Takeaways:
An interrupt is an event that occurs randomly in the flow of continuity.
The external interrupts are the interrupts received from the (external) devices interfaced with the microcontroller. They are received at INTx pins of the controller.
These can be level-triggered or edge-triggered.
In level triggered, interrupt is enabled for a low at INTx pin; while in case of edge triggering, interrupt is enabled for a high to low transition at INTx pin. The edge or level trigger is decided by the TCON register.
The TCON register has the following bits:
TCON:
Figure 6. TCON register
Setting the IT0 and IT1 bits makes the external interrupt 0 and 1 edge-triggered respectively. By default, these bits are cleared and so the external interrupt is level triggered.
Following are the steps for using external interrupt :
Example code
//Level trigger external interrupt
void main()
{
IE = 0x81;
while(1);
}
void ISR_ex0(void) interrupt 0
{
<body of interrupt>
}
Example code
//Edge trigger external interrupt
void main()
{
IE = 0x84;
IT1 = 1;
while(1);
}
void ISR_ex1(void) interrupt 2
{
<body of interrupt>
}
Key Takeaways:
In 8051 INT0 and INT1 are used as external hardware interrupts. Upon activation of these pins, the 8051 gets interrupted in whatever it is doing and jumps to the
vector table to perform the interrupt service routine.
ADC0808/0809:
ADC0808/0809 is a monolithic CMOS device that has 28 pins and gives 8-bit value in output and 8- channel ADC input pins (IN0-IN7). I
It has a resolution of 8 so it can encode the analoge data into one of the 256 levels (28).
This device has three channel address lines namely: ADDA, ADDB, and ADDC for selecting a channel.
Pin Diagram for ADC0808
Figure 7. ADC 0808 Pin
ADC0808/0809 requires a clock pulse for conversion. This can be provided by using an oscillator or by using a microcontroller.
Select the input channel using address lines, like the input line IN0 by keeping all three address lines (ADDA, ADDB, ADDC) low.
Suppose IN2 has selected the keep ADDA and ADDB low and ADDC high.
ADC Channel name | ADDC Pin | ADDB Pin | ADDA Pin |
IN0 | Low | Low | Low |
IN1 | Low | Low | High |
IN2 | Low | High | Low |
IN3 | Low | High | High |
IN4 | High | Low | Low |
IN5 | High | Low | High |
IN6 | High | High | Low |
IN7 | High | High | High |
SOC [Start of conversion]:
When a High to low signal is appears to this pin of ADC, ADC then starts the conversion
Figure 8. SOC
EOC [End of conversion]:
ADC sends this high EOC signal to Micro-Controller to indicate completion of the conversion.
OE [Output Enable]:
When a high signal is applied to this pin, the output latch of ADC gets enables and the converted data is then available to Micro-Controller.
The reference voltage determines the range of analog input voltage.
For example: - If the reference voltage is 5V then analog voltage range is from 0V-5V. If the reference voltage is 2.56V then the Analog signal range is from 0V-2.56V.
The frequency of the clock signal applied determines the conversion speed.
Working:
First, the microcontroller provides a 500 kHz clock signal to ADC0808 because the Timer 0 interrupts as ADC requires a clock signal to operate.
Then the microcontroller sends a LOW to HIGH-level signal to the ALE pin (active-high pin) of ADC0808 to enable the latch in the address.
By applying HIGH to LOW-Level signal to SC (Start Conversion), ADC starts analog to digital conversion. And then wait for the EOC (End of Conversion) pin to go LOW.
When EOC goes LOW, it means analog to digital conversion has been completed and data is ready to use.
After this, the microcontroller enables the output line by applying a HIGH to LOW signal to the OE pin of ADC0808.
ADC0808 gives ratiometric conversion output at its output pins.
Radiometric conversion is given by
Vin/(Vfs – Vz) = Dx / (Dmax – Dmin)
Where:
Vin is input voltage for conversion
Vfs is the full-scale voltage
Vz is zero voltage
Dx is a data point being measured
Dmax is a maximum data limit
Dmin is the minimum data limit.
Interfacing Diagram:
Figure 9. Interfacing 8051 with ADC0808
Program:
SOC EQU P2.6
EOC EQU P2.5
OE EQU P2.4
ALE EQU P2.3
ADDR_C EQU P2.2
ADDR_B EQU P2.1
ADDR_A EQU P2.0
ORG 0000H
MOV P1, #0FFH
SETB P2.5
CLR SOC
CLR OE
CLR ALE
AGAIN: CLR ADDR_C
CLR ADDR_B
CLR ADDR_A
SETB SOC
SET ALE
ACALL DELAY
CLR SOC
CLR ALE
BACK: JB EOC BACK
HERE: JNB EOC HERE
SETB OE
MOV A, P1
ACALL CONVERSION
ACALL DISPLAY
AGAIN: SJMP AGAIN
Key Takeaways:
The telephone modem is one of the examples of ADC, which is used for the internet, it converts analog data into digital data.
References:
1. The 8051 Microcontroller and Embedded Systems using Assembly and C by Muhammad Ali Mazidi.
2. The 8051 Microcontroller by I. Scott Mackenzie, Raphael C.W Phan
8051 Microcontrollers: Internals, Instructions, Programming, and Interfacing Book by Subrata Ghoshal
3. 8051 Microcontroller Based Embedded Systems Textbook by MANISH K PATEL
4. 8051 Microcontrollers: An Applications Based Introduction Book by David Calcutt, Frederick Cowan, and G. Hassan
5. Advanced PIC Microcontroller Projects in C Book by Dogan Ibrahim