简体   繁体   English

MSP430 i var 在循环中间随机重置为值 0

[英]MSP430 i var randomly resets at value 0 in middle of loop

So I got this very strange problem that happens every time.所以我遇到了这个每次都会发生的非常奇怪的问题。 I am trying to interface and LCD with the MSP430 module.我正在尝试与 MSP430 模块连接和 LCD。 But in this function at the middle of the loop, the variable i resets itself to 0 for no apparent reason at all, somethimes it even crashes.但是在循环中间的这个 function 中,变量 i 完全没有明显的原因将自己重置为 0,有时甚至崩溃。
This is the structure of the lcd_t struct:这是 lcd_t 结构的结构:

    struct lcd_t
{   
    uint8_t rs, rw, e;
    uint8_t pin[8];
};

This is the function where i is defined and "reseted":这是 function,其中 i 被定义并“重置”:

    void
lcd_dat(const struct lcd_t* lcd, uint8_t dat)
{
  static uint8_t i;
  
  // Setting RS.
  //
  lcd_change_pin_state(lcd->rs, 1);
  
  // Setting each data pin to match the dat.
  //
  for(i = 0; i < 8; i++) // TODO: Four bit mode
  {
    
    if(dat & (1 << i))
    {
      lcd_change_pin_state(lcd->pin[i], 1);
    }
    
    else
    {
      lcd_change_pin_state(lcd->pin[i], 0); <-- This is where i resets
    }
    
  }
  
  // Setting E.
  //
  lcd_change_pin_state(lcd->e, 1);
  
  __delay_cycles(2*1000);
  
  // Clearing E.
  //
  lcd_change_pin_state(lcd->e, 0);
  
}

This is the function where i resets:这是我重置的 function:

static volatile void
lcd_change_pin_state(uint8_t pin, uint8_t newstate)
{
  
  if(newstate == 0)
  {
    
    if(pin/10 == 1)
    {
      P1OUT &= ~(1 << (pin % 10));
    }
    
    else
    {
      P2OUT &= ~(1 << (pin % 10));
    }
    
  }
  
  else
  {
    
    if(pin/10 == 1)
    {
      P1OUT |= (1 << (pin % 10));
    }
    
    else
    {
      P2OUT |= (1 << (pin % 10));
    }
    
  }
  
}

Plese tell me what other information do you need!请告诉我您还需要什么其他信息! Thanks!谢谢!

WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer

This instruction was missing...这条指令不见了……
I can't even think how much time was lost because of this...我什至无法想象为此浪费了多少时间……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM