Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

some code

Status
Not open for further replies.

aibelectronics

New Member
yesterday i was trying to compile this code and all the while i was getting: "Declaration syntax error" on my_isr() and function main itself!!

#include <stdio.h>

void interrupt (*oldhandler)()
void interrupt my_isr()

int main()
{
int j=0, flag=0;

oldhandler =getvect(0x08);
setvect(0x08,my_isr);
outportb(0x21, inportb(0x21) & 0xFE); /*enable IRQ 0*/
if (flag=1 && !kbhit)
{
printf("welcome to interrupt routine/n");
}
return 0;
}


void interrupt my_isr()
{
if (j=1000)
{
flag=0;
j=0}
else
j++;
outportb(0x20,0x20); /*interrupt routine has been processed*/
}

What could be the problem?
 
reply

I'm using turbo C.

Actually I'm trying to hook up the timer interrupt (8253). I'm trying to see if I can print the "welcome to interrupt routine" a certain number of times i.e once in (54.2 * 1000) secs, i.e approximately 1 minute.

The 54.2ms is the speed of the 8253 timer if I might add. I want j to run from 0 to 1000 before the ISR sets the flag, so that the necessary action is done only after that time might have elapsed.

I'm actually trying to simulate a portion of a LARGER program I'm trying to build.
 
reply

well i'm not sure i fully understand what you mean by 'dos application'?
yes turbo c is a dos based compiler, but it's not that i'm booting my system up from dos, there is an IDE that comes with the compiler which i'm using. i'm using windows 98 by the way.
i guess the problem would still be there if i was to run the program with the more modern compilers? say salford, lcc or gcc?

the problem has something to do with my function declarations i guess, but i can't exactly figure out what...
 
reply

now megamox that is a very strong point!
obviously since i've declared j in main, it'll be illegal for my_isr to alter its value?
or I could just decide to make it a pointer variable, *j?
I just hope the problem ends there...
 
"j" can be in the ISR if you declare it "static" in that context.
"flag" should be global and declared "volatile".
Unless there's some difference with Turbo C I don't know about, "j=1000" means assign 1000 to j and return 1. This is not what you want. Testing if j is 1000 is "if (j==1000)". Same with the flag=1 test.

It is preferrable to say "if(j>=1000)", in case some later development makes it possible to snafu it.
 
Yeah if you want a test for j equal to 1000, you use if (j==1000). Otherwise you'll be assigning the value of 1000 to j.

Megamox
 
reply

it's very strange, but the problem seems to persist: "DECLARATION SYNTAX ERROR".
would how i declare a variable, or assign a value to it actually affect the declaration syntax of any of my functions?
 
reply

an ;? I'm not sure I've seen functions declarations have them...

(later) or I'm mistaken? I've just seen a couple :lol:
 
Functions with code bodies enclosed with {} don't end with ;
All other declarations end with ;
That includes function declarations that don't have {}
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top