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.
My program works wrong because of c compiler's optimization. If I use "volatile" to declare some varibles and functions, the optimization will be affetced, and perhaps the program works well, but if I changed the program, I would have to add "volatile" to other varibles or functions. I have to try many times to make compiler compile my program "correctly" after change the program. Is there a way to remove optimization completely? I use #pragma SAVE #pragma OPTIMIZE(0) my_func1() { ...; } #pragma RESTORE but I know optimize level 0 doesn't mean no optimization, and my program can't be compiled correctly even at optimize level 0, if without "volatile" to most varibles and functions. I only use P0, P1 and P2, to read and write some IO lines. Compiler is keil c51 v6.12
I have found the real reason is the broken hardware! The AT89C52 I was using is damaged, and caused wrong IO. After using new AT89S52 instead of the old chip, everything OK. There is no bussiness about optimize and volatile varibles, it's a hardware fault. Thanks.