From e9a7367a18fae5455cac4bf9cecf140b272e3178 Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Wed, 7 Dec 2011 20:48:24 -0700 Subject: [PATCH] Use bit definitions to simplify adc_random() --- adc_random.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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; -- 2.39.2