Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hi there can any one help im programming a 16f877 pic from my isr i call one function but from that funtion various others are called. but when i return via the closing } the interrupt goes mad. Can any one help.
//-----------------------------INTERRUPT Routine------------------------------------
interrupt isr() //interrupt service routine
{
INTF = 0;
SubtimeI();
if ((RB1 = 0)&&(RB2 = 0))
{
SubtimeI();
if ((RB1 = 0)&&(RB2 = 0))
{
PrintMM1();
}
}
}
//***********TOP LEVEL MENU -- MAX,OPTIMAL,MIN LEVEL ADJUST--**********
void PrintMM1() //max level adjust menu
{
CLRSI();
for (a = 19; a < NN; a++)
{
PORTD = num[a];
LCDPI();
if (a == 29)
{
DisArrow();
a = 126;
}
}
while (loop1 != 0)
{
loop2 = 1;
//Delayms(50);
if ((RB2 = 0)&&(RB1 = 0))
{
loop1 = 0;
}
Delayms(50);
else if (RB1 == 1) //scroll
{
PrintMM2();
}
Delayms(50);
else if (RB2 == 1) // select
{
CLRSI();
for (a = 19; a < NN1; a++) //max level menu entered
{
PORTD = num[a];
LCDPI();
}
SubtimeI();
lev1 = max;
MM1();
}
}
}
void PrintMM2() //optimal level adjust menu
{
CLRSI();
for (a = 30; a < NN; a++)
{
PORTD = num[a];
LCDPI();
if (a == 40)
{
DisArrow();
a = 126;
}
}
while (loop1 != 0)
{
loop2 = 1;
Delayms(50);
if ((RB2 = 0)&&(RB1 = 0))
{
loop1 = 0;
}
Delayms(50);
else if (RB1 == 1) //scroll
{
PrintMM3();
}
Delayms(50);
else if (RB2 == 1) // select
{
CLRSI();
for (a = 30; a < NN2; a++) //optimal level menu entered
{
PORTD = num[a];
LCDPI();
}
SubtimeI();
lev1 = opt;
MM1();
}
}
}
void PrintMM3() //min level adjust menu
{
CLRSI();
for (a = 41; a < NN; a++)
{
PORTD = num[a];
LCDPI();
if (a == 51)
{
DisArrow();
a = 126;
}
}
while (loop1 != 0)
{
loop2 = 1;
Delayms(50);
if ((RB2 = 0)&&(RB1 = 0))
{
loop1 = 0;
}
Delayms(50);
else if (RB1 == 1) //scroll
{
PrintMM1();
}
Delayms(50);
else if (RB2 == 1) // select
{
CLRSI();
for (a = 41; a < NN3; a++) //min level menu entered
{
PORTD = num[a];
LCDPI();
}
SubtimeI();
lev1= min;
MM1();
}
}
}
//***************CURRENT LEVEL DISPLAY**********************
void DisplayLevI()
{
MN = 77;
X= 10;
CLRSI();
for (a = 59;a < MN; a++)
{
--X;
PORTD = num[a];
LCDPI();
if (a == 67)
{
a = lev;
}
if (X == 0)
{
a = 77;
}
}
}
//*************MIDDLE MENU --- INCREASE AND DECREASE---**********
void MM1()
{
CLRSI();
if (lev1 == 0x00) //Full Tank 11111111
{
lev = 67 ;
}
else if (lev1 == 0x01) //00000001
{
lev = 68 ;
}
else if (lev1 == 0x03) //00000011
{
lev = 69;
}
else if (lev1 == 0x07) //00000111
{
lev = 70;
}
else if (lev1 == 0x0F)// Tank half full 00001111
{
lev = 71;
}
else if (lev1 == 0x1F) // 00011111
{
lev = 72 ;
}
else if (lev1 == 0X3F) //00111111
{
lev = 73;
}
else if (lev1 == 0X7F) //01111111
{
lev = 74;
}
else if (lev1 == 0XFF)//Tank Empty 11111111
{
lev = 75;
}
Z = 2;
DisplayLevI();
while (loop2 != 0)
{
Delayms(50);
if ((RB2 = 0)&&(RB1 = 0)) //Enter
{
loop2 = 0;
}
Delayms(50);
else if (RB1 == 1) //Increment
{
if(lev1 == 0x01)
{
lev1 = 0x03;
MM1();
}
else if((lev1 == 0x00)||(lev1 == 0x03)||(lev1 == 0x07)||(lev1 == 0x0F)||(lev1 == 0x1F)||
(lev1 == 0X3F)||(lev1 == 0X7F)||(lev1 == 0XFF))
{
lev1 = (lev1 * 2) + 1;
MM1();
}
}
Delayms(50);
else if (RB2 == 1) //Decrement
{
if(lev1 == 0x01)
{
lev1 = 0x00;
MM1();
}
else if((lev1 == 0x03)||(lev1 == 0x07)||
(lev1 == 0x0F)||(lev1 == 0x1F)||
(lev1 == 0X3F)||(lev1 == 0X7F)||
(lev1 == 0XFF))
{
lev1 = (lev1 - 1) / 2;
MM1();
}
}
}
}
//-----------Display Arrow------------------------------------------------------------
void DisArrow()
{
RB4 = 0; //RS line
PORTD = 0x8E; //set cgram address
LCDPI(); // Clock data into lcd
RB4 = 1;
PORTD = 0x00;
LCDPI();
RB4 = 0; //RS line
PORTD = 0xCE; //set cgram address
LCDPI(); // Clock data into lcd
RB4 = 1;
PORTD = 0x01;
LCDPI();
RB4 = 0; //RS line
PORTD = 0x8F; //set cgram address
LCDPI(); // Clock data into lcd
RB4 = 1;
PORTD = 0x02;
LCDPI();
RB4 = 0; //RS line
PORTD = 0xCF; //set cgram address
LCDPI(); // Clock data into lcd
RB4 = 1;
PORTD = 0x03;
LCDPI();
}
//-------------------CLEAR, DELAY AND CLOCK IN LCD FUNCTIONS---------------------
void CLRSI()
{
RB4 = 0;
PORTD = 0x01;
LCDPI();
RB4 = 1;
}
void LCDPI()
{
RB5 = 0; //ENABLE
Delayms(50);
RB5 = 1; //ENABLE
Delayms(50);
}
void SubtimeI()
{
multime = 10;
while (multime != 0)
{
--multime;
Delayms(200);
}
}
I don't do C, but your entire premise is wrong from the beginning - I would suggest rewriting it from scratch, and doing the absolute minimum in the ISR, and no calls.
You're also making matters much worse using C as well, as you've no idea how many calls each section of C code might be generating.
You're also making matters much worse using C as well, as you've no idea how many calls each section of C code might be generating.