We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
i want to use my interrupt rotine for the different function in different c files;
main.c file
void my_fonction(void); data unsigned char switch_state ; void my_interrupr_rotine (void) IE0_VECTOR using 1 { switch_state = P1^3;//read switch } void main (void){ while(1){ if(switch_state){ //some thing } else my_function(); } }
and another c file
extern data unsigned char switch_state ; void my_fonction(void){ while (switch_state==0) { //somethings } }
my program enters in my_function, but in this function, the interrupt routine isnt working, what is the solutuion?(or is tehere any solution?) im seraching in google andkeil database "interrupt modular" ,"interrupt extern" "interrupt global" etc. i havent found anything
i forgot to write my message, i initilize in my program my interrupt enables(EA extrenal interrupt enable) at main
but the problem remain (sorry for my english)
"the interrupt routine isnt working"
What do you mean by, "isn't working" ?
Does the interrupt handler get called? Does it read the port OK?
Have you tried it in the Simulator?
switch_state = P1^3; //read switch
What precisely do you think this line is doing?
Note that the '^' here is the standard ANSI 'C' bitwise Exclusive-OR operator - is that what you intended?
when i writed, my_interrupr_routine , main and my_function functions in the same files , the program working very well (no problem) but i i have alot of functions and i want to use modular programming, for this; i create a lot of c file for my_function and others functions, in this case, my main function is working well (also interrupt servis rotine, my switch_state is changing when i switched my button in main.c) also another function in another files are working but switch_state isn't changing when i switched my button. switch_state = P1^3; instead of orginally in my program: switch_state =PSD_reg.DATAIN_A ; i only want to explain i only read my buton situation in interrupt servis routine and this is working when i write all my function in same file, (repeat sory for english , i wish i can explain my prolem)
sounds like your "global" switch_state variable is not actually global.
Are you using a header file for the 'extern' declaration? If not, there is a very high risk that you will make a slight type somewhere and your different files will be referencing different data
main.c
#include "main.h" // Including this here ensures that the extern declaration // of switch_state matches the actual definition data unsigned char switch_state ; void my_interrupr_rotine (void) IE0_VECTOR using 1 { switch_state = P1^3; //read switch }
main.h
extern data unsigned char switch_state ;
other.c
#include "main.h" // Provide extern declaration of switch_state void my_fonction(void) { while (switch_state==0) { //somethings } }
c-faq.com/.../decldef.html
thank you for your reply, i was use extern decleration only in another file, not in main file becouse i didnt know, i tried this exactly as you tell, but the trouble remaining, switch_state is changing only when the program in main.c file if, in another file there is no change on switch_state. is keil has got any rule about interrupt routines, suchlike; the interrupt rotines are active only when te program executuion statement is on the same file with interupt routine.
"i was use extern decleration only in another file, not in main file becouse i didnt know, i tried this exactly as you tell"
There is only any point in doing this if you use a header file!
Are you using a header file?
"is keil has got any rule about interrupt routines, suchlike; the interrupt rotines are active only when te program executuion statement is on the same file with interupt routine."
Absolutely not.
thank you very much ! my program now working, i am using header files, also the problem was in the one of this header files one my variable structure; xdata volatile PSD_REGS PSD_reg _at_ PSD_REG_ADDR; and its extern line at header file is; extern xdata PSD_REGS PSD_reg _at_ PSD_REG_ADDR; when i writing ,i forgot volatile keyword, (i think may be optimiser didnt take care of on switch port changing whitout volatile (port d which is contrlled by PSD_REGS )) and i didnt see this very long time. i cant paste all my code here becouse the program nearly 700 line, if i can paste here , most probably you can see the wrong line, in one minute:) thanks