This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with a simple vector manipulation! Help!

Hi. I'm using Phytec KC-161 eval board. During my project i found a a problem with vectors. So i tried to monitor the values of a simple unsigned int vector[6] after I initialize it. And i saw that the vector's elements don't take any values. The same problem with char aString[6]; manipulation. Why? What can cause this problem - the incorect settings of the project, or from hardware? I started from the project given for Phytec KC-161 (Blinky), from \Boards directory.

#include <reg161.h>
#include <stdio.h>
#include <string.h>

void setup_serial();

void main (void)  {
        unsigned int vector[6];
        unsigned int c=0,cnt=0;

        setup_serial();

        for(cnt=0; cnt<6; cnt++){
                vector[cnt] = 1;
                if(vector[cnt] != 1)
                        putchar('!');
                else
                        putchar('1');
        }

        while (1) {
        }
}

void setup_serial(){
  /* init physical memory model */
  BUSCON0 |= 0x003F;    /*; 0 Wait no Delay */

  /* initialize the serial interface     */
  P3  |= 0x0400;        /* SET PORT 3.10 OUTPUT LATCH (TXD)              */
  DP3 |= 0x0400;        /* SET PORT 3.10 DIRECTION CONTROL (TXD OUTPUT)  */
  DP3 &= 0xF7FF;        /* RESET PORT 3.11 DIRECTION CONTROL (RXD INPUT) */
  S0TIC = 0x80;         /* SET TRANSMIT INTERRUPT FLAG                   */
  S0RIC = 0x00;         /* DELETE RECEIVE INTERRUPT FLAG                 */
  S0BG  = 0x19;                 /* SET BAUDRATE TO 19200 BAUD AT 16MHZ           */
  S0CON = 0x8011;       /* SET SERIAL MODE                               */
}

Thank you.

Parents
  • And i saw that the vector's elements don't take any values.

    Modern compilers optimize code. In the code you presented the condition of the if statement is always false, and, in all likelihood, the compiler knew that. Most likely, the compiler did not allocate the array, so there was no variable to watch in the debugger.
    Set optimization level to minimum and see if anything changes.

    Regards,
    - mike

Reply
  • And i saw that the vector's elements don't take any values.

    Modern compilers optimize code. In the code you presented the condition of the if statement is always false, and, in all likelihood, the compiler knew that. Most likely, the compiler did not allocate the array, so there was no variable to watch in the debugger.
    Set optimization level to minimum and see if anything changes.

    Regards,
    - mike

Children