Do following things,
- Call
lcd_init()
function outside thewhile(1)
loop, - Call
lcd_clear()
before re-writing on same position (e.g.xy(1,1)
, just a test case, not required, you can overwrite any character of the lcd, but by clearing the lcd is just can be a test case if your gotoxy() function is working properly or not) - Most importantly verify your crystals frequency
Try removing capacitors across the crystal, try changing the crystal, and if you can try using 4Mhz crystal. Using capacitors with high frequency crystal some time causes problems there check for datasheet for proper capacitors value to attach, better to use some lower frequency crystal or by removing capacitors with same crystal
- Also make sure you do not change the fuse bits at the time of flash burning, make them same as you mentioned in your code, brown out detect and power up timer will be preferable to use.