When you declare variables inside a function, they do not retain their values after a return from the function unless you declare them "static":
void loop(){
static unsigned char i,j,k;
loop() is called repeatedly and returns repeatedly. That is definitely a problem for variable j.