OBJECTIVE
- Students understand the interrupt system on microcontrollers
- Students can apply interruption systems to making digital clocks.
- Students can understand the use of assembly language for using interrupt systems.
The microcontroller provides 5 interrupt sources, 2 external interrupts, 2 timer interrupts, and 1 serial interrupt. In order for interrupts to be served, assembly instructions must be placed at the following vector addresses, according to the interrupt source to be used.
| Source | Vector Address |
|---------|----------------|
| IE0 | 0003H |
| TF0 | 000BH |
| IE1 | 0013H |
| TF1 | 001BH |
| RI + TI | 0023H |
Org 0000h
Ljmp Start
Org 000bh
Ljmp Timer0Interupt
Start: ; Instruksi Rutinitas
; Instruksi Rutinitas
; Instruksi Rutinitas
Sjmp Start; { Looping Forever }
;
Timer0Interupt:
:
:
Reti
End
In the example of the programming instruction, it is seen that if there is no interrupt, the program will go to start and run the routines continuously, but if an interrupt generated by overflow timer 0 occurs, then the program that was originally nested in the routine will jump to the vector address 0bh (the timer 0 interrupt address) and jump to the interrupt subroutine Timer0Interupt.
Experiment 11.1. Generating a clock on a digital clock D by utilizing the timer 0 interrupt.
In the experiment, the clock for a digital clock will be generated, only the tens seconds (display 1) and units seconds (display 2) sections on 7 segments.
In this mode, with a 12MHz crystal, the timer will overflow every 65,536 useconds. In this experiment, to generate an interrupt every 50,000 useconds, the data that must be filled in the TL1 and TH1 registers is as follows
65536 - 50000 = 15536 d or 3CB0h
So the TF1 interrupt will be generated every 50000 x 1 usecond = 0.05 seconds.
in this programming, RO is implemented as a software counter, Register R0 will increment every Timer 1 overflow. If register R7 has detected a value of 50 then port P0.0 (LED D0) will light up for = 0.05 x 20 seconds = 1 second.
To do this experiment, do the following steps:
- Connect jumper 7Segment_EN, to enable the 74LS138 Decoder.
- Connect the Microcontroller Trainer module to the +5V power supply.
- Connect the Microcontroller Trainer module to the programmer circuit
- Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
- Type the following program download file prog111a.asm )
detik equ 30h detikpuluhan equ 31h detiksatuan equ 32h counter20 equ 33h ; Org 0h sjmp Start Org 0bh Ljmp Interrupt_Timer0 ; Start: mov detik,#0 call InitTimer ; Forever: call ClockDisplay sjmp Forever ; ; Interrupt_Timer0: mov tl0,#0b0h mov th0,#03ch djnz Counter20, EndInterrupt mov Counter20,#20 call DoClock EndInterrupt: reti ; DoClock: inc detik mov A,detik cjne A,#60,Update mov detik,#0 Update:mov A,detik mov B,#10 DIV AB mov detikpuluhan,A mov detiksatuan,B ret ; ClockDisplay: Mov DPTR,#Decoder7Segmen mov A,detiksatuan Movc A,@A+DPTR mov P0,A clr P3.5 ; Setb P3.6 Setb P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,detikpuluhan Movc A,@A+DPTR mov P0,A ; Setb P3.5 ; clr P3.6 Setb P3.7 call delay ret ; InitTimer: mov TMOD,#00000001b mov tl0,#0b0h mov th0,#03ch setb ET0 ;Enable Timer 0 Interrupt setb EA ;Master Interrupt Enable setb TR0 ;Clock start running ret ; ;=============================== ;subroutine delay time ;=============================== delay: mov R1,#2 del1: mov R2,#255 del2: djnz R2,del2 djnz R1,del1 ret ;======================================== ; L O O K U P T A B L E ; Decode to Seven Segmen -> g f e d c b a ;======================================== Decoder7Segmen: DB 11000000b,11111001b,10100100b,10110000b,10011001b DB 10010010b,10000010b,11111000b,10000000b,10010000b ; End
- Save the program you typed and name it: prog111a.asm
- In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
- Program the microcontroller using the ISP Software Program (See Instructions for Use)
- Make observations on the displayed second time data to see whether it matches a conventional clock.
| Display Detik (:DD) | Jam Konvensional (Detik) |
|---------------------|--------------------------|
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| : | |
| 60 | |
Experiment 10.2 Serial data transfer from ADC to Microcontroller to PC
In this experiment, ADC0804 data is taken using port 1 of the microcontroller and sent via the serial port to the PC.
Experiment 10.2 Serial data transfer from ADC to Microcontroller to PC
Do some trial steps as follows:
- Connect the Microcontroller Trainer module to the +5V power supply.
- Connect the Microcontroller Trainer module to the programmer circuit
- Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
- Type the following assembly program: ( download the file prog102a.asm )
org 0h call initserial ; start: call ADC; ambil data dari adc call Sendout sjmp start ; ADC: clr P3.3 nop setb P3.3 eoc: jb P3.2,eoc clr P3.4 mov A,P1 setb P3.4 ret ; Sendout: detect: jnb ti,detect; clr ti ; mov sbuf,a ; ret ; initserial: mov scon,#52h;initialize serial mode 1 mov tmod,#20h;timer1 mode 2 mov th1,#0F3h;Reload value for baud rate 2400 setb tr1 ret end
- Open Delphi Program
- Type the following Delphi program, to run communication through a serial port with a base address of 3F8h. ( download the ADCserial file )
ADCserial file
var
Form1: TForm1;
data,status:byte;
const
base = $3f8;{base address port serial}
lcr = 3; {line control register}
dll = 0; {divisor lacht low byte}
dlh = 1; {divisor lacht high byte}
lsr = 5; {line status register}
implementation
{$R *.DFM}
Procedure Initserial;
begin
asm
mov dx,base+lcr; {address line control register}
mov al,$80 ; {10000000b = access bit divisor lacht}
out dx,al
;
mov dx,base+dll; {address divisor lacht low byte}
mov al,$30 ; {DLLB = 30h}
out dx,al
;
mov dx,base+dlh; {address divisor lacht high byte}
mov al,$00 ; {DLLH = 00h}
out dx,al
; {Pada saat ini Port serial}
; {memp.baud rate = 2400 bps}
mov dx,base+lcr;{address line control register}
mov al,$03 ; {00000011b =}
out dx,al ; {bit 7=0, access to Rx buffer & Tx
; {bit 6=0, set break disable
; {bit 5-4-3=000, no parity
; {bit 2=0, one stop bit
; {bit 1-0=11,data lenght 8 bit}
end;
end;
Procedure Receive_Data_Serial;
begin
asm
mov dx,base
in al,dx
mov data,al
end
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Repeat
asm
mov dx,base+lsr ; { address line status register }
in al,dx
and al,$01 ; {LSR = 00000001b, detects bit 0}
mov status,al ; {bit 0 = data ready}
end;
until status = $01;{ jika bit 0 = 1 then data ready}
Receive_Data_Serial;
edit1.text:=inttostr(data);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
initserial;
timer1.enabled:=true;
end;
- Save the program you typed and name it: prog102a.asm
- In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
- Program the microcontroller using the ISP Software Program (See Instructions for Use)
- Run the Delphi program by pressing the F9 or RUN button.
- Make observations for the displayed ADC data.
Experiment 11.2. Generating a clock on a digital clock MM D by utilizing the timer 0 interrupt
In the experiment, a clock will be generated for a digital clock for seconds and minutes on 7 segments. To do this experiment, do the following steps:
- Connect jumper 7Segment_EN, to enable the 74LS138 Decoder.
- Connect the Microcontroller Trainer module to the +5V power supply.
- Connect the Microcontroller Trainer module to the programmer circuit
- Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
- Type the following program: ( download file prog112a.asm )
detik equ 30h detikpuluhan equ 31h detiksatuan equ 32h menit equ 33h menitpuluhan equ 34h menitsatuan equ 35h counter20 equ 36h ; Org 0h sjmp Start Org 0bh Ljmp Interrupt_Timer0 ; Start: mov detik,#0 mov menit,#0 call InitTimer ; Forever: call ClockDisplay sjmp Forever ; ; Interrupt_Timer0: mov tl0,#0b0h mov th0,#03ch djnz Counter20, EndInterrupt mov Counter20,#20 call DoClock EndInterrupt: reti ; DoClock: inc detik mov A,detik cjne A,#60,Update mov detik,#0 satumenit: inc menit mov A,#60 cjne A,menit,Update mov menit,#0 Update:mov A,detik mov B,#10 DIV AB mov detikpuluhan,A mov detiksatuan,B ; mov a,menit mov b,#10 div ab mov menitpuluhan,A mov menitsatuan,B ret ; ClockDisplay: Mov DPTR,#Decoder7Segmen mov A,menitpuluhan Movc A,@A+DPTR mov P0,A clr P3.5 ; clr P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,menitsatuan Movc A,@A+DPTR mov P0,A setb P3.5 ; clr P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,detikpuluhan Movc A,@A+DPTR mov P0,A clr P3.5 ; setb P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,detiksatuan Movc A,@A+DPTR mov P0,A setb P3.5 ; Setb P3.6 clr P3.7 call delay ret ; InitTimer: mov TMOD,#00000001b mov tl0,#0b0h mov th0,#03ch setb ET0 ;Enable Timer 0 Interrupt setb EA ;Master Interrupt Enable setb TR0 ;Clock start running ret ; ;=============================== ;subroutine delay time ;=============================== delay: mov R1,#2 del1: mov R2,#255 del2: djnz R2,del2 djnz R1,del1 ret ;======================================== ; L O O K U P T A B L E ; Decode to Seven Segmen -> g f e d c b a ;======================================== Decoder7Segmen: DB 11000000b,11111001b,10100100b,10110000b,10011001b DB 10010010b,10000010b,11111000b,10000000b,10010000b ; End
- Save the program you typed and name it: prog112a.asm
- In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
- Program the microcontroller using the ISP Software Program (See Instructions for Use)
- Make observations for the time data displayed.
| Display Detik (:DD) | Jam Konvensional (Detik) |
|---------------------|--------------------------|
| 00:01 | |
| 00:02 | |
| 00:03 | |
| 00:04 | |
| 01:59 | |
Experiment 11.3. Generating MM D clock down by utilizing timer 0 interrupt
In the experiment, a clock will be generated with a countdown from minute 60 seconds 60 for seconds and minutes on 7 segments. To do this experiment, do the following steps:
- Connect jumper 7Segment_EN, to enable the 74LS138 Decoder.
- Connect the Microcontroller Trainer module to the +5V power supply.
- Connect the Microcontroller Trainer module to the programmer circuit
- Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
- Type the following program: ( download file prog113a.asm )
detik equ 30h detikpuluhan equ 31h detiksatuan equ 32h menit equ 33h menitpuluhan equ 34h menitsatuan equ 35h counter20 equ 36h ; Org 0h sjmp Start Org 0bh Ljmp Interrupt_Timer0 ; Start: mov detik,#60 mov menit,#59 call InitTimer ; Forever: call ClockDisplay sjmp Forever ; ; Interrupt_Timer0: mov tl0,#0b0h mov th0,#03ch djnz Counter20, EndInterrupt mov Counter20,#20 call DoClock EndInterrupt: reti ; DoClock: dec detik mov A,detik cjne A,#0,Update mov detik,#60 satumenit: dec menit mov A,#0 cjne A,menit,Update mov menit,#60 Update:mov A,detik mov B,#10 DIV AB mov detikpuluhan,A mov detiksatuan,B ; mov a,menit mov b,#10 div ab mov menitpuluhan,A mov menitsatuan,B ret ; ClockDisplay: Mov DPTR,#Decoder7Segmen mov A,menitpuluhan Movc A,@A+DPTR mov P0,A clr P3.5 ; clr P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,menitsatuan Movc A,@A+DPTR mov P0,A setb P3.5 ; clr P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,detikpuluhan Movc A,@A+DPTR mov P0,A clr P3.5 ; setb P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,detiksatuan Movc A,@A+DPTR mov P0,A setb P3.5 ; Setb P3.6 clr P3.7 call delay ret ; InitTimer: mov TMOD,#00000001b mov tl0,#0b0h mov th0,#03ch setb ET0 ;Enable Timer 0 Interrupt setb EA ;Master Interrupt Enable setb TR0 ;Clock start running ret ; ;=============================== ;subroutine delay time ;=============================== delay: mov R1,#2 del1: mov R2,#255 del2: djnz R2,del2 djnz R1,del1 ret ;======================================== ; L O O K U P T A B L E ; Decode to Seven Segmen -> g f e d c b a ;======================================== Decoder7Segmen: DB 11000000b,11111001b,10100100b,10110000b,10011001b DB 10010010b,10000010b,11111000b,10000000b,10010000b ; End
- Save the program you typed and name it: prog113a.asm
- In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
- Program the microcontroller using the ISP Software Program (See Instructions for Use)
- Make observations for the time data displayed.
Experiment 11.3. Generating MM D clock down by utilizing timer 0 interrupt
In the experiment, a clock will be generated with a countdown from minute 60 seconds 60 for seconds and minutes on 7 segments. To do this experiment, do the following steps:
- Connect jumper 7Segment_EN, to enable the 74LS138 Decoder.
- Connect the Microcontroller Trainer module to the +5V power supply.
- Connect the Microcontroller Trainer module to the programmer circuit
- Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
- Type the following program: ( download file prog113a.asm )
detik equ 30h detikpuluhan equ 31h detiksatuan equ 32h menit equ 33h menitpuluhan equ 34h menitsatuan equ 35h counter20 equ 36h ; Org 0h sjmp Start Org 0bh Ljmp Interrupt_Timer0 ; Start: mov detik,#60 mov menit,#59 call InitTimer ; Forever: call ClockDisplay sjmp Forever ; ; Interrupt_Timer0: mov tl0,#0b0h mov th0,#03ch djnz Counter20, EndInterrupt mov Counter20,#20 call DoClock EndInterrupt: reti ; DoClock: dec detik mov A,detik cjne A,#0,Update mov detik,#60 satumenit: dec menit mov A,#0 cjne A,menit,Update mov menit,#60 Update:mov A,detik mov B,#10 DIV AB mov detikpuluhan,A mov detiksatuan,B ; mov a,menit mov b,#10 div ab mov menitpuluhan,A mov menitsatuan,B ret ; ClockDisplay: Mov DPTR,#Decoder7Segmen mov A,menitpuluhan Movc A,@A+DPTR mov P0,A clr P3.5 ; clr P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,menitsatuan Movc A,@A+DPTR mov P0,A setb P3.5 ; clr P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,detikpuluhan Movc A,@A+DPTR mov P0,A clr P3.5 ; setb P3.6 clr P3.7 call delay ; Mov DPTR,#Decoder7Segmen mov A,detiksatuan Movc A,@A+DPTR mov P0,A setb P3.5 ; Setb P3.6 clr P3.7 call delay ret ; InitTimer: mov TMOD,#00000001b mov tl0,#0b0h mov th0,#03ch setb ET0 ;Enable Timer 0 Interrupt setb EA ;Master Interrupt Enable setb TR0 ;Clock start running ret ; ;=============================== ;subroutine delay time ;=============================== delay: mov R1,#2 del1: mov R2,#255 del2: djnz R2,del2 djnz R1,del1 ret ;======================================== ; L O O K U P T A B L E ; Decode to Seven Segmen -> g f e d c b a ;======================================== Decoder7Segmen: DB 11000000b,11111001b,10100100b,10110000b,10011001b DB 10010010b,10000010b,11111000b,10000000b,10010000b ; End
- Save the program you typed and name it: prog113a.asm
- In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
- Program the microcontroller using the ISP Software Program (See Instructions for Use)
- Make observations for the time data displayed.