编译背景如下:
;IC BODY : STC12C5A32AD
;IDE : KEIL uV3 C51 COMPILER V8.16 8级优化
;OSCILLATOR : XTAL=12MHz
最近在原程序基础上修改程序,出现如下一个问题:
原程式中定义一数组:unsigned char xdata level_ad[16] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
后因需要修改为:unsigned char xdata level_ad[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
该数组上电后均会在外部EEPROM中读取数值添将数据补齐。
进行操作。
操作指令如下:
if(work_opt == w_pstart){
target_ad = level_ad[bar[level_bar]];
}
else if(work_opt == w_tstart){
target_ad = level_ad[bar[level_bar]];
}
else if(work_opt == w_wstart){
target_ad = watt_ad;
}
else if(work_opt == w_ad){
target_ad = level_ad[motor_level];
}
else{
target_ad = 0;
}
原始程式没有问题,修改后程式运行时:
执行 else if(work_opt == w_ad){
target_ad = level_ad[motor_level];}
语句,当motor_level = 0 ,target_add取得的值为255 问题点实际应该为0;执行其他语句时可得到实际值。
将语句更改为:
else if(work_opt == w_ad){
target_ad = level_ad[motor_level];
if(motor_level == 0)target_ad = level_ad[0];
}
编译后汇编代码如下:
163: else if(work_opt == w_ad){
C:0x4C61 E57C MOV A,program_no(0x7C)
C:0x4C63 B4101A CJNE A,#0x10,C:4C80
164: target_ad = level_ad[motor_level];
C:0x4C66 7451 MOV A,#level_ad(0x51)
C:0x4C68 257B ADD A,motor_level(0x7B)
C:0x4C6A F582 MOV DPL(0x82),A
C:0x4C6C E4 CLR A
C:0x4C6D 3400 ADDC A,#user1_bar(0x00)
C:0x4C6F F583 MOV hand_hight_time(0x83),A
C:0x4C71 E0 MOVX A,@DPTR
C:0x4C72 78A9 MOV R0,#target_ad(0xA9)
C:0x4C74 F6 MOV @R0,A
165: if(motor_level == 0)target_ad = level_ad[0];
C:0x4C75 E57B MOV A,motor_level(0x7B)
C:0x4C77 700E JNZ C:4C87
C:0x4C79 900051 MOV DPTR,#level_ad(0x0051)
C:0x4C7C E0 MOVX A,@DPTR
C:0x4C7D F6 MOV @R0,A
166: }
C:0x4C7E 8007 SJMP C:4C87
问题依旧。
附运行正常程序,改段代码编译:
163: else if(work_opt == w_ad){
C:0x4C59 E57B MOV A,work_opt(0x7B)
C:0x4C5B B41011 CJNE A,#0x10,C:4C6F
164: target_ad = level_ad[motor_level];
C:0x4C5E 78A8 MOV R0,#motor_level(0xA8)
C:0x4C60 E6 MOV A,@R0
C:0x4C61 2477 ADD A,#area4_opt(0x77)
C:0x4C63 F582 MOV hand_hight_time(0x82),A
C:0x4C65 E4 CLR A
C:0x4C66 3400 ADDC A,#user1_bar(0x00)
C:0x4C68 F583 MOV DPH(0x83),A
C:0x4C6A E0 MOVX A,@DPTR
C:0x4C6B 08 INC R0
C:0x4C6C F6 MOV @R0,A
165: }
C:0x4C6D 8004 SJMP C:4C73 |