Unit 3
Unit 3
Interfacing-I
Interrupt Vs Polling
It becomes inefficient if devices frequently interrupt Polling becomes inefficient when the CPU rarely
the CPU. finds a device that is ready to be serviced.
Steps in executing an interrupt
11-9
Classification of Interrupts
• Maskable Interrupts
• Nonmaskable Interrupts
• Vectored Interrupts
• Non-vectored
Interrupts
Note: Non Maskable : cannot be disabled or ignored by the instructions of CPU
Maskable : disabled or ignored by the instructions of CPU
Sources of Interrupts:
INTCON3
INT2IP INT1IP ---- INT2IE INT1IE ---- INT2IF INT1IF
Show the instructions to
PSPIF: Parallel Slave Port Read/Write Interrupt SSPIF: Synchronous Serial Port (SSP) Interrupt Flag bit
Flag bit(1) CCP1IF: CCP1 Interrupt Flag bit
1 = A read or a write operation has taken place TMR2IF: TMR2 to PR2 Match Interrupt Flag bit
0 = No read or write has occurred
1 = TMR2 to PR2 match occurred
ADIF: A/D Converter Interrupt Flag bit 0 = No TMR2 to PR2 match occurred
1 = An A/D conversion completed TMR1IF: TMR1 Overflow Interrupt Flag bit
0 = The A/D conversion is not complete
1 = TMR1 register overflowed
RCIF: USART Receive Interrupt Flag bit 0 = TMR1 register did not overflow
1 = The USART receive buffer is full
0 = The USART receive buffer is empty
TXIF: USART Transmit Interrupt Flag bit
1 = The USART transmit buffer is empty
0 = The USART transmit buffer is full
PIR2 (Peripheral Interrupt Request Register 2)
CMIF: Comparator Interrupt Flag bit BCLIF: Bus Collision Interrupt Flag bit
1 = The comparator input has changed 1 = A bus collision has occurred
in the SSP when configured for I2C
0 = The comparator input has not changed
Master mode
0 = No bus collision has occurred
EEIF: EEPROM Write Operation Interrupt Flag
bit
CCP2IF: CCP2 Interrupt Flag bit
1 = The write operation completed
0 = The write operation is not complete or
has not been started
PIR3
PIE Register (Peripheral Interrupt
Enable)
► PIE Register (Peripheral Interrupt Enable) contain the individual enable bits for
the peripheral interrupts.
► Due to the number of peripheral interrupt sources, there are three peripheral
Interrupt Enable registers (PIE1, PIE2, PIE3)
► When IPEN is clear, the PEIE bit must be set to enable any of these peripheral
interrupts.
PIE Register 1 (Peripheral Interrupt Enable)
PSPIE: Parallel Slave Port Read/Write TXIE: USART Transmit Interrupt Enable bit
Interrupt Enable bit(1) 1 = Enables the USART to transmit interrupt
1 = Enables the PSP read/write interrupt 0 = Disables the USART transmit interrupt
0 = Disables the PSP read/write interrupt SSPIE: Synchronous Serial Port Interrupt Enable bit
ADIE: A/D Converter Interrupt Enable bit 1 = Enables the SSP interrupt
1 = Enables the A/D converter interrupt 0 = Disables the SSP interrupt
0 = Disables the A/D converter interrupt CCP1IE: CCP1 Interrupt Enable bit
RCIE: USART Receive Interrupt Enable bit 1 = Enables the CCP1 interrupt
1 = Enables the USART to receive interrupt 0 = Disables the CCP1 interrupt
0 = Disables the USART receive interrupt TMR2IE: TMR2 to PR2 Match Interrupt Enable bit
RCIE: USART Receive Interrupt Enable bit 1 = Enables the TMR2 to PR2 match interrupt
1 = Enables the USART to receive interrupt 0 = Disables the TMR2 to PR2 match interrupt
0 = Disables the USART receive interrupt
CMIE: Comparator Interrupt Enable bit
1 = Enables the comparator interrupt
0 = Disable the comparator interrupt
1. Enable GIE,PEIE,TMRxIE
2. Configure the TxCON register
3. Clear TMRxIF Timer interrupt flag.
4. Load the count in Timer register TMRx.
5. Set TMRxON to start Timer operation.
6. When TMRxIF =1 , code will jump to ISR to execute it, and after
excecution control returns to the main program.
Example: Write a C program for the PIC18 to generate a square wave of 2 KHz frequency
on RB4 using Timer0 ISR and a square wave of 5 KHz frequency on RB5 using TIMER1
ISR. Assume XTAL=10 MHz
Answer : Given : Fosc = 10 MHz , No Prescaler Ftimer =Fosc /4 = 10/4= 2.5 MHz
Period = 1/Timer= 1/ 2.5 MHz = 0.4 µsec.
a. LED connected in current source mode b. LED connected in current sink mode
Q. Write an embedded pic18 c program to
flash the LED connected to pin 0 of PORTB
Assume that Ton and Toff of LED = PortBit =0;
500 msec.
DELAY(500);
#include<pic18f4550.h>
}
#define PortBit PORTbits.RB0
}
void DELAY(unsigned int);
Void DELAY (unsigned int t);
void main(void)
{ {
{ DELAY(500);
TRISD=0; PD5 = 1;
While(1); DELAY(500);
Interfacing of LCD:-
RD0 DB0 Vcc
RD1 DB1
RD2 DB2 16 character * 2 line VEE
RD3 DB3
RD4 DB4 LCD display module
RD5 DB5 VSS
RD6 DB6
PIC18XXX RD7 DB7 RS RW E
RE0
RE1
RE2