PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 11, 2010 6:38 pm |
|
|
To save the lowest value, you just do a simple test. Compare the
current value to the previous lowest value. If the current value
is lower, then it becomes the new "lowest" value.
The program below shows one way to do it. Once you get a low value,
you will never get anything higher than that as the output. Once you
turn the trimpot down to 0, this program will keep displaying 0, no matter
what you turn the trimpot to later. I'm not sure if that's what you want.
At least this code will give you some ideas.
Code: |
#include <16F877.H>
#device adc=8
#fuses XT, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//======================================
void main()
{
int8 current, lowest;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);
lowest = 0xFF;
while(1)
{
current = read_adc();
if(current < lowest)
lowest = current;
printf("Lowest = %x \n\r", lowest);
delay_ms(500);
}
} |
|
|