int encoderPos=0,A,B,N=0,TD,given,address=0,ad;
Getyourspacekeyfixed. There is no excuse for jamming the declarations together without white space.
duration1=pulseIn(encoderPinA,HIGH);
duration1=pulseIn(encoderPinA,HIGH);
if(duration1==duration2){
Are both values supposed to be stored in duration1?
Inconsistent placement of curly braces sucks. Put EVERY { on a line BY ITSELF.
Your indenting sucks. Use Tools + Auto Format, so you can fake knowing what you are doing.
Serial.print("GIVEN ADDRESS=");
Serial.print(ad);
Serial.print("\t");
Serial.print("DATA");
Serial.print(TD);
Why is the value in TD jammed up against DATA? Spaces are cheap. Here are some for you to copy and paste where you need them.