Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Prinint array number index on the lcd with PIC 16F877A

Status
Not open for further replies.

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
Print array number index on the lcd with PIC 16F877A

Can you plz help me to print on the lcd an index of any number after comparison of the following arrays;the pic is reading a frequency on its TICK1 of PIC16F877A and then that value is compared in those two arrays and print the index on the screen.

Code:
void final()
{
const float lo_limit[10] = {1,2,3,4,5,6,7,8,70,85};
const float  hi_limit[10] = {2,3,4,5 ,6,7,8,9,50,60};

for(i=0;i<lo_limit[i];i++)
{
for(j=0;j<hi_limit[j];j++)
{
if((value1>=hi_limit[i])&&(value1<=lo_limit[j]))
jean1=i;
printf(lcd_putc,"\f%d",i);
}
}}

where am I wrong the lcd is alwyas printing 10;do not worry abot those codes just correct only those ones my main program is not displayed here.
 
Last edited by a moderator:

Re: Print array number index on the lcd with PIC 16F877A

Convert i to string and display the string.

what I want is that if for example we have the following array:

const int k[]={1,2,3,4,5,6};I want to print for example 2 when the number found using the previuos codes I posted is 3 in this array.
The target is to read the frequency from T1CKI of PIC16F877A and then the number search that number in the array which is given after that display on the lcd the index of that number found in the array and read from the T1CKI.

Thanks
 

Hello can you please help on the codes below ,I want to find the index of a number corresponding to the frequency read from pin T1CKI of pic16f877a:see the codes below:
Code:
#include <16f877a.h>
#DEVICE ADC=10
#Device *=16 
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,cpd
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#byte portc=0x07
#include "lcd.c"
#define ARRAY_SIZE 191

float value,value1,l,p1,p2,p3,v1,v2,v3;
int i,ti,found,q;
void frequency();


