khansaab21
Advanced Member level 4
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
}
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
}