#define of inline asm

General discussion on mikroC.
Post Reply
Author
Message
dgoadby
Posts: 18
Joined: 01 Aug 2005 07:03

#define of inline asm

#1 Post by dgoadby » 02 Aug 2005 17:10

I needed lots of inline clrwdt instructions so I decided to try this:

#define CLEARDOG asm { clrwdt }

This does not work. The expanded code looks like this:

asm{ clrwdt } ; and the compiler rejects the next line as invalid assembler.

After much messing about it seems that the compiler requires a line end before the final braces. So the code that does work looks like this:
asm{clrwdt
};

This seems a little quirky to me. I cant seem to force an inline line end. Any ideas on a workaround for this?

A function call would work but the overhead is excessive as the compiler can't be forced to do an inline expansion.
Last edited by dgoadby on 04 Aug 2005 23:47, edited 1 time in total.
David Goadby

Storic
Posts: 393
Joined: 01 Oct 2004 00:20
Location: Australia (S.A.)

#2 Post by Storic » 03 Aug 2005 01:05

Have you tried to reset the WDT within an interupt

Code: Select all

void interupt() {
  cnt++;               // Increment value of cnt on every interupt
  TMR0L  = 96;
  INTCON = 0x20;       // Set T0IE, clear T0IF
  if (cnt == 400) {
     PORTA.f3 = ~PORTA.f3;  //CPU Led heart beat
     cnt = 0;          // Reset cnt
     asm CLRWDT ;      // Reset watch dog timer
     }
}//~
The above gives me an aprox 1 sec CPU pulse and reset the WDT at every pulse.

Andrew

pizon
mikroElektronika team
Posts: 823
Joined: 11 Oct 2004 08:53

#3 Post by pizon » 03 Aug 2005 08:04

Try this:

Code: Select all

#define CLEARWDOG asm  CLRWDT
...
void main() {
  ...
  CLEARWDOG;
  ...
}
pizon

Storic
Posts: 393
Joined: 01 Oct 2004 00:20
Location: Australia (S.A.)

#4 Post by Storic » 03 Aug 2005 23:44

Thanks,
I have learnt something
I have added into my code

Code: Select all

#define CLEARWDOG asm  CLRWDT
#define CPU_Led PORTA.f3
...
     CPU_Led = ~CPU_Led;   //CPU Led heart beat
     cnt = 0;              // Reset cnt
     CLEARWDOG ;           // Reset watch dog timer
And WORKS :)

Andrew

dgoadby
Posts: 18
Joined: 01 Aug 2005 07:03

#5 Post by dgoadby » 04 Aug 2005 23:43

Thanks "pizon" it does work fine. I am not sure why though...

Thanks to Andrew for highlighting another idea that I have already found a good use for. :lol:
David Goadby

Post Reply

Return to “mikroC General”