please note:-
1. always use {} with all loop and if statements even though u need to execute single statement under it
2.declare all variables before initializing any variale...ur arrays are initialized after tmod and th1.
3.i used int w in delay as w<=255 will always be true for unsigned char type..i gives warning for that...