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.

[SOLVED] Interrupt instead of delay function in mikroc

Status
Not open for further replies.

sonar_abhi

Member level 1
Joined
Mar 15, 2016
Messages
36
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Activity points
380
Hello all,

Can anybody please explain to me how does this particular code work in mikroc. The timer is set to overflow every 32ms. Thus, the following code toggles the PortB pins roughly every 1 second.

Initinterrupt ()
{
======;
======;
}

Interrupt()
{
========;
========;
timerint++;
}

Void main ()
{
Initinterrupt();
TRISB =0;
PORTB =0;
while (1)
{
if (timerint==32)
{
PORTB=~PORTB;
timerint=0;
}
}


So far so good,
But if I set the PortB value after while loop, the timer function does not work as expected.
Can someone explain me why so. The above code is just an abstraction of an another function that I am using which isn't working as expected. Will post that function also tomorrow.

Regards,
Abhishek
 

while(1) means loop forever. All code after this condition will not be executed.
Excep if you are using RTOS.
 

Yes, that I understand. All the code in my program is contained within the while (1) loop since we require it to work continuously.
 

hello,


in this case Timer1 (with it's associated interupt service) will do
all the job

Code:
Initinterrupt ()
{
======;
======;
}

Interrupt()
{
========;
========;
timerint++;
 if (timerint==32)
  {
   PORTB=~PORTB;
   timerint=0;
  }
}

Void main ()
{
Initinterrupt();
TRISB =0;
PORTB =0;
while (1)
{
  // do nothing !
}
}
 

Hello,

I'll just paste the code I'm having trouble with...

void shiftdata(char _shiftdata)
{
char i;
char temp;
int m,n;
temp = _shiftdata;
i=8;
while (i>0)
{
if (temp.F7==0)
{
SHIFT_DATA1 = 0;
}
else
{
SHIFT_DATA1 = 1;
}

temp = temp<<1;
SHIFT_CLOCK1 = 1;
if (latdelay == 3){
//Delay_ms(100);
SHIFT_CLOCK1 = 0;
i--;
latdelay = 0;
}
}
}

in the above code, if I comment the latdelay part of the code and replace it by the delay, the program works perfectly. Also if I comment out the latdelay = 0, the program works as expected except very fast thus rendering it useless.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top