the for loop is being skipped. Does not changes value of PKD_BCD.
for(i = 0; i < 10; i++)
{
x = ASCII_1[i] - '0';
y = ASCII_2[i] - '0';
PKD_BCD[i] = (x & 0x0f) | ((y << 4)& 0xf0);
}
the for loop is being skipped. Does not changes value of PKD_BCD.
for(i = 0; i < 10; i++)
{
x = ASCII_1[i] - '0';
y = ASCII_2[i] - '0';
PKD_BCD[i] = (x & 0x0f) | ((y << 4)& 0xf0);
}
What you are observing may depend upon:
welcome to AVRFreaks.
Note that you can put the image in the post - where we can see it:
See Tip #1 in my signature, at the foot of my posts, for how to do that.
'Unknown location' most likely means that the whole thing is being optimised away[1] - do you ever do anything with the x, y, or PKD_BCD variables ?
Please post a minimum but complete program which illustrates the issue - Tip #1 also shows how to post source code.
On optimisation: https://www.avrfreaks.net/forum/tutcoptimization-and-importance-volatile-gcc (note that, although it focuses on GCC, the principles are general)
EDIT
[1] Or, as frog_jr said, it is out-of-scope at the point you tried to examine it.
This is why it's important to see the code in context.
#include <avr/io.h>
int main(void)
{
unsigned char ASCII_1[] = {'9','8','7','6','5','4','3','2','1','0'};
unsigned char ASCII_2[] = {'0','1','2','3','4','5','6','7','8','9'};
unsigned char PKD_BCD[10];
unsigned char x, y;
int i;
for(i = 0; i < 10; i++)
{
x = ASCII_1[i] - '0';
y = ASCII_2[i] - '0';
PKD_BCD[i] = (x & 0x0f) | ((y << 4)& 0xf0);
}
return 0;
}
This is my complete code. What do you mean by in-scope???
You didn't read the tip, then?
So that code never does anything with x, y, or PKD_BCD - so it most likely will be all optimised away.
Also note that you mustn't return from main() - the microcontroller has nowhere to return to.
What do you mean by in-scope???
C is a block-structured language - things defined within a block are not visible outside that block.
https://en.cppreference.com/w/c/language/scope
Here are some C learning & reference materials - including a free online textbook: https://blog.antronics.co.uk/201...
Please try my modified code:
#include <avr/io.h>
int main(void)
{
unsigned char ASCII_1[] = {'9','8','7','6','5','4','3','2','1','0'};
unsigned char ASCII_2[] = {'0','1','2','3','4','5','6','7','8','9'};
volatile unsigned char PKD_BCD[10]; //volatile ensures compilation
unsigned char x, y;
int i;
for(i = 0; i < 10; i++)
{
x = ASCII_1[i] - '0';
y = ASCII_2[i] - '0';
PKD_BCD[i] = (x & 0x0f) | ((y << 4)& 0xf0);
}
while (1) {
asm("nop"); //tread water
}
return 0; //never get here
}
Place a Breakpoint on the for() loop and a Breakpoint on the NOP statement. Run the Simulator in AS7.0.
View the PKDBCD[] array in hex e.g. as Locals
I covered something almost identical to the issues in this thread in this one from Sunday..