jean12
Advanced Member level 2
- Joined
- Aug 27, 2013
- Messages
- 529
- Helped
- 5
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 18
- Activity points
- 5,497
Code C - [expand] 1 2 3 4 5 6 7 8 9 big_value = 0; small_value = 0xFFFF; for ( i = 0; i < 20; i++) { if ( array[i] < small_value ) small_value = array[i]; if ( array[i] > big_value ) big_value = array[i]; }
#include"16f877a.h"
#device adc=10
#fuses HS,NOWDT,NOLVP,NODEBUG,NOCPD,NOBROWNOUT
#use delay(clock=4M)
#include"lcd.c"
int value,i,k,valuet;
unsigned long value1,valuenew;
//unsigned int value2,value3;
float value3,result;
int array[10];
void main()
{
set_tris_d(0x00);
set_tris_a(0xff);
set_tris_c(0x00);
set_tris_b(0x00);
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
set_adc_channel(0);
setup_vref(FALSE);
lcd_init();
lcd_gotoxy(1,1);
while(true)
{
delay_us(100);
for(i=0;i<10;i++)
{
delay_ms(50);
read_adc(adc_start_only);
delay_us(100);
value=read_adc(adc_read_only);
delay_us(100);
value1=value;
value3=(value1*50)/1023;
delay_us(100);
array[i]=value3;
}
printf(lcd_putc,"\f%d",array[i]);
delay_ms(500);
}
}
for(i=1;i<10;i++)
{
if(array[0]<array[i])
{
//printf(lcd_putc,"\f%f",array[0]);
//delay_ms(500);
printf(lcd_putc,"\fThe result000 is");
delay_ms(1500);
printf(lcd_putc,"\f%f",array[0]);
delay_ms(1500);
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 float a[10] = {10.2, 55.4, 9.3, 4.6, 234.8, 20.1, 30.5, 40.2, 22.6, 34.1}; float max = a[0]; float min = a[0]; usigned int i; for (i = 0; i < 10; i++) { if (a[i] > max) { max = a[i]; } else if (a[i] < min) { min = a[i]; } }
Code C - [expand] 1 for (i = 0; i < 10; i++)
Code C - [expand] 1 i < 10;
Code C - [expand] 1 i < counter;
#include"16f877a.h"
#device adc=10
#fuses HS,NOWDT,NOLVP,NODEBUG,NOCPD,NOBROWNOUT
#use delay(clock=4M)
#include"lcd.c"
int value,i,k,valuet;
unsigned long value1,valuenew;
//unsigned int value2,value3;
float value3,result;
int array[10];
void main()
{
set_tris_d(0x00);
set_tris_a(0xff);
set_tris_c(0x00);
set_tris_b(0x00);
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
set_adc_channel(0);
setup_vref(FALSE);
lcd_init();
lcd_gotoxy(1,1);
while(true)
{
delay_us(100);
for(i=0;i<10;i++)
{
delay_ms(50);
read_adc(adc_start_only);
delay_us(100);
value=read_adc(adc_read_only);
delay_us(100);
value1=value;
value3=(value1*50)/1023;
delay_us(100);
array[i]=value3;
}
printf(lcd_putc,"\f%d",array[i]);
delay_ms(500);
}
}
for(i=1;i<10;i++)
{
if(array[0]<array[i])
{
//printf(lcd_putc,"\f%f",array[0]);
//delay_ms(500);
printf(lcd_putc,"\fThe result000 is");
delay_ms(1500);
printf(lcd_putc,"\f%f",array[0]);
delay_ms(1500);
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 #include"16f877a.h" #device adc=10 #fuses HS,NOWDT,NOLVP,NODEBUG,NOCPD,NOBROWNOUT #use delay(clock=4M) #include"lcd.c" int value,i,k,valuet; unsigned long value1,valuenew; float value3,result; int array[25], arraySize = 0; float min, max; void main() { set_tris_d(0x00); set_tris_a(0xff); set_tris_c(0x00); set_tris_b(0x00); setup_comparator(NC_NC_NC_NC); setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(AN0); set_adc_channel(0); setup_vref(FALSE); lcd_init(); lcd_gotoxy(1,1); while(true) { delay_us(100); for(i = 0; i < 10; i++) { delay_ms(50); read_adc(adc_start_only); delay_us(100); value=read_adc(adc_read_only); delay_us(100); value1=value; value3=(value1*50)/1023; delay_us(100); array[i]=value3; printf(lcd_putc,"\f%d", array[i]); arraySize++; } min array[0]; max = array[0]; for (i = 0; i = arraySize; i++) { if (array[i] > max) { max = array[i]; } else if (array[i] < min) { min = array[i]; } } printf(lcd_putc,"\fThe min is %d", min ); printf(lcd_putc,"\fThe max is %d", max ); delay_ms(500); } }
...code...
actually there is no need to have a 2nd loop for the search -- it can be included in the 1st loop itself where the values are being acquired by adc
#include"16f877a.h"
#device adc=10
#fuses HS,NOWDT,NOLVP,NODEBUG,NOCPD,NOBROWNOUT
#use delay(clock=4M)
#include"lcd.c"
int value,i,k,valuet;
unsigned long value1,valuenew;
float value3,result;
int array[25], arraySize = 0;
float min, max;
void main()
{
set_tris_d(0x00);
set_tris_a(0xff);
set_tris_c(0x00);
set_tris_b(0x00);
setup_comparator(NC_NC_NC_NC);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
set_adc_channel(0);
setup_vref(FALSE);
lcd_init();
lcd_gotoxy(1,1);
while(true)
{
delay_us(100);
min =0;
max = 0;
for(i = 0; i < 10; i++)
{
delay_ms(50);
read_adc(adc_start_only);
delay_us(100);
value=read_adc(adc_read_only);
delay_us(100);
value1=value;
value3=(value1*50)/1023;
delay_us(100);
array[i]=value3;
printf(lcd_putc,"\f%d", array[i]);
if (array[i] > max)
{
max = array[i];
}
else if (array[i] < min)
{
min = array[i];
}
}
printf(lcd_putc,"\fThe min is %d", min );
printf(lcd_putc,"\fThe max is %d", max );
delay_ms(500);
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?