Make your loop variable an int
.
unsigned char
can’t exceed 255, so incrementing i
past that will wrap it to 0.
2*130
is 260, because the type of literal 2
is int
, and multiplying an int
by unsigned char
you get an int
.
Thus, when i
is an unsigned char
, your loop termination condition will never be satisfied since i
will always be less than 260, hence the infinite looping.