Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C18 Code not working

Status
Not open for further replies.

vicky001.iith

Advanced Member level 4
Full Member level 1
Joined
Aug 5, 2013
Messages
113
Helped
37
Reputation
74
Reaction score
31
Trophy points
48
Location
INDIA
Visit site
Activity points
721
Hello everyone,I am facing a problem.The code given below is not working properly.
Code is whenever i gets an interrupt at PIN B2.Led should blink.But it is not working in the expected way.It doesn't enter in this loop.
Code:
      if (INTCON3bits.INT2IF == 1)
      {
              blink_RA();
              delay(200);
                 INTCON3bits.INT2IF = 0;
              }
    }

I am giving interrupt to pin B2 a 5V pulse.

CODE :-
Code:
include <p18f26k22.h>
//#include <adc.h>
#pragma config PLLDIV=1,IESO=OFF
#pragma config WDT=OFF,PWRT=ON,BOR=OFF,PBADEN=OFF
#pragma config DEBUG=OFF,STVREN=ON,FCMEN=OFF
#pragma config LVP=OFF,MCLRE = OFF,XINST=OFF
#pragma config EBTR0=OFF,EBTR1=OFF,EBTRB=OFF
#pragma config WRT0=OFF,WRT1=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF
#pragma config CP0=OFF,CP1=OFF,CPB=OFF,CPD=OFF

#define FOSC_FREQ  (unsigned long)11059200	// 11.0592 MHz
void chk_isr(void);				//checks if int1 set the interrupt
void INT1_ISR(void);
void blink_RA();

#pragma code My_HiPrio_Int = 0x08  // high-priority interrupt location
void My_HiPrio_Int (void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma code
#pragma interrupt chk_isr // used for high-priority interrupt only

void chk_isr (void)
{
if (INTCON3bits.INT1IF==1)	//INT1 causes interrupt?
INT1_ISR();	//YES. Execute INT1 program
}
void INT1_ISR(void)
{
    blink_RA();
INTCON3bits.INT1IF=0;		//clear INT1 flag
}

void delay(unsigned char time);
void blink_RA2();
void blink_RA1();

void delay(unsigned char time)
{
    unsigned char i,j;


                for(i=0;i<250;i++)
                {
                        for(j=0;j<250;j++);
                }
}

void blink_RA2()
{
	TRISCbits.TRISC0 = 0;
        TRISCbits.TRISC1 = 0;
	LATCbits.LATC1 = 1 ;\
        LATCbits.LATC0=0;

        delay(50);
}
void blink_RA1()
{
    	TRISCbits.TRISC0 = 0;
        TRISCbits.TRISC1 = 0;
	LATCbits.LATC1 = 0 ;\
        LATCbits.LATC0=1;

        delay(50);
}
void blink_RA()
{
	TRISCbits.TRISC0 = 0;
        TRISCbits.TRISC1 = 0;
	LATCbits.LATC1 = 1 ;\
        LATCbits.LATC0 = 1;
        delay(50);
}
void main()
{
    TRISBbits.TRISB2 = 1; // pir input
    	INTCON3bits.INT1IF=0;	//	clear int1
	INTCON3bits.INT1IE=1;	//	enable int1 interrupt
	//INTCON2bits.INTEDG1=0;	//	make it positive edge
	INTCON2bits.RBPU=1;
	INTCONbits.GIE=1;		//	enable all interrupts
	INTCONbits.GIE=0;		//	Disable all interrupts
        ADCON1 = 0x0F;              //all digital I/O
        blink_RA2();
        delay(50);
        blink_RA2();
        delay(50);
    while(1)
    {
        blink_RA1();
        blink_RA2();
      //  blink_RA();
      if (INTCON3bits.INT2IF == 1)
      {
              blink_RA();
              delay(200);
                 INTCON3bits.INT2IF = 0;
              }
    }

}
 

Hello everyone,I am facing a problem.The code given below is not working properly.
Code is whenever i gets an interrupt at PIN B2.Led should blink.But it is not working in the expected way.It doesn't enter in this loop.
Code:
      if (INTCON3bits.INT2IF == 1)
      {
              blink_RA();
              delay(200);
                 INTCON3bits.INT2IF = 0;
              }
    }

