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 write a program as following. I want to point a table for driving step motor to ccw or cw. But I cant access code table data. Please help me. Thanx.
#include <reg52.h>
void main(void) {
unsigned char code uc_code_SMCW_Table[8]={0x09,0x01,0x02,0x03,0x06,0x04,0x0c,0x08};
unsigned char code uc_code_SMCCW_Table[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
unsigned char code *uc_code_SM_Table_Ptr;
unsigned char data uc_data_SM_Table_Index;
uc_data_SM_Table_Index=1;
switch(uc_data_SM_Table_Index) {
case 1:
uc_code_SM_Table_Ptr=uc_code_SMCW_Table;
break;
case 2:
uc_code_SM_Table_Ptr=uc_code_SMCCW_Table;
}
//The result is not correct.
uc_data_SM_Table_Index=uc_code_SM_Table_Ptr[0];
I am very comfusion
Yes, I think you possibly are.
It is highly likely that the compiler is seeing that the result is not needed and optimising it out.
Do something with the result. Like maybe put it into a global variable or make the variable volatile.
u are right. I try to modify my program as following.
. . .
P0=uc_code_SM_Table_Ptr[0]; uc_data_Tmp=uc_code_SM_Table_Ptr[0];
The result is correct. I think I have something to learn. such as Compiler option.
Thanx u give me the suggestion.
u are right. I try to modify my program as following maybe micro (u) is right; however, generally, I would recommend always running with optimization 2 for the C51
Erik