Wixel SDK
random_from_adc.c
Go to the documentation of this file.
1 
5 #include <cc2511_types.h>
6 #include <cc2511_map.h>
7 #include <random.h>
8 
9 static uint8 adcReadTemp(void)
10 {
11  ADCIF = 0; // Clear the flag.
12  ADCCON3 = 0b10001110; // Read the temperature sensor using VDD as a reference, with only 7 bits of resolution.
13  while(!ADCIF){}; // Wait for the reading to finish.
14  return ADCL;
15 }
16 
18 {
19  randomSeed(adcReadTemp(), adcReadTemp());
20 }
21 
22 // The function below was commented out because it was not being used and might
23 // not be needed:
24 /* Adds another seed to the state of the random number generator.
25  * If you do this regularly, it will help guarantee that no two Wixels have the
26  * same random number stream (at least not for long).
27  */
28 /*
29 void randomRefreshFromAdc()
30 {
31  adcReadTemp();
32 
33  while(ADCCON1 & 0x0C); // Wait for the last random number to finish.
34  RNDL = RNDH ^ ADCL; // Add the seed, but don't throw away the randomness in RNDH.
35  ADCCON1 = (ADCCON1 & ~0x0C) | 0x07; // Start generating the next random number.
36 }*/
37 
38 // Local Variables: **
39 // mode: C **
40 // c-basic-offset: 4 **
41 // tab-width: 4 **
42 // indent-tabs-mode: nil **
43 // end: **
unsigned char uint8
Definition: cc2511_types.h:9
void randomSeedFromAdc(void)