Look up interrupt on change in you chips data sheet.