const float k[]={
12349,12341,12319,12315,12300.9,12289,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,12280,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 frequency ()
{
float value, value1;
output_low(PIN_C4);
set_timer1(0);
setup_timer_1(T1_EXTERNAL| T1_DIV_BY_8);
delay_ms(250); 
setup_timer_1(T1_DISABLED);
value=get_timer1();
value1=(((value*8*4))/100);
delay_ms(1000);
printf(lcd_putc, "\f%f",value1);
delay_ms(2000);
for ( i =0,found=-1; i<ARRAY_SIZE ; i++)
delay_ms(2500);
printf(lcd_putc, "\f%f",l);
printf(lcd_putc, "\f%%");
delay_ms(1500);
}
void main()
{ 
set_tris_d(0x00);
set_tris_a(0xff);
set_tris_c(0x01);
lcd_init();
delay_us(200); 

aba:delay_ms(1200);
printf(lcd_putc, "\fSinusoidal");
delay_ms(1500);
printf(lcd_putc, "\f%f",value1);
delay_ms(1500);
printf(lcd_putc, "\f%d",i);
delay_ms(1500);

while(true)
 { 
frequency();

if((input(PIN_A0)==0)&&(value1<= k[i])&&(j[i]<=value1))
  {  
printf(lcd_putc,"\fWait....");
//frequency();
delay_ms(150);

 l=(0.1*i)+8.0;
output_high(PIN_C4);
delay_ms(5000);
 lcd_gotoxy(6,2);
 printf(lcd_putc,"\f%2.1f", l);
 printf(lcd_putc,"\%%");
 //output_high(PIN_C4);
 delay_ms(10000); 
//goto bi;
}
else if((value1>12360)||(value1<10120))
{
output_high(PIN_C4);
//printf(lcd_putc,"\f%f",value1);
delay_ms(1500);
printf(lcd_putc,"\f%d",i);
delay_ms(1500);
printf(lcd_putc,"\fConnectProbe");
delay_ms(1500);
printf(lcd_putc,"\fAndThen");
delay_ms(1500);
printf(lcd_putc,"\fPress");
delay_ms(1500);
printf(lcd_putc,"\fREDButton");
}
}
}
 
Last edited by a moderator:

Code:
pdiff= big value;
for(i=0; i<(sizeof(k)*4); i++)                  
{
cdiff = (value>k[i]) ? (value - k[i]) :(k[i] - value);        // find the diff for each value

if(cdiff<pdiff)                                                            // if the number is closer than the previous number take the i value
temp = i;
}
return i;                                                                   // i is the index..
 

hello is it possible to help me using my two arrays I used in the codes I give you:
array k and array j


so I want to find the index of a given number so that:

k <=value1<= j;so I want my program to print

Thanks.
 

read in the frequency then loop the array and check if the freq matches with any value in array. While looping you will use a variable as index. When a match is found break loop and then the value of index will be pointing to the matched freq.
 

read in the frequency then loop the array and check if the freq matches with any value in array. While looping you will use a variable as index. When a match is found break loop and then the value of index will be pointing to the matched freq.

can you please help me with codes?I tried many alternatives but I am not succeeding.
Please help
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
//variable freq contains read and calculated frequency
 
 
for(i=0; i<sizeof(k)-1;i++){
 
    if(freq == k[i])break;
 
}
 
//i will be the index of the matched freq in the array

 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
//variable freq contains read and calculated frequency
 
 
for(i=0; i<sizeof(k)-1;i++){
 
    if(freq == k[i])break;
 
}
 
//i will be the index of the matched freq in the array


there may not be exactly equal float values at all.. That is the problem
 

there may not be exactly equal float values at all.. That is the problem[/QUOTE

Hello the frequency read by the PIC from its T1CKI is a float number which is located between j<=frequency<=k;
so I want to find out those two float numbers j and k which fulfill the above condition and then when found,the program has to printout on the LCD
the index which is (i).

Thanks
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
for(jindex=0; jindex<sizeof(j)-1;jindex++){
 
    if(freq > j[jindex])break;
 
}
 
for(kindex=0; kindex<sizeof(k)-1;kindex++){
 
    if(freq < K[kindex])break;
 
}
 
//jindex and kindex gives the required indices.

 
Last edited:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
for(jindex=0; jindex<sizeof(j)-1;jindex++){
 
    if(freq > j[jindex])break;
 
}
 
for(kindex=0; kindex<sizeof(k)-1;kindex++){
 
    if(freq < K[kindex])break;
 
}
 
//jindex and kindex gives the required indices.


Thank you so much for your response;can you try to compare my codes on post #6 and put conveniable codes for this you proposed;I think the index has to be the same for the two arrays k and J

j[]={1,2,3,4,5,6}
k[]={7,8,9,10,11,12}

if for example the frequency read from T1CKI is 5.5 then this value has to be compared with j[jindex]<=5.5<=k[kindex]
so we find out that j[4]<=5.5<=k[4] here means :5<=5.5<=11

so the index will be 4;this 4 is what I want to print on the lcd.

Thanks again
 

Index cannot be same. The value of freq read from T1CKI lies between values in j[] and k[]. So if freq is 5.5 and j[6] is 5.4 and k[10] is 5.6 then j[6] is < freq and k[10] is > 5.5 so freq lies between j[6] and k[10] so indices will be different.

if freq is 5.5 and j[0] is 5.1, j[1] is 5.12, j[2] is 5.3 then it compares freq with j[0] and as it is less than freq the loop breaks.


If you want to get the next lower and higher values wrt to freq then you have to do like this


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
for(i = 0; i < sizeof(j)-1; i++){
 
    if(j[i] <= freq)
    else break;
 
}
 
i--;
 
for(j = 0; j < sizeof(k)-1; j++){
 
    if(k[j] <= freq)
    else break;
 
}

 
Last edited:

I get the point but the arrays are arranged like j[0...201]<k[0...201]
all values of array j are less than the ones of array k when considering the same index meanwhile:
j[5]<k[5]for example and so on so the value of frequency read is always between two numbers j[jindex]<=freq<=k[kindex];the codes you proposed above are giving the index 0 for all.

Try to help;hope you get the point now;see the codes I am using;if required I can attach also the proteus schematic which I am using :

Code:
#include <16f877a.h>
#DEVICE ADC=10
#Device *=16 
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,cpd
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#byte portc=0x07
#include "lcd.c"
#define ARRAY_SIZE 200
float value,freq,l,p1,p2,p3,v1,v2,v3;
int i,t,found;
int m;


const float k[]={
12349,12341,12319,12315,12300.9,12289,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};
//one array divided into 3 arrays

const float j[]={
12359,12348,12340,12318,12303,12301,12280,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()
{ 
set_tris_d(0x00);
set_tris_a(0xff);
set_tris_c(0x01);
lcd_init();
delay_us(200); 
output_high(PIN_C4);  
aba:delay_ms(1200);
printf(lcd_putc, "\fWave");
delay_ms(1500);
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();
//value1=(((value*8*4)-54344)/100);
freq=(((value*8*4))/100);
//printf(lcd_putc, "\f%f",freq);
//delay_ms(1500);

for(i=0;i<sizeof(j)-1; i++)
{
	if((freq>j[i])||(freq==j[i]))	
	break;
}
for(t=0;t<sizeof(k)-1;t++)
{
	if((freq<k[t])||(freq==k[t]))
	break;

}

	printf(lcd_putc,"\f%d",t);
	delay_ms(1500);
	printf(lcd_putc,"\f%d",i);
	delay_ms(1500);

	printf(lcd_putc, "\f%f",freq);
	delay_ms(2000);


}
}
 
Last edited by a moderator:

hi here you go..........
Code:
main()
{
  float value;
  int i,size;
  char str[16];

  lcd init();
  size = (sizeof(k)/sizeof(float));
  while(1)
    {
    value = frequency();              // Read frequency
    for(i=0; i<size; i++)
      {
      if( (k[i] <= value) && (j[i] >= value) ) // find the match (k is the low value and j is the big value boundries )
        break;
      }
      if(i != size)      // some value match found (if no value matches i will reach size and no need to print wrong info)
        {
        sprintf(str,"index = %d",i);
        put_lcd((void*)str);
        }
    }
}
I think this is all and you have write function for lcd........
I belive this will work for sure..

- - - Updated - - -

don forget to include stdio.h (for sprintf)..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top