Fundamentals of Microcontroller & Its Application: Unit-Iv
Fundamentals of Microcontroller & Its Application: Unit-Iv
Fundamentals of
CLASS NOTES
Microcontroller
& its Application
UNIT-IV
Mr. RAJAN PATEL
Asst. Prof.
Electrical Engg. Dept., GCOERC
Course Outcome: CO-4
Elaborate interrupt structure of 8051 and program to handle interrupt and ADC809.
Teaching Hours: 6
Content: -
Interrupt structure of 8051 and SFR associated with interrupts Programming of External
hardware interrupts in C. Interfacing of ADC 0809 with 8051.
Interrupts in 8051 Microcontroller
It is a sub-routine calls that given by the microcontroller when some other program with
high priority is request for acquiring the system buses than interrupt occur in current
running program.
Interrupts provide a method to postpone or delay the current process, performs a sub-
routine task and then restart the standard program again.
Types of Interrupts in 8051 Microcontroller
The 8051 microcontroller can recognize five different events that cause the main program
to interrupt from the normal execution. These five sources of interrupts in 8051are:
o Timer 0 overflow interrupt- TF0
o Timer 1 overflow interrupt- TF1
o External hardware interrupt- INT0
o External hardware interrupt- INT1
o Serial communication interrupt- RI/TI
The Timer and Serial interrupts are internally generated by the microcontroller, whereas
the external interrupts are generated by additional interfacing devices or switches that are
externally connected to the microcontroller.
These external interrupts can be edge triggered or level triggered.
When an interrupt occurs, the microcontroller executes the interrupt service routine so that
memory location corresponds to the interrupt that enables it.
The Interrupt corresponding to the memory location is given in the interrupt vector table
below.
Interrupt Flag Interrupt vector address
Reset - 0000H
INT0 (Ext. int. 0) IE0 0003H
Timer 0 TF0 000BH
INT1 (Ext. int. 1) IE1 0013H
Timer 1 TF1 001BH
Serial TI/RI 0023H
All the interrupts can be set or cleared by some special function register that is also known
as interrupt enabled (IE), and it is totally depends on the priority, which is executed by using
interrupt priority register.
Interrupt Enable (IE) Register
IE register is used for enabling and disabling the interrupt.
This is a bit addressable register in which EA value must be set to one for enabling interrupts.
The individual bits in this register enables the particular interrupt like timer, serial and
external inputs.
Consider in the below IE register, bit corresponds to 1 activate the interrupt and 0 disable
the interrupt.
Bit 3- IE1:
External Interrupt 1 edge flag, set by hardware when interrupt on INT1 pin occurred and cleared
by hardware when interrupt get processed.
Bit 2- IT1:
This bit selects the external interrupt event type on INT1 pin,
1= sets interrupt on falling edge
0= sets interrupt on low level
Bit 1- IE0:
Interrupt0 edge flag, set by hardware when interrupt on INT0 pin occurred and cleared by
hardware when an interrupt is processed.
Bit 0 - IT0:
This bit selects the external interrupt event type on the INT0 pin.
1= sets interrupt on falling edge
0= sets interrupt on low level
Interrupt programming in 8051
Timer Interrupt Programming: In microcontroller Timer 1 and Timer 0 interrupts are
generated by time register bits TF0 AND TF1.
This timer interrupts programming by C code involves:
o Selecting the configuration of TMOD register and their mode of operation.
o Enables the IE registers and corresponding timer bits in it.
Selection of Channel
We can select the any input channel by using the Address lines ADD A, ADD B and ADD C).
We can select the input line IN0 by keeping all three address lines (ADD A, ADD B and ADD
C) Low.
If we want to select input channel IN4 then we need to keep ADD A, ADD B low and ADD C
high.
For selecting all the other input channels, have a look on the given table:
void main()
{
lcd_init();
show("TEMP: ");
cmd(0xc0);
show("GAS : ");
while(1) {
cmd(0x86);
temp=adc(0); //Reading Value from ADC Channel 0
dat((temp/100)%10 +0x30);
dat((temp/10)%10 +0x30);
dat(temp%10 +0x30);
cmd(0xc6);
gas=adc(1); //Reading Value from ADC Channel 1
dat((gas/100)%10 +0x30);
dat((gas/10)%10 +0x30);
dat(gas%10 +0x30);
}
}
void lcd_init()
{
cmd(0x02);
cmd(0x28);
cmd(0x0e);
cmd(0x06);
cmd(0x80);
}
void lcd_delay()
{
unsigned int lcd_delay;
for(lcd_delay=0;lcd_delay<=1000;lcd_delay++);
}