打印

MDK 中 if 比较不正确

[复制链接]
1997|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 Volftooth 于 2012-5-30 16:42 编辑

在 KEIL MDK 中写了这样一句代码、
if(LCD_ReadReg(0) == 0x5408)
{
....
}

但是不管是不是 5408H、都会执行 IF 里面的代码、这是怎么回事?、
看汇编代码里面并没有生成跳转的代码、
MOVS R0, #0x00
BL.W  LCD_ReadReg(0)
SUB    R1, R0, #0x5400

然后就没了啊.........
谁能解释一下子、、

相关帖子

沙发
ayb_ice| | 2012-5-30 16:52 | 只看该作者
SUB    R1, R0, #0x5400

看你的汇编代码都不对,是不是对应的汇编文件都是问题

使用特权

评论回复
板凳
Volftooth|  楼主 | 2012-5-30 16:58 | 只看该作者
2# ayb_ice
我把优化关掉了、可以正常判断 if、生成的汇编代码如下、
0x08006D44 2000      MOVS     r0,#0x00
0x08006D46 F7FDF95F  BL.W     LCD_ReadReg (0x08004008)
0x08006D4A F5A041A8  SUB      r1,r0,#0x5400
0x08006D4E 3908      SUBS     r1,r1,#0x08
0x08006D50 D17D      BNE      0x08006E4E


但就不知道我程序哪里让它认为可以优化了.........

使用特权

评论回复
地板
ayb_ice| | 2012-5-30 17:31 | 只看该作者
我试了一下,优化级别3,没有问题

未命名.JPG (11.83 KB )

未命名.JPG

使用特权

评论回复
5
ayb_ice| | 2012-5-30 17:32 | 只看该作者
RT

未命名.JPG (15.62 KB )

未命名.JPG

使用特权

评论回复
6
Volftooth|  楼主 | 2012-5-30 17:34 | 只看该作者
下面是整个函数的代码、我怎么都看不出来哪里可优化、
我用 O0 级就可以、用 O3 级就不行、

