Professional Documents
Culture Documents
Tassaduq 3
Tassaduq 3
Task 01: In normal operation, the LED on RB4 will be flashing at an interval of 1 second. When
there is an interrupt, the main program will jump to this subroutine and Flash fast the LED connected to
PORTB5.
Config.c
/*
* File: config.c
*/
// CONFIG1H
// CONFIG2L
// CONFIG2H
// CONFIG3H
// CONFIG4L
// CONFIG5L
// CONFIG5H
// CONFIG6L
// CONFIG6H
// CONFIG7L
// CONFIG7H
C Code:
/*
* File: intp.c
* Author: Syed Haider Abbas
*
* Created on October 1, 2022, 4:48 AM
*/
#define _XTAL_FREQ 8000000
#include <stdio.h>
#include <stdlib.h>
#include "config.c"
#include <xc.h>
}
}
void main(void)
{
TRISB = 0x0F; //Set PORTB first 4 pins as Input and last 5 as Output
INTCONbits.INT0E = 1; //enable Interrupt 0 (RB0 as interrupt)
INTCON2bits.INTEDG0 = 0; //cause interrupt at falling edge
INTCONbits.INT0F = 0; //clear interrupt flag
ei(); // This is like flipping the master switch to enable interrupt
while (1)
{
LATBbits.LATB4 = 1; //Switch ON B4
for (int count=0; count<20; count++)
__delay_ms(50); //Generate 1 sec delay
LATBbits.LATB4 = 0; //Switch OFF B4
for (int count=0; count<20; count++)
__delay_ms(50); //Generate 1 sec delay
if(PORTBbits.RB0==1)
CheckSwitchPressed();
}
return;
}
Output: