X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=adc_random.c;h=133fc86221a7c740eab3fc8de4fa04b15335e3db;hb=b8cc7d22ae11576cdf44ca2cd3b39d64e514a930;hp=e5e76940b762538c0a7ff8704d77c65a9e27fc92;hpb=77bec8ca2aa7d464cb5d3034a497e0ff8933864a;p=rgblamp.git diff --git a/adc_random.c b/adc_random.c index e5e7694..133fc86 100644 --- a/adc_random.c +++ b/adc_random.c @@ -10,21 +10,21 @@ unsigned char adc_random() { - static bit save_ansa2; - static bit save_trisa2; + static bit save_ansa0; + static bit save_trisa0; unsigned char accumulate = 0; /* Turn on the FVR, configured for 1.024V to the ADC */ FVRCON = 0b10000001; while (!FVRRDY); /* wait for ready signal */ - /* Configure RA2 (AN2) for ADC input */ - save_ansa2 = ANSA2; - ANSA2 = 1; - save_trisa2 = TRISA2; - TRISA2 = 1; + /* Configure RA0 (AN0) for ADC input */ + save_ansa0 = ANSA0; + ANSA0 = 1; + save_trisa0 = TRISA0; + TRISA0 = 1; ADCON1 = 0b11110011; /* Right justified result, Frc clk, FVR/Vss refs */ - ADCON0 = 0b00001001; /* Enable channel AN2, enable ADC */ + ADCON0 = 0b00000001; /* Enable channel AN0, enable ADC */ /* Sample the ADC several times, accumulating the LSB of the result */ for (unsigned i = 0; i < 128; i++) { @@ -37,8 +37,8 @@ unsigned char adc_random() /* Turn off ADC, FVR, and revert PORTA changes */ ADON = 0; FVREN = 0; - TRISA2 = save_trisa2; - ANSA2 = save_ansa2; + TRISA0 = save_trisa0; + ANSA0 = save_ansa0; /* Return the result */ return accumulate;