[go: up one dir, main page]

0% found this document useful (0 votes)
20 views2 pages

Falling Edge Program

The document is a C program for a PIC microcontroller that configures various settings and initializes I/O ports. It includes an interrupt service routine that checks the state of PORTB and controls PORTD based on its value. The main loop continuously displays the OPTION_REG and INTCON registers on PORTC with a delay.

Uploaded by

tpgitspotify
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Falling Edge Program

The document is a C program for a PIC microcontroller that configures various settings and initializes I/O ports. It includes an interrupt service routine that checks the state of PORTB and controls PORTD based on its value. The main loop continuously displays the OPTION_REG and INTCON registers on PORTC with a delay.

Uploaded by

tpgitspotify
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// CONFIG

#pragma config FOSC = EXTRC // Oscillator Selection bits (RC oscillator)


#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial
Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for
programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data
EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write
protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code
protection off)

// #pragma config statements should precede project file includes.


// Use project enums instead of #define for ON and OFF.

/*
* File: taskprograminterrupt.c
* Author: HAPPY
*
* Created on June 13, 2025, 11:10 PM
*/

#include <xc.h>
#define _XTAL_FREQ 6000000
void init(void);
unsigned value;

void main(void) {
init();
while(1)
{
PORTC=OPTION_REG;
__delay_ms(1000);
PORTC=INTCON;
__delay_ms(1000);
}
}
void init()
{
TRISC=0x00;
PORTC=0x00;
TRISD=0x00;
PORTD=0x00;
TRISB=0x0F;
PORTB=0x00;
INTCON &=0xFD; //clear the flag
OPTION_REG &=0xBF; //disable the option_reg
OPTION_REG |=0x80; // set the falling edge
INTCON |=0x90;
}
void __interrupt() _ISR(void)
{
if(INTCON & 0x02)
{
value=PORTB;
if(value==0x00) // 0000 0000
{
PORTD=0xFF;
__delay_ms(2000);
PORTD=0x00;
__delay_ms(1000);
}
}
__delay_ms(3000);
INTCON &=0xFD; //clear the flag
}

You might also like