打印

请教张教主程序优化问题

[复制链接]
1832|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
TIANDIRENAI|  楼主 | 2009-9-5 12:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
芯片:MC68HC908LK24
环境:freescale codewarrior 6.2
问题:部分程序被编译器干掉,甚至一些对寄存器赋值语句
      NumberByte = 0;
        SPDR = 0xd;
        断点没有办法设置到这两个语句,两条语句也没有被执行,编译时没有任何提示信息。
源代码:
#include <MC68HC908LK24.h>             /* I/O map for MC68HC908LK24CFQ */
#include "MCUinit.h"
#include "main.h"

#ifdef __cplusplus
extern "C"
#endif


extern unsigned char StateSPIDEV;
extern unsigned char StateSPIen;
extern unsigned char StateSPICounter;
extern unsigned char NumberByte;



void SPIProcess(void)
{
  if(StateSPIDEV == 1)
  {                     
    StateSPIDEV = 2;
    CS_ADE = 0;
    StateSPICounter = 0;
    StateSPIen = 1;
   
    NumberByte = 0;
    SPDR = 0xd;
  }
  else if(StateSPIDEV == 4)
  {     
    CS_ADE = 0;
    StateSPIDEV = 5;
    NumberByte = 0;
    SPDR = 0xd;   
  }
  else if(StateSPIDEV == 7)
  {     
    CS_ADE = 0;
    StateSPIDEV = 8;
    NumberByte = 0;
    SPDR = 0xd;   
  }
  else if(StateSPIDEV == 10)
  {      
    CS_ADE = 0;
    StateSPIDEV = 11;
    NumberByte = 0;
    SPDR = 0xd;   
  }
  else if(StateSPIDEV == 13)
  {  
    CS_ADE = 0;
    StateSPIDEV = 14;
    NumberByte = 0;
    SPDR = 0xd;   
  }
  else if(StateSPIDEV == 15)
  {
    CS_ADE = 0;
    StateSPIen = 0;
    StateSPICounter = 0;   
  }
}


void VoltageInterruptProcess(void)
{
  unsigned char tmpt;
  
  NumberByte++;
  if(NumberByte == 1) SPDR = 0x55;
  else if(NumberByte == 2) SPDR = 0x55;
  else if(NumberByte == 3) SPDR = 0x55;
  
  else if(NumberByte == 4)
  {
    CS_ADE = 1;
//    tmpt = 2;
    tmpt = 4;
    CS_ADE = 1;
//    tmpt = 2;
    tmpt = 4;   
    SPDR = 0xe;
  }
  else if(NumberByte == 5) SPDR = 0x55;
  else if(NumberByte == 6) SPDR = 0x55;
  else if(NumberByte == 7) SPDR = 0x55;

  else if(NumberByte == 8)
  {
    CS_ADE = 1;
//    tmpt = 2;
    tmpt = 4;
    CS_ADE = 1;
//    tmpt = 2;
    tmpt = 4;   
    SPDR = 0xe;
  }
  else if(NumberByte == 9) SPDR = 0x55;
  else if(NumberByte == 10) SPDR = 0x55;
  else if(NumberByte == 11) SPDR = 0x55;
  else if(NumberByte == 8)
  {
    CS_ADE = 1;
    NumberByte = 0;
    StateSPIDEV++;        
  }   

}

相关帖子

沙发
张明峰| | 2009-9-5 22:06 | 只看该作者
没事的啦。
你重复了这两条指令好几遍,编译器帮你生成一个函数然后重复调用以便节约代码空间。看汇编代码执行过程就明白了。

使用特权

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

本版积分规则

1

主题

1

帖子

0

粉丝