Documente Academic
Documente Profesional
Documente Cultură
Polling..
In polling, the micro controller continuously monitors
service.
After that, it moves on to monitor the next device until
do anything else.
That is a waste of microcontroller time that could have been used
doing other tasks, and when the TMROIF flag is raised, the timer
will interrupt the microcontroller in whatever it is doing.
following steps:
1. It finishes the instruction it is executing and saves the address of the next
instruction (program counter) on to the stack.
2. It jumps to a fixed location in memory called the interrupt vector table. The
interrupt vector table directs the microcontroller to the address of the interrupt
service routine (lSR).
3. The microcontroller gets the address of the ISR from the interrupt vector
table and jumps to it. It starts to execute the interrupt service subroutine until
it reaches the last instruction of the subroutine, which is RETFIE (return from
interrupt exit).
4. Upon executing the RETFIE instruction, the micro controller returns to the
place where it was interrupted. First, it gets the program counter (PC)
address from the stack by popping the top bytes of the stack into the PC. Then
it starts to execute from that address.
the
RB0
external hardware
for transmit.
The PORTB-Change interrupt.
The ADC (analog-to-digital converter).
The CCP (compare capture pulse-width modulation).
The PIC 18 has many more interrupts than the above list.
and another
RCON
INTCON
INTCON2
INTCON3
PIR1, PIR2
PIE1, PIE2
IPR1, IPR2
Interrupt.
A limited number of bytes is set aside for high-priority
interrupts.
A total of 8 bytes, from location 0008 to 000017H, are set aside
ORG 0
;wake-up ROM reset location
GOTO MAIN ;To bypass interrupt vector table
;---- the wake-up program
ORG 100H
MAIN --------- ;Write the main code at100 onwards.
---------END
TMR0IF
and TXIF, we have to enable the PEIE flag in addition to the GIE
bit.
BSF INTCON,TMROIE
BSF INTCON,INTOIE
BSF INTCON,GIE
TRISB,5
MOVLW 0x08
MOVWF T0CON
MOVWF TMR0H
MOVLW 0xF2
MOVWF TMR0L
BCF
INTCON,
BTG
PORTB, 5
BSF
T0CON,
INTCON,
TMR0IF
AGAIN BTFSS
BRA
AGAIN
BCF
T0CON,
BRA
HERE
TMR0IF
timer rolls
over. We have also seen how to monitor the timer
flag with the instruction "BTFSS TMR0IF".
In polling TMR0IF, we have to wait until TMR0IF is
raised.
The problem with this method is that the
raised whenever the timer rolls over and the microcontroller jumps
(automatically) to the interrupt vector table to service the ISR.
In this way, the microcontroller can do other things until it is notified
interrupt because all the interrupts are masked upon power-on reset.
The TMRxIE bit enables the interrupt for a given timer-x.
TMRxIE bits are held by various registers.
In the case of Timer0, the INTCON register contains the
TMR0IE bit, and PIE1 (peripheral interrupt enable) holds the TMRlIE bit
Enable
Bit
Register
TMR0IE INTCON
Timer1 TMR1IF
PIR1
TMRlIE
PIE 1
Timer2 TMR2IF
PIR1
TMR2IE
PIE1
Timer3 TMR3IF
PIR3
TMR3IE
PIE2
ORG 0000H
GOTO MAIN ;bypass interrupt vector table
;--on default all interrupts land at address 00008
ORG 0008H ; interrupt vector table
BTFSS INTCON,TMR0IF ;Timer0 interrupt?
RETFIE ;No. Then return to main
GOTO T0_ISR ;Yes. Then go Timer0 ISR
;--main program for initialization and keeping CPU busy
ORG 00100H
; after vector table space
MAIN BCF TRISB, S ; PB5 as an output
CLRF TRISD
;make PORTD output
SETF TRISC ;make PORTC input
enter an infinite loop to keep the CPU busy. This could be a realworld application being executed by the CPU. (Here, the loop gets
data from PORTC and sends it to PORTD.)
While the PORTC data is brought in and issued to PORTD
At this point, the PIC18 clears the GIE bit (D7 of INTCON) to
ORG 0000H
GOTO MAIN ;To bypass interrupt vectors
;--on default all the interrupts land on 008.
ORG 0008H ;HP interrupt vector table
GOTO CHK_INT ;Jump to a location where mores pace is available.
;--check to identify the source of interrupt.
ORG 0040H
CHK_INT
BTFSC INTCON,TMR0IF ;Is it Timer0 interrupt?
BRA T0_ISR ;Yes. Then branch to Timer 0 ISR
BTFSC PIR1,TMR1IF ;Is it Timer1 interrupt?
BRA T1_ISR ; Yes. Then branch to Timer1 ISR
RETFIE ;If both are not, Then return to main
;-main program for initialization and keeping CPU busy
ORG 0100H ;somewhere after int. vector table space
MAIN BCF TRISB,l ; PB1 as an output
BCF TRISB,7 ;PB7 as an output
CLRF TRISD ;make PORTD output
SETF TRISC ;make PORTC input
MOVLW 0x08 ;Timer0,16-bit, ;no prescale, internal clk
MOVWF T0CON
;load T0CON reg .
MOVLW 0xFF ; TMROH = FFH, the high byte
MOVWF TMR0H
; load Timer0 high byte
MOVLW 0xF2 ;TMR0L = F2H, the low byte
MOVWF TMR0L
;load Timer0 low byte
associated
with
INTxIE
bits
are shown
Interrupt
(Pin)
Flag Bit
Register
Enable Register
INT0 (RB0)
INT0IF
bit
INTCON INT0IE
INT1 (RB1)
INT1IF
INTCON3 INT1IE
INTCON3
INT2 (RB2)
INT2IF
INTCON3 INT2IE
INTCON3
INTCON
must
program the INTEDGx bits.
connected a switch to INT0 and an LED to pin RB7. In this program, every
time when the logic level of the pin RB0 changes from low to high (Voltage
of this pin changes from 0 to 5 V) , INT0 is activated, it jumps to ISR,
where code to toggles the LED is kept, while at the same time data is
being transferred from PORTE to PORTD.
ORG 00H
GOTO MAIN ;bypass interrupt vector table
;--on default all interrupts go to 008H.
ORG 0008H ;interrupt vector table
BTFSS INTCON,INTOIF ;Did we get here due to INT0?
RETFIE ;No. Then return to main
GO TO INT0_ISR ; Yes. Then go INT0_ISR
;;--the main program for initialization
ORG 00100H
MAIN BCF TRISB,7
;PB7 as an output
BSF TRISB,INT0 ;make INT0 (RB0) as an input pin, to accept interrupt in this pin.
CLRF TRISD ;make PORTD output
SETF TRISC ;make PORTC input
BSF INTCON,INT0IE ;enable INT0 interrupt
BSF INTCON,GIE ;enable interrupts globally
OVERMOVFF PORTC, PORTD; send data from PORTC to PORTD
BRA OVER ;stay in this loop forever
;--------------------------ISR for INT0
INT0_ISR
ORG 200H
BTG PORTB,7 ;toggle PB7
BCF INTCON,INTOIF ; clear INTO interrupt flag bit
RETFIE ;return from ISR
END
edge-triggered interrupts.
To make any of them a negative (falling) edge- triggered interrupt, we must
register, respectively.
The status of these bits determines the negative or positive edge-triggered
MAIN, to toggle the LED when the level of the RB0 pin changes from high to
low (LED was toggling when the RB0 level changes from low to high there).
The rising edge (or the falling edge) is latched by the PIC 18
flags.
When an interrupt-in-service flag is raised, it indicates to the
execution of instruction RETFIE), the IF bits (INT0IFINT2IF) must be cleared in our code (Will not
happen automatically), indicating that the interrupt
is finished and the PIC 18 is ready to respond to
another interrupt on that pin.
PORTB-CHANGE INTERRUPT
The four pins of the PORTB (RB4-RB7) can cause an
interrupt when any changes are detected on anyone of
them.
They are referred to as "PORTB-Change interrupt" to
distinguish them from the INTO-INT2 interrupts, which
are also located on PORTB (RBO-RB2).
INTCON REGISTER
What
Interrupt
Power-on-Reset
High-priority
Interrupt
0000
0008 (Default upon power-on
reset)
Two-level priority
We can make the PIC18 a two-level priority system by way of
IPR1 (interrupt priority register) with the IP bits for TXIP, RCIP,
TMR1IP, and TMR2IP. If IPEN = 1, then the IP bit will take effect and
will
assign a given interrupt a low priority.
land at the address 0018 instead of 0008 in the interrupt vector table.
The IP (interrupt priority) bit along with the IF (interrupt flag) and
The INT0 has only one priority and that is high priority. That
means all the PIC 18 interrupts can be assigned a low or high priority
level, except the external hardware interrupt of INT0.
priority.
control
interrupt operation
Note: Do not use the
RCON
MOVFF instruction to
INTCON
modify any of the
Interrupt control
INTCON2
registers while any
INTCON3
interrupt is enabled.
PIR1, PIR2
Doing so may cause
PIE1, PIE2
erratic microcontroller
IPR1, IPR2
behaviour.
Flag bit
Enable bit
Priority
(Register)
(Register)
(Register)
Timer0
TMR0IF (INTCON)
Timer1
TMR1IF (PIR1)
TMR1IE (PIE1)
TMR1IP (IPR1)
Timer2
TMR2IF (PIR1)
TMR2IE (PIE1)
TMR2IP (lPR1)
Timer3
TMR3IF (PIR2)
TMR3IE (PIE2)
TMR3IP (lPR2)
INT1
INT1IF (INTCON3)
INT1IE (INTCON3)
INT1IP (INTCON3)
INT2
INT2IF (INTCON3)
INT2IE (INTCON3)
INT2IP (INTCON3)
TXIF
TXIF (PIR1)
TXIE (PIE1)
TXIP (lPR1)
RCIF
RCIF (PIR1)
RCIE (PIE1)
RCIP (lPR1)
RBIE (lNTCON)
RBIP (INTCON2)
RB INT
RBIF (INTCON)
The interrupt priority feature is enabled by setting the IPEN bit (RCON<7>).
When interrupt priority is enabled, there are two bits which enable interrupts
globally.
Setting the GIEH bit (Same as GIE bit, INTCON<7>) enables all interrupts
bit are set, the interrupt will vector immediately to address 000008h or
000018h, depending on the priority level.
Individual interrupts can be disabled through their corresponding enable
bits.
(a) We must set GIEH = 1. The GIEH bit is part of the INTCON register
and is the same as GIE, which we have used in previous sections. In
this regard there is no difference between the priority and no priority
systems.
(b) The second bit we must set high is GIEL (part of INTCON). Making
GIEL = 1 will enable all the interrupts whose IP = 0.
That means all the interrupts that have been given the low priority will
be forced to vector location 00018H.
INTCON REGISSTER
Program 11-11
Although all the interrupts are latched and kept internally, no low-priority
interrupt can get the immediate attention of the CPU until the PIC18 has
finished servicing all the high-priority interrupts.
The GIE (which is also called GIEH) and GIEL bits play an important role in the
process of the interrupt inside the interrupt.
Points to be noted .
* The RETFIE instruction at the end of the ISR will enable the
GIEL (GIEL = 1) automatically, which allows low-priority
interrupts to come in again.
PC
value
is
This way, the three key registers of the main task are saved
internally.
Interrupt latency
The
type of the instruction in which the CPU was executing when the
interrupt comes in.
It takes slightly longer in cases where the instruction being
simulation.
This can be done with simple instructions to set the
Conclution..
An interrupt is an external or internal event that interrupts
raised.