middledog 发表于 2008-2-27 09:43:02

马老师,我这段代码编译能通过,但走到init_device()内部就死住了,为什么呢?

我是用仿真器单步走的,会死在port_init()内部,注释掉port_init(),又会死在init_device()里面,
编这个小程序是为了测试外挂的32KRAM,起先定义为0X1100到0X90FF。虽然程序本身也会用到变量,但缺省
应该是放在内部RAM的吧?不会和被测试的外部RAM冲突吧?有可能是堆栈的问题吗?
#include <iom128v.h>
#include <macros.h>

void port_init(void)
{
PORTA = 0x00;
DDRA= 0x00;
PORTB = 0x00;
DDRB= 0x00;
PORTC = 0x00; //m103 output only
DDRC= 0x00;
PORTD = 0x00;
DDRD= 0x00;
PORTE = 0x00;
DDRE= 0x00;
PORTF = 0x00;
DDRF= 0x00;
PORTG = 0x00;
DDRG= 0x00;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV= 0x00; //xtal divider
XMCRA = 0x00; //external memory

port_init();

MCUCR = 0xC0;
EICRA = 0x00; //extended ext ints
EICRB = 0x00; //extended ext ints
EIMSK = 0x00;
TIMSK = 0x00; //timer interrupt sources
ETIMSK = 0x00; //extended timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}


main()
{
      unsigned char OriChar = 0;
      unsigned char ReadChar = 0;
      
                unsigned char* pChar = (unsigned char *)0x1100;
                unsigned char* pChar2 = (unsigned char *)0x7fff;
               
          init_devices();

      //AUXR = 0x00;
      //P10 = 0x00;
      PORTD = PORTD & 0xef;

      while(1)
      {
               OriChar = OriChar + 7;
               pChar = pChar + 1;
         
               if (pChar > (unsigned char *)0x7fFF) pChar = (unsigned char *)0x1100;
               
               *pChar = OriChar;
               ReadChar = *pChar;
               if( OriChar == ReadChar)
               {
                        
                        PORTE = PORTE | 0x10;
               }
               else
               {
                        
                        PORTE = PORTE & 0xef;
               }
      }
}

machao 发表于 2008-2-28 15:00:38

先检查你M128溶丝位配置工作方式为128方式吗?
页: [1]
查看完整版本: 马老师,我这段代码编译能通过,但走到init_device()内部就死住了,为什么呢?