I'm afraid to tell you that your code did not complete compiling. I don't know what i'm missing also in my program.
I'm still a beginner CCS programmer so some times i find some things are suspicious ...
I'm always used to program my pic16f877a chip using pic c compiler v4.084 then a decided to install pic c compiler v5.015 which i found it easy to use especially it does not always need ext ...