From: R. Steve McKown Date: Thu, 8 Dec 2011 03:48:24 +0000 (-0700) Subject: Use bit definitions to simplify adc_random() X-Git-Tag: 1.0~40 X-Git-Url: https://oss.titaniummirror.com/gitweb?a=commitdiff_plain;h=e9a7367a18fae5455cac4bf9cecf140b272e3178;p=rgblamp.git Use bit definitions to simplify adc_random() --- diff --git a/adc_random.c b/adc_random.c index 05450f4..d516d7f 100644 --- a/adc_random.c +++ b/adc_random.c @@ -10,8 +10,8 @@ unsigned char adc_random() { - unsigned char save_ansela; - unsigned char save_trisa; + static bit save_ansa2; + static bit save_trisa2; unsigned char accumulate = 0; /* Turn on the FVR, configured for 1.024V to the ADC */ @@ -19,10 +19,10 @@ unsigned char adc_random() while (!FVRRDY); /* wait for ready signal */ /* Configure RA2 (AN2) for ADC input */ - save_ansela = ANSELA; - ANSELA |= 4; - save_trisa = TRISA; - TRISA |= 4; + save_ansa2 = ANSA2; + ANSA2 = 1; + save_trisa2 = TRISA2; + TRISA2 = 1; ADCON1 = 0b11110011; /* Right justified result, Frc clk, FVR/Vss refs */ ADCON0 = 0b00001001; /* Enable channel AN2, enable ADC */ @@ -37,8 +37,8 @@ unsigned char adc_random() /* Turn off ADC, FVR, and revert PORTA changes */ ADON = 0; FVREN = 0; - TRISA = save_trisa; - ANSELA = save_ansela; + TRISA2 = save_trisa2; + ANSA2 = save_ansa2; /* Return the result */ return accumulate;