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.

Interrupt trouble in PIC

Status
Not open for further replies.

khansaab21

Advanced Member level 4
Joined
Apr 12, 2008
Messages
108
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,298
Activity points
2,214
Device: PIC16F628A
Compiler: MikroC
Language: C

I have to use two interrupt services of the controller. The interrupts are of External interrupt and Serial Receive.

But the problem is code is not working on hardware. I guess there is something wrong with my code. Following is the code snippet.

void interrupt()
{
if (INTCON.INTF = 1) //If external interrupt
{
TRISB.F0 = 1; //Making it input for picking up states at reqiured delays

start_delay; //delay of 444 uS
start1 = ip;
bit_delay;
start2 = ip;

bit_delay; //Delay of 1778 uS
toggle = ip;

for (i = 0; i <= 4; i ++) //Address bits
{
bit_delay;
addr = ip;
}

for (i = 0; i <= 5; i ++) //Command bits
{
bit_delay;
comm = ip;
}
test_inst(); //Calling the function to process instruction
} //Interrupt flag is cleared in the called instruction.

else if (PIR1.RCIF = 1) //If in PC then
{
x = Usart_Read(); //Receiving data from PC

switch(x)
{
case 'A': {forward(); break;}
case 'B': {backward(); break;}
case 'C': {right(); break;}
case 'D': {left(); break;}
case 'E': {stop(); break;}
}
PIR1.RCIF = 0; //Clearing USART receive interrupt flag bit
}
}

//Start of main program

void main()
{
TRISA.F0 = 0; //Making PORTA as output
TRISA.F1 = 0;
TRISA.F2 = 0;
TRISA.F3 = 0;

TRISB.F4 = 0; //Making PORTB.F4 as output (error indicator)
error = 0;

Usart_Init(2400); //Initializing serial Baud Rate at 2400

//Enabling interrupts

INTCON.GIE = 1; //Enabling global interrupts
INTCON.PEIE = 1; //Enalbling peripheral interrupts

//Enabling serial interrupts

PIR1.RCIF = 0; //Clearing USART receive interrupt flag bit
PIE1.RCIE = 1; //Enabling USART receive inteerupt

//Enabling external interrupt

INTCON.INTF = 0; //Clearing external interrupt flag
INTCON.INTE = 1; //Enabling external interrupt
OPTION_REG.INTEDG = 1; //External interrupt on rising edge

while(1); //Stay here until interrupted
}
 

Hi khansaab21,

Please tell us what output you are expecting and what you are getting now. How frequently is your external interrupt occuring? I think interrupt service routine for external interrupt is consuming some time and if an interrupt occurs during this period it won't be serviced.
 

Thank you very much matfob for replying. But the good news is problem has been trouble shooted. Checking the interrupt flag in the ISR was givig trouble and i have found a way to do the same thing but with other piece of code.
 

if (INTCON.INTF = 1) ?? This assigns 1 to INTCON.INTF

else if (PIR1.RCIF = 1) ?? ?? This assigns 1 to PIR1.RCIF

in C, the test for equality is if(INTCON.INTF == 1)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top