I am giving interrupt to pin B2 a 5V pulse.

CODE :-
Code:
include <p18f26k22.h>
//#include <adc.h>
#pragma config PLLDIV=1,IESO=OFF
#pragma config WDT=OFF,PWRT=ON,BOR=OFF,PBADEN=OFF
#pragma config DEBUG=OFF,STVREN=ON,FCMEN=OFF
#pragma config LVP=OFF,MCLRE = OFF,XINST=OFF
#pragma config EBTR0=OFF,EBTR1=OFF,EBTRB=OFF
#pragma config WRT0=OFF,WRT1=OFF,WRTB=OFF,WRTC=OFF,WRTD=OFF
#pragma config CP0=OFF,CP1=OFF,CPB=OFF,CPD=OFF

#define FOSC_FREQ  (unsigned long)11059200	// 11.0592 MHz
void chk_isr(void);				//checks if int1 set the interrupt
void INT1_ISR(void);
void blink_RA();

#pragma code My_HiPrio_Int = 0x08  // high-priority interrupt location
void My_HiPrio_Int (void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma code
#pragma interrupt chk_isr // used for high-priority interrupt only

void chk_isr (void)
{
if (INTCON3bits.INT1IF==1)	//INT1 causes interrupt?
INT1_ISR();	//YES. Execute INT1 program
}
void INT1_ISR(void)
{
    blink_RA();
INTCON3bits.INT1IF=0;		//clear INT1 flag
}

void delay(unsigned char time);
void blink_RA2();
void blink_RA1();

void delay(unsigned char time)
{
    unsigned char i,j;


                for(i=0;i<250;i++)
                {
                        for(j=0;j<250;j++);
                }
}

void blink_RA2()
{
	TRISCbits.TRISC0 = 0;
        TRISCbits.TRISC1 = 0;
	LATCbits.LATC1 = 1 ;\
        LATCbits.LATC0=0;

        delay(50);
}
void blink_RA1()
{
    	TRISCbits.TRISC0 = 0;
        TRISCbits.TRISC1 = 0;
	LATCbits.LATC1 = 0 ;\
        LATCbits.LATC0=1;

        delay(50);
}
void blink_RA()
{
	TRISCbits.TRISC0 = 0;
        TRISCbits.TRISC1 = 0;
	LATCbits.LATC1 = 1 ;\
        LATCbits.LATC0 = 1;
        delay(50);
}
void main()
{
    TRISBbits.TRISB2 = 1; // pir input
    	INTCON3bits.INT1IF=0;	//	clear int1
	INTCON3bits.INT1IE=1;	//	enable int1 interrupt
	//INTCON2bits.INTEDG1=0;	//	make it positive edge
	INTCON2bits.RBPU=1;
	INTCONbits.GIE=1;		//	enable all interrupts
	INTCONbits.GIE=0;		//	Disable all interrupts
        ADCON1 = 0x0F;              //all digital I/O
        blink_RA2();
        delay(50);
        blink_RA2();
        delay(50);
    while(1)
    {
        blink_RA1();
        blink_RA2();
      //  blink_RA();
      if (INTCON3bits.INT2IF == 1)
      {
              blink_RA();
              delay(200);
                 INTCON3bits.INT2IF = 0;
              }
    }

}

Code:
      if (INTCON3bits.INT2IF == 1)
      {
              blink_RA();
              delay(200);
                 INTCON3bits.INT2IF = 0;
              }
    }

Put this code into your ISR.
 

Tried this also.Still not working ...

What this functions means to?
void chk_isr (void);
void INT1_ISR(void);

which is your actual ISR?

Also U have disabled GI in your main. Check it once again...
 
I have defined these functions here.And i enabled GI in main(). Disabling GI was a silly mistake.
But It is not working.
 

Hey mathespbe, Thanks for your suggestion ... :smile:
It is working now .I forgot to initialize these things.
Code:
    OSCCONbits.SCS = 0; // system clock select primary oscillator block
    OSCCON2bits.PRISD = 1; // primary oscillator drive circuit on
    OSCCONbits.IDLEN = 1; // IDLE mode on SLEEP instruction

    ANSELA = 0x00; // make all pins digital
    ANSELC = 0x00;
    ANSELB = 0x00;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top