Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
//=============================================================================
// MAKE RANDOM BYTE
//=============================================================================
void make_random_byte(void)
{
//-----------------------------------------------------
// this function make 8 new psuedo random bits in randL.
// 16bit random number generator is taken from Microchip's
// AN544 math routines appnote "psuedo random number generator";
// 1. XOR bits 15^14 into A
// 2. XOR bits 12^3 into B
// 3. XOR bits A^B into C
// 4. left shift rand var 1 bit
// 5. put C in bit 0
//-------------------------------------------------
unsigned char rng_bitcount;
unsigned char rand_temp;
// generate 8 new RNG bits (in randL);
rng_bitcount = 8;
while(rng_bitcount)
{
// 1. XOR bits 15^14 into A
rand_temp = 0;
if(randH.F7 != randH.F6) rand_temp.F2 = 1;
// 2. XOR bits 12^3 into B
if(randH.F4 != randL.F3) rand_temp.F1 = 1;
// 2. XOR bits A^B into C
if(rand_temp.F2 != rand_temp.F1) rand_temp.F0 = 1;
// 4. left shift rand var 1bit
asm CLRF STATUS ;
asm RLF randL,f ;
asm RLF randH,f ;
// 5. put C in bit 0
if(rand_temp.F0) randL++;
rng_bitcount--;
}
}
//-----------------------------------------------------------------------------
rando = (randL % 10) ; // result in rando is now 0-9 range