global variable accessing problem

Status
Not open for further replies.

arecssor

Junior Member level 1
Joined
Feb 21, 2015
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
159
hi,
i tried to use interrupts in at8535 to perform a switch operation , am getting an error

my code


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <mega8535.h>
#include <alcd.h>
#include <delay.h>
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
x=1; // when int0 pressed x =1
}
interrupt [EXT_INT1] void ext_int1_isr(void)
{
x=2;
}
int x;// global variable declaration
void main(void)
 {
if(x=1)
{
lcd_putsf('int0');
}
else if(x==2)
{
lcd_putsf('int1');
 }
}

this is the format of the code am getting an error that ISR can't recognize the variable 'x', it shows undefined variable . i used code vision avr how can i resolve this issue
 

i declared the variable 'x' before void main function, even after that am getting the same error, you can see that a variable 'x' is declared before the void main function .
Code:
1

#include <mega8535.h>
#include <alcd.h>
#include <delay.h>
// External Interrupt 0 service routine
interrupt [EXT_INT0] void ext_int0_isr(void)
{
x=1; // when int0 pressed x =1
}
interrupt [EXT_INT1] void ext_int1_isr(void)
{
x=2;
}
int x;// global variable declaration
void main(void)
 {
if(x==1)
{
lcd_putsf('int0');
}
else if(x==2)
{
lcd_putsf('int1');
 }
}
please provide the code with proper variable declaration , so that i can understand the cause for the error , am using code vision avr for programming .

Thank you
 

Variable x is used in ISR so declare x before ISR. Make declarations in the first few lines of the code.
 

tried but no result , same response undefined variable
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…