Prinint array number index on the lcd with PIC 16F877A

Status
Not open for further replies.
Are both arrays have the same size? If not, you have to use sizek = (sizeof(k)/sizeof(float)); and sizej = (sizeof(j)/sizeof(float));

if freq = 12320 then

k[2] which is 12319 is < 12320

and

j[2] which is 12340 is > 12320

So, k[2] and j[2] are the boundries.

k[2]<freq<j[2]

Is this what you want?
 

Hello,yes it is that I want and the array has the same size.All arrays has 191 numbers .

Thanks
 


Hello venkadeshm ,can you plz help me to understand what cdiff and pdiff mean?
Are those codes printing the index of two numbers from two differents arrays which are compared to the frequency I read from the T1CKI pin of PIC16F877A?

Thanks.
 

Hello can you help me to think how I can retrieve a float number in when I change the below arrays into float?I am retrieving the index using to enter an integer number but when I use to change the arrays to float type and enter a float number I am getting errors:
see the code below:


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
main()
{
// float k[10]={2, 4, 6, 8, 10,12,14,16,18,20};
//int j[10]={3,5,7,9,11,13,15,17,19,21};
 
const int k[]={10,12,17,22,27,32,37,42,47,52,57,62,67,72,77,82} ;
const int j[]={13,15,20,24,31,35,40,45,50,55,60,65,70,75,80,85} ;
 
 
int i,t;
int q;
printf("Enter any number Q\n");
scanf("%d",&q);
 
 
 
 
for(t=0;t<16;t++)
{
for(i=0;i<16;i++)
{
 
if((q<=j[t])&&(q>=k[t])&&(t==i))
{
printf("%dis present at location %d. \n",q,i+1 );
break;
 
}
}
 
}
 
}



This program operate as follows:when I enter a number for example 14;the index is 2 because 12<=14 and 14,=15;
69;the index is 13 because 67<=69 and 69<=70;
and so on;so what I want is to use float numbers in the above arrays and retrieve the index of that float number using the above structure:

Please help.

Thanks.
 
Last edited by a moderator:

Run in dev c++
Code:
#include <stdio.h>

