We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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.
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
You may also try defining the array as volatile.
Suvidh
Thanks for your answer. But I didn't specified that the problem is from the divice, not from the debuger. When I use debuger step by step the rusult is correct, it prints six of '1' at the serial window. But when the target is running alone (in hyper terminal) it prints six of '!' (incorrect or not like I expect).
It sounds like you have specified the wrong address and/or size for your RAM memory. When running in real hardware, your variables are stored in the "bit bucket". Some of your variables will look ok, because they are stored in registers, or parts of the variables may have addresses within the RAM address space, and some outside.
Dear, Per Westermark It sounds like you have specified the wrong address and/or size for your RAM memory.
Thank you for explanation, but can you give me a solution? You mean that I have to modify the settings from options of the project?