void STM3210E_LCD_Init(void)
{
/* Configure the LCD Control pins --------------------------------------------*/
  LCD_CtrlLinesConfig();

/* Configure the FSMC Parallel interface -------------------------------------*/
  LCD_FSMCConfig();

  Delay(5); /* delay 50 ms */

  /* Check if the LCD is SPFD5408B Controller */
  if(LCD_ReadReg(0x00) == 0x5408)
  {
    /* Start Initial Sequence ------------------------------------------------*/
    LCD_WriteReg(R1, 0x0100);  /* Set SS bit */
    LCD_WriteReg(R2, 0x0700);  /* Set 1 line inversion */
    LCD_WriteReg(R3, 0x1030);  /* Set GRAM write direction and BGR=1. */
    LCD_WriteReg(R4, 0x0000);  /* Resize register */

    LCD_WriteReg(R8, 0x0202);  /* Set the back porch and front porch */
    LCD_WriteReg(R9, 0x0000);  /* Set non-display area refresh cycle ISC[3:0] */
    LCD_WriteReg(R10, 0x0000); /* FMARK function */
    LCD_WriteReg(R12, 0x0000); /* RGB 18-bit System interface setting */
    LCD_WriteReg(R13, 0x0000); /* Frame marker Position */
    LCD_WriteReg(R15, 0x0000); /* RGB interface polarity, no impact */

    /* Power On sequence -----------------------------------------------------*/
    LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
    LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
    LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
    Delay(20);                 /* Dis-charge capacitor power voltage (200ms) */

    LCD_WriteReg(R17, 0x0007);        /* DC1[2:0], DC0[2:0], VC[2:0] */
    Delay(5);                   /* Delay 50 ms */
    LCD_WriteReg(R16, 0x12B0);        /* SAP, BT[3:0], AP, DSTB, SLP, STB */
    Delay(5);                        /* Delay 50 ms */
    LCD_WriteReg(R18, 0x01BD);  /* External reference voltage= Vci */
    Delay(5);
    LCD_WriteReg(R19, 0x1400);  /* VDV[4:0] for VCOM amplitude */
    LCD_WriteReg(R41, 0x000E);  /* VCM[4:0] for VCOMH */
    Delay(5);                   /* Delay 50 ms */
    LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */
    LCD_WriteReg(R33, 0x013F); /* GRAM Vertical Address */

    /* Adjust the Gamma Curve (SPFD5408B)-------------------------------------*/
    LCD_WriteReg(R48, 0x0b0d);
    LCD_WriteReg(R49, 0x1923);
    LCD_WriteReg(R50, 0x1c26);
    LCD_WriteReg(R51, 0x261c);
    LCD_WriteReg(R52, 0x2419);
    LCD_WriteReg(R53, 0x0d0b);
    LCD_WriteReg(R54, 0x1006);
    LCD_WriteReg(R55, 0x0610);
    LCD_WriteReg(R56, 0x0706);
    LCD_WriteReg(R57, 0x0304);
    LCD_WriteReg(R58, 0x0e05);
    LCD_WriteReg(R59, 0x0e01);
    LCD_WriteReg(R60, 0x010e);
    LCD_WriteReg(R61, 0x050e);
    LCD_WriteReg(R62, 0x0403);
    LCD_WriteReg(R63, 0x0607);

    /* Set GRAM area ---------------------------------------------------------*/
    LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */
    LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */
    LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */
    LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */

    LCD_WriteReg(R96,  0xA700); /* Gate Scan Line */
    LCD_WriteReg(R97,  0x0001); /* NDL, VLE, REV */
    LCD_WriteReg(R106, 0x0000); /* set scrolling line */

    /* Partial Display Control -----------------------------------------------*/
    LCD_WriteReg(R128, 0x0000);
    LCD_WriteReg(R129, 0x0000);
    LCD_WriteReg(R130, 0x0000);
    LCD_WriteReg(R131, 0x0000);
    LCD_WriteReg(R132, 0x0000);
    LCD_WriteReg(R133, 0x0000);

    /* Panel Control ---------------------------------------------------------*/
    LCD_WriteReg(R144, 0x0010);
    LCD_WriteReg(R146, 0x0000);
    LCD_WriteReg(R147, 0x0003);
    LCD_WriteReg(R149, 0x0110);
    LCD_WriteReg(R151, 0x0000);
    LCD_WriteReg(R152, 0x0000);

    /* Set GRAM write direction and BGR=1
       I/D=01 (Horizontal : increment, Vertical : decrement)
       AM=1 (address is updated in vertical writing direction) */
    LCD_WriteReg(R3, 0x1018);

    LCD_WriteReg(R7, 0x0112); /* 262K color and display ON */

    return;
  }
  
/* Start Initial Sequence ----------------------------------------------------*/
  LCD_WriteReg(R229,0x8000); /* Set the internal vcore voltage */
  LCD_WriteReg(R0,  0x0001); /* Start internal OSC. */
  LCD_WriteReg(R1,  0x0100); /* set SS and SM bit */
  LCD_WriteReg(R2,  0x0700); /* set 1 line inversion */
  LCD_WriteReg(R3,  0x1030); /* set GRAM write direction and BGR=1. */
  LCD_WriteReg(R4,  0x0000); /* Resize register */
  LCD_WriteReg(R8,  0x0202); /* set the back porch and front porch */
  LCD_WriteReg(R9,  0x0000); /* set non-display area refresh cycle ISC[3:0] */
  LCD_WriteReg(R10, 0x0000); /* FMARK function */
  LCD_WriteReg(R12, 0x0000); /* RGB interface setting */
  LCD_WriteReg(R13, 0x0000); /* Frame marker Position */
  LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */

/* Power On sequence ---------------------------------------------------------*/
  LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
  LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
  LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
  Delay(20);                 /* Dis-charge capacitor power voltage (200ms) */
  LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
  LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
  Delay(5);                  /* Delay 50 ms */
  LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
  Delay(5);                  /* Delay 50 ms */
  LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
  LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
  Delay(5);                  /* Delay 50 ms */
  LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */
  LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */

/* Adjust the Gamma Curve ----------------------------------------------------*/
  LCD_WriteReg(R48, 0x0006);
  LCD_WriteReg(R49, 0x0101);
  LCD_WriteReg(R50, 0x0003);
  LCD_WriteReg(R53, 0x0106);
  LCD_WriteReg(R54, 0x0b02);
  LCD_WriteReg(R55, 0x0302);
  LCD_WriteReg(R56, 0x0707);
  LCD_WriteReg(R57, 0x0007);
  LCD_WriteReg(R60, 0x0600);
  LCD_WriteReg(R61, 0x020b);
  
/* Set GRAM area -------------------------------------------------------------*/
  LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */
  LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */
  LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */
  LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */

  LCD_WriteReg(R96,  0x2700); /* Gate Scan Line */
  LCD_WriteReg(R97,  0x0001); /* NDL,VLE, REV */
  LCD_WriteReg(R106, 0x0000); /* set scrolling line */

/* Partial Display Control ---------------------------------------------------*/
  LCD_WriteReg(R128, 0x0000);
  LCD_WriteReg(R129, 0x0000);
  LCD_WriteReg(R130, 0x0000);
  LCD_WriteReg(R131, 0x0000);
  LCD_WriteReg(R132, 0x0000);
  LCD_WriteReg(R133, 0x0000);

/* Panel Control -------------------------------------------------------------*/
  LCD_WriteReg(R144, 0x0010);
  LCD_WriteReg(R146, 0x0000);
  LCD_WriteReg(R147, 0x0003);
  LCD_WriteReg(R149, 0x0110);
  LCD_WriteReg(R151, 0x0000);
  LCD_WriteReg(R152, 0x0000);

  /* Set GRAM write direction and BGR = 1 */
  /* I/D=01 (Horizontal : increment, Vertical : decrement) */
  /* AM=1 (address is updated in vertical writing direction) */
  LCD_WriteReg(R3, 0x1018);

  LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */  
}

使用特权

评论回复
7
平常人| | 2012-5-31 00:30 | 只看该作者
看不到定义,怀疑是LCD_ReadReg函数类型的问题,与比较对象不匹配。

使用特权

评论回复
8
ayb_ice| | 2012-5-31 09:42 | 只看该作者

LCD_ReadReg
函数源代码帖出来

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:好想睡觉好想睡觉!! 困困困困困

14

主题

61

帖子

1

粉丝