PIC18F25K80 4 > 20 returns true. How is this possible?
if (time_out &gt; 20){
    while(Busy1USART());
    Write1USART(time_out);


This writes time_out as ASCII character to the USART module. If you see '4' over the USART, that means the ASCII character '4', real value 0x34, is sent. And 0x34, 52 decimal, is greater than 20. 

If you want to print the decimal value as a string to the USART, you can do this:

#define putch Write1USART 

printf("%ul", time_out);


The printf() function formats time_out as an unsigned long (hence %ul) and writes it byte by byte to putch(). putch() should therefore have the signature:

void putch(unsigned char);


The #define in the example above makes sure Write1USART() is used for putch().