Interesting problem but I cannot follow it. Please read the forum gujdelines and post your code according them using code tags. Post all of the code.
Guidelines: How to get the best out of this forum Also if there are hardware devices include links to there technical information and an annotated schematic showing how it is wired, be sure to include all power, grounds and power sources.