OK - First thing is first
You need to set your config bits -> This sets up thing like the oscillator, watchdog timer - Things that if not set up properly, will make your PIC seem like it is doing random things. Learning how to do this should be your priority. An incorrect setting of LVP (low voltage programing) with a floating pin will lead to a reset every time your hand goes near your microprocessor.
It's good to see that you are now declaring 'j' and 'end'. However, you need to declare them as "volatile". To help you avoid the strenuous task of a Google search, here is how you do that:
Code:
volatile char i, j, start, end;
If you don't declare them as volatile, bad things will happen. If you want to learn more about why this is so, have a look on google or gooligum.
statement should be
You shouldn't be writing to PORTAbits.RAn, but rather LATAbits.LATAn
You're treating main() like it is going to loop forever (like the loop function on the Arduino), but it's not. If you want it to loop, you'll need to use
Code:
while(1){ /* Everything you want to loop */ }
or
Code:
for(;;) { /* Everything you want to loop */ }
It's really a personal choice which one you use.
As a rule with Microcontrollor programming -> Avoid doing anything in an interrupt that isn't necessary. The usual way to do this is by setting up your program like this:
When a timer interrupt happens -> Set a flag (i.e. Set a (volatile) variable's value from 0 to 1)
In your main loop ->
Code:
(pseudo/C)
int main(void)
{
/* Set up registers/variable values here */
while(1) /* Loop forever */
{
if (flag == 1)
{
flag = 0; // (Clear flag here)
/* Get your random numbers here */
/* Use your random numbers here */
}
}
return 0;
}