gordon the light
Newbie level 4
Hi, Sorry if I posted in the wrong thread.
I tried to use Timer0 to generate 2 random numbers, using PIC18f4520 and c18 compiler in c language. But is not working. Please help me.
Here is my program.
I tried to use Timer0 to generate 2 random numbers, using PIC18f4520 and c18 compiler in c language. But is not working. Please help me.
Here is my program.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include<p18f4520.h> #include <stdlib.h> void ISR (void); char i,start; #pragma code L_vector=0x18void L_vector(void){_asm goto ISR _endasm} #pragma code#pragma interruptlow ISR void ISR(void) {if(INTCONbits.TMR0IF){ TMR0H=0xC2;TMR0L=0xF7;i=rand();start=(i+TMR0H)%8;j=rand();end=(j+TMR0L)%8;}} void main(void){ INTCONbits.GIEH=0;RCONbits.IPEN=1;INTCON2bits.TMR0IP=0;TMR0H=0xC2;TMR0L=0xF7;T0CON=0b100000101;INTCON=0b11100000; while(1);}
Last edited by a moderator: