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.

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
 

arecssor

Junior Member level 1
Joined
Feb 21, 2015
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
159
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
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
524
Trophy points
1,393
Activity points
0
Variable x is used in ISR so declare x before ISR. Make declarations in the first few lines of the code.
 

arecssor

Junior Member level 1
Joined
Feb 21, 2015
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
159
tried but no result , same response undefined variable
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top