main()
{
 float k[10]={2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
 float j[10]={3, 5, 7, 9, 11, 13, 15, 17, 19, 21};

int i,t;
float q;
printf("Enter any number Q\n");
scanf("%f",&q);


for(i=0;i<16;i++)

if( ( q <= j[i] ) && (q >= k[i]) )
{
printf("%f is present at location %d. \n", q, i+1 );
break;
}

}
 

Hello the above one has been resolved but now I am having trouble with my big codes when I simulate in proteus;I am always using the two arrays J and K;and the program relaized in MPLAB is for retrieving the index corresponding to the number reads from the T1CKI of PIC16F877A so for the first 6 numbers in those two arrays the simulation gives good result but when I take any other number in the arrays which has the index > 5 the ISIS print out the errors;see my schematics on second page of this post,the codes are here below;the proteus is printing out :Stack underflow executing return instruction
Hope you help.
PHP:
#include <16f877a.h>
#DEVICE ADC=10
#include<stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,cpd
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#byte portc=0x07
 #define LCD_ENABLE_PIN  PIN_D0                                   
 #define LCD_RS_PIN      PIN_D1                                   
 #define LCD_RW_PIN      PIN_d2                                   
 #define LCD_DATA4       PIN_D4                                    
 #define LCD_DATA5       PIN_D5                                    
 #define LCD_DATA6       PIN_D6                                    
 #define LCD_DATA7       PIN_D7 
#include "lcd.c"
#define ARRAY_SIZE 189

float value;
int i,t;

const float k[]={
12349,12341,12319,12315,12300.9,12280,12260,12262,12248,12230.01,
12229.99,12209.99,12200.01,12199.99,12179.95,12180,12179.39,12170,12160,12151.3,
12150,12120,12100,12099,12095,12094.99,12085,12070,12050,12025,
12015,12010,12000,11995,11990,11985,11970,11968.99,11960,11955,
11950,11945,11940,11935,11930,11900,11885,11870,11841,11832.4,
11822.3,11812,11810,11800,11790,11738.5,11736.5,11735,11725,11715,
11700,11685,11675,11660,11645,11630,11599.99,11585,11575,11565,
11550,11535,11515,11505,11498.8,11440,11430,11418,11415,11426,
11415,11404,11396,11385.6,11375,11365,11355,11345,11335,11299.99,
11285,11274.99,11274,11235,11225,11215,11199.5,11185,11175,11165,
11150,11135,11120,11105,11080,11065,11052,11035,11025,11010,
10997.99,10985,10975,10964,10952,10940,10925,10915,10900,10885,
10875,10862,10850,10820,10800,10785,10775,10765,10759,10758.6,
10758.3,10748.2,10735,10725,10712,10700,10685,10672,10661,10650,
10632,10624,10613,10610,10600,10580,10560,10550,10540,10530,
10519.5,10515,10500,10485,10470,10455,10440,10425,10412,10400,
10385,10370,10355,10340,10320,10300,10289.99,10275,10265,10260,
10250,10240,10225,10215,10210,10200,10185,10182,10180,10175,
10170,10165,10160,10155,10155,10145,10140,10135,10125,10120};

const float j[]={
12359,12348,12340,12318,12303,12301,12289,12264,12261.2,12245,
12230,12230,12210,12200,12199.99,12199.96,12179.99,12179.38,12169.99,12159.99,
12151.29,12149.99,12120,12099.99,12098.99,12098,12097.99,12084.99,12069.99,12049.99,
12024.99,12014.99,12009.99,11999.99,11994.99,11989.99,11980,11969,11968.99,11959.99,
11954.99,11949.99,11944.99,11939.99,11934.99,11929.99,11899.99,11880,11869.99,11840.99,
11832.39,11822.29,11811.99,11809.99,11799.99,11749.49,11738.49,11736.49,11734.99,11724.99,
11714.99,11699.99,11684.99,11674.99,11659.99,11644.99,11629.99,11599.97,11584.99,11574.99,
11564.99,11549.99,11525,11514.99,11504.99,11498.7,11439.99,11429.99,11417.99,11434.99,
11425.99,11414.99,11403.99,11395.99,11385.59,11374.99,11364.99,11354.99,11344.99,11334.99,
11299.98,11284.99,11275,11249.98,11234.99,11224.99,11214.99,11199.49,11184.99,11174.99,
11164.99,11149.99,11134.99,11119.99,11090,11079.99,11064.99,11051.99,11034.99,11024.99,
11009.99,10997.98,10984.99,10974.99,10963.99,10951.99,10939.99,10924.99,10914.99,10899.99,
10884.99,10874.99,10861.99,10849.99,10819.99,10799.99,10784.99,10774.99,10764.99,10758.99,
10758.59,10758.29,10748.19,10734.99,10724.99,10711.99,10699.99,10684.99,10671.99,10660.99,
10649.99,10631.99,10623.99,10612.99,10609.99,10599.99,10579.99,10559.99,10549.99,10539.99,
10529.99,10519.49,10514.99,10499.99,10484.99,10469.99,10454.99,10439.99,10424.99,10411.99,
10399.99,10384.99,10369.99,10354.99,10330,10319.99,10299.99,10289.98,10274.99,10264.99,
10259.99,10249.99,10239.99,10224.99,10214.99,10209.99,10199.99,10184.99,10181.99,10179.99,
10174.99,10169.99,10164.99,10159.99,10159.99,10149.99,10144.99,10139.99,10129.99,10124.99};

void main()
{
  int i,t;
  lcd_init();
  lcd_gotoxy(1,1);
  while(true)
    {
set_timer1(0); //Must be reset
setup_timer_1(T1_EXTERNAL| T1_DIV_BY_8);
delay_ms(250); 
setup_timer_1(T1_DISABLED);
value=(((get_timer1()*8.0*4.0))/100); 
for (i=0;i<189;i++)
{
for(t=0;t<189;t++)
{
if((value<=j[t])&&(value>=k[i])&&(t=i))
{
delay_ms(50);
printf(lcd_putc,"\fIndex:");
delay_ms(1500);
delay_ms(50);
printf(lcd_putc,"%d",i+1);
delay_ms(2500);
break;
}
}
}
}
}

Thanks
 

Thanks to all of you who helped me to think on the above problem;by now I solved by reducing the for loop and also by dividing the big array into the smaller ones;but still I have a great problem for printing the index i
as you know I have to print the index from 1 to 190 and you know that with the integer we can only print up to 128;can you please help me to solve this issue because after getting the value of i I have to use it in the formula:
PHP:
l=(0.1*i)+8.0
;so the i has to be always positive number and varid for all numbers in the arrays ;for example the index of 10124.99 is -67 which might be 191;see my codes here below:
PHP:
#include <16f877a.h>
#DEVICE ADC=10
#include<stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,cpd
#use delay(clock=20000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include<stdio.h>

 #define LCD_ENABLE_PIN  PIN_D0                                   
 #define LCD_RS_PIN      PIN_D1                                   
 #define LCD_RW_PIN      PIN_d2                                   
 #define LCD_DATA4       PIN_D4                                    
 #define LCD_DATA5       PIN_D5                                    
 #define LCD_DATA6       PIN_D6                                    
 #define LCD_DATA7       PIN_D7 
#include "lcd.c"

void main()

{
float value,m;
int i,t;

lcd_init();
lcd_gotoxy(1,1);


const float k[]={12349,12341,12319,12315,12300.9,12280,12260,12262,12248,12230.01,
12229.99,12209.99,12200.01,12199.99,12179.95,12180,12179.39,12170,12160,12151.3,
12150,12120,12100,12099,12095,12094.99,12085,12070,12050,12025,
12015,12010,12000,11995,11990,11985,11970,11968.99,11960,11955,
11950,11945,11940,11935,11930,11900,11885,11870,11841,11832.4,
11822.3,11812,11810,11800,11790,11738.5,11736.5,11735,11725,11715};

const float w[]={11700,11685,11675,11660,11645,11630,11599.99,11585,11575,11565, //index start from 61
11550,11535,11515,11505,11498.8,11440,11430,11418,11415,11426,
11415,11404,11396,11385.6,11375,11365,11355,11345,11335,11299.99,
11285,11274.99,11274,11235,11225,11215,11199.5,11185,11175,11165,
11150,11135,11120,11105,11080,11065,11052,11035,11025,11010,
10997.99,10985,10975,10964,10952,10940,10925,10915,10900,10885}; //index ends at 119

const float v[]={10875,10862,10850,10820,10800,10785,10775,10765,10759,10758.6,//index start from 121
10758.3,10748.2,10735,10725,10712,10700,10685,10672,10661,10650,
10632,10624,10613,10610,10600,10580,10560,10550,10540,10530,
10519.5,10515,10500,10485,10470,10455,10440,10425,10412,10400,
10385,10370,10355,10340,10320,10300,10289.99,10275,10265,10260,
10250,10240,10225,10215,10210,10200,10185,10182,10180,10175};
const float u[]={10170,10165,10160,10155,10155,10145,10140,10135,10125,10120};

//Second array Side declaration


const float j[]={12359,12348,12340,12318,12303,12301,12289,12264,12261.2,12245,
12230,12230,12210,12200,12199.99,12199.96,12179.99,12179.38,12169.99,12159.99,
12151.29,12149.99,12120,12099.99,12098.99,12098,12097.99,12084.99,12069.99,12049.99,
12024.99,12014.99,12009.99,11999.99,11994.99,11989.99,11980,11969,11968.99,11959.99,
11954.99,11949.99,11944.99,11939.99,11934.99,11929.99,11899.99,11880,11869.99,11840.99,
11832.39,11822.29,11811.99,11809.99,11799.99,11749.49,11738.49,11736.49,11734.99,11724.99};


const float a[]={11714.99,11699.99,11684.99,11674.99,11659.99,11644.99,11629.99,11599.97,11584.99,11574.99,
11564.99,11549.99,11525,11514.99,11504.99,11498.7,11439.99,11429.99,11417.99,11434.99,
11425.99,11414.99,11403.99,11395.99,11385.59,11374.99,11364.99,11354.99,11344.99,11334.99,
11299.98,11284.99,11275,11249.98,11234.99,11224.99,11214.99,11199.49,11184.99,11174.99,
11164.99,11149.99,11134.99,11119.99,11090,11079.99,11064.99,11051.99,11034.99,11024.99,
11009.99,10997.98,10984.99,10974.99,10963.99,10951.99,10939.99,10924.99,10914.99,10899.99};

const float b[]={10884.99,10874.99,10861.99,10849.99,10819.99,10799.99,10784.99,10774.99,10764.99,10758.99,
10758.59,10758.29,10748.19,10734.99,10724.99,10711.99,10699.99,10684.99,10671.99,10660.99,
10649.99,10631.99,10623.99,10612.99,10609.99,10599.99,10579.99,10559.99,10549.99,10539.99,
10529.99,10519.49,10514.99,10499.99,10484.99,10469.99,10454.99,10439.99,10424.99,10411.99,
10399.99,10384.99,10369.99,10354.99,10330,10319.99,10299.99,10289.98,10274.99,10264.99,
10259.99,10249.99,10239.99,10224.99,10214.99,10209.99,10199.99,10184.99,10181.99,10179.99,};
const float c[]={10174.99,10169.99,10164.99,10159.99,10159.99,10149.99,10144.99,10139.99,10129.99,10124.99};


  
  while(true)
{
set_timer1(0); 
setup_timer_1(T1_EXTERNAL| T1_DIV_BY_8);
delay_ms(250); 
setup_timer_1(T1_DISABLED);
value=(((get_timer1()*8.0*4.0))/100); 

if(input(PIN_C4)==0)
{
for (i=0;i<191;i++)
//{
//for(t=0;t<191;t++)
{
if((value<=j[t])&&(value>=k[i])&&(t=i))
{
printf(lcd_putc,"\fIndex");
delay_ms(1500);
delay_ms(50);

printf(lcd_putc,"\f%d",i+1);
delay_ms(2500);
break;
}
else if((value<=a[t])&&(value>=w[i])&&(t=i))
{
printf(lcd_putc,"\fIndex");
delay_ms(1500);
delay_ms(50);

printf(lcd_putc,"\f%d",i+60);
delay_ms(2500);
break;
}
else if((value<=b[t])&&(value>=v[i])&&(t=i))
{
printf(lcd_putc,"\fIndex");
delay_ms(1500);
delay_ms(50);
printf(lcd_putc,"\f%d",i+120);
delay_ms(2500);
break;
}
else if((value<=c[t])&&(value>=u[i])&&(t=i))
{
printf(lcd_putc,"\fIndex");
delay_ms(1500);
delay_ms(50);
printf(lcd_putc,"\f%d",i+180);
delay_ms(2500);
break;
}

}

}
}
}

Any help for this is is wonderfull.

Thanks.
 
Last edited:

normaly int will be 16 bits and upto 32000
if you having lower sized compiler means just put

int i; ====> unsigned int i;

- - - Updated - - -

and how your program works with unwanted variable t in each if statement ??

- - - Updated - - -

replace t with i in conditions and remove the comparison (t=i) Its not a comparison a good compiler will show a warning....

- - - Updated - - -

Code:
else if((value<=a[t])&&(value>=w[i])&&(t=i))

- - - Updated - - -

Code:
else if((value<=a[i])&&(value>=w[i]))
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…