analog output from pic 18f4520
The variable k is unsigned char so can only hold values up to 255. Ideally it should also be volatile as it's used in both main and interrupt. 

Change the declaration to volatile unsigned short k = 0; and see if that helps, similar with m too, so something like:

#include"pic18f4520.h"
#pragma config WDT = OFF
volatile unsigned short k = 0;
volatile unsigned short m = 401;
// etc.


Actually, the code you posted doesn't use m, but maybe that's not all of your code, so just be aware.

Assuming you are using Microchip's XC8 compiler, the supported data types and ranges are all described from page 151 of the XC8 Compiler User Guide. For example, here are the two relevant tables:





If you want to ensure that your code is portable, regardless of differing compiler defaults, you can #include &lt;stdint.h&gt;, which defines types that specifically identify the size. For example:

#include &lt;stdint.h&gt;
volatile k uint16_t = 0;    // 16-bit unsigned integer


Other types follow a similar pattern, for example int32_t is a 32-bit signed integer, uint8_t is 8-bit unsigned, etc.