Prinint array number index on the lcd with PIC 16F877A

Status
Not open for further replies.

Hello Sir,thanks for the codes you proposed unfortunately I did not write any additional lcd function because I am not able;I am using the ordinary file of the Lcd coming with ccs c setup;so I am having problem when compiling the codes you give;I am having error on put_lcd((void*)str); line can you please help me to print that using the normal lcd command:printf(lcd_putc," ");

Are those codes display the index when the value reads is between two numbers of the same index from two differents arrays,J and K.

Thanks and waiting for the positive reply.

- - - Updated - - -

Hello Sir,thanks for the codes you proposed unfortunately I did not write any additional lcd function because I am not able;I am using the ordinary file of the Lcd coming with ccs c setup;so I am having problem when compiling the codes you give;I am having error on put_lcd((void*)str); line can you please help me to print that using the normal lcd commandrintf(lcd_putc," ");

Are those codes display the index when the value reads is between two numbers of the same index from two differents arrays,J and K.

Thanks and waiting for the positive reply.

- - - Updated - - -

Did you try the second code I gave?

Yeah ,I did but no result ,can you add the instructions for printing on the lcd then I try all of them;just the combination of the previous codes and the instructions for printing on the lcd.
Thanks
 

Code:
main()
{
  float value;
  int i,size;
  char str[16];

  lcd_init();
  lcd_gotoxy(1,1);
  printf(lcd_putc, "Error Frequency");
  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)
        {
        lcd_gotoxy(1,1);
        printf(lcd_putc, "index = %d", i );
        }
    }
}
this will find the index of the given value from j and k (exactly as you said) I assume you know how to configure pins of LCD and for a correct value of frequency only this will print index..
if the frequency not matches at all it will print Error if you configured LCD correctly..
 


Hello,thank you very much for the proposed codes,unfortunately I am always printing error frequency;because my circuits operates as follow;consider my two arrays below:
PHP:
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,
};
the number k[4] and j[4] for examples are respectively:12300.9 (from array K) and 12303 (from array J);so when the input(the frequency read)on the pin T1CKI is between 12303Hz and 12300.9Hz ;I want the lcd to show 4 (as index corresponding to the boundaries of the frequency read).

For the codes you proposed I think the index 4 will e printed when the frequency read from T1CKI is 12300Hz or 12303.9Hz;can you explain in few words because with my simulation in proteus,the lcd is always printing Error Frequency.

consider the Proteus simulation circuit attached here

Help to solve this;thanks.
 

Attachments

  • New WinRAR ZIP archive.zip
    9.9 KB · Views: 46
Last edited:

The number 4 will be displayed as for the given value is in between the 12300.9 (from array K) and 12303 (from array J); so don worry if you get error frequency always means the problem is with your frequency or frequency function only.. are you got it??
the condition in the program is correct only if the given frequency is greater than K and less than j then it will print the value..

- - - Updated - - -

The number 4 will be displayed as for the given value is in between the 12300.9 (from array K) and 12303 (from array J); so don worry if you get error frequency always means the problem is with your frequency or frequency function only.. are you got it??
the condition in the program is correct only if the given frequency is greater than K and less than j then it will print the value..
 


Hello,have you tried with my simulation schematic from proteus?What value of frequency have you used?on pin 15?
Consider my frequency function here,is there any error?
PHP:
void frequency()
{
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);
    value = freq;     
}
also ,see the error( on the attachment) , I am getting with simulation in proteus
Check for me you let me know,thanks.
 

Attachments

  • photo.zip
    146 bytes · Views: 48
Last edited:

sorry i don have proteus and i didnt simulated the program at all..

but problem is clearly seems to be in your frequency function...
please post your new full program to check.........
 

sorry i don have proteus and i didnt simulated the program at all..

but problem is clearly seems to be in your frequency function...
please post your new full program to check.........


Thanks,my new full program is here below:
PHP:
#include <16f877a.h>

#DEVICE ADC=10
#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"
#include <stdio.h>
#define ARRAY_SIZE 201
float value,freq,l,p1,p2,p3,v1,v2,v3;
int i,t,found;


float tt,diff,diff1,value1;
int m;
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()
{
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);
    value1 = freq;     
}


main()
{
  float value;
  int i,size;
  char str[16];

  lcd_init();
  lcd_gotoxy(1,1);
  printf(lcd_putc, "Error Frequency");
  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)
        {
        lcd_gotoxy(1,1);
        printf(lcd_putc, "index = %d", i );
        }
    }
}
 

Code:
#include <16f877a.h>

#DEVICE ADC=10
#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"
#include <stdio.h>
#define ARRAY_SIZE 201

float value;

void frequency(void);

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(void)
{
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);
}


main()
{
  int i,size;
  char str[16];

  lcd_init();
  lcd_gotoxy(1,1);
  printf(lcd_putc, "Error Frequency");
  size = (sizeof(k)/sizeof(float));
  while(1)
    {
    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)
        {
        lcd_gotoxy(1,1);
        printf(lcd_putc, "index = %d", i );
        }
    }
}

- - - Updated - - -

Now try this and it will work fine..
the frequency should be in between 1012000Hz and 1235900Hz for valid frequency..

- - - Updated - - -

try with 1.1Mhz
 
Last edited:


hello I used the codes but the error remains the same always printing "Error Frequency".

- - - Updated - - -


hello I used the codes but the error remains the same always printing "Error Frequency".
 

Post the latest Project files zipped. Also include Proteus file. I will try to fix it.

Value lies between 12300.9 and 12301 and not 12300. So, the indices wil not be equal.

See if this works.



12344.00 is less than k[0] which is 12349 and > j[2] which is 12340.
 

Attachments

  • New Folder (2).rar
    131 KB · Views: 41
  • freq.png
    36.1 KB · Views: 67
Last edited:


There is only one index.. that is needed to be printed..
for a given value for a particular index the value shd be (k <= value) && (j >= value)

- - - Updated - - -

Code:
#include <16f877a.h>

#DEVICE ADC=10
#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"
#include <stdio.h>
#define ARRAY_SIZE 201

float value;

void frequency(void);

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(void)
{
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);
}


main()
{
  int i,size;
  char str[16];

  lcd_init();
  lcd_gotoxy(1,1);
  printf(lcd_putc, "Error Frequency");
  size = (sizeof(k)/sizeof(float));
  value = 11000;
  while(1)
    {
    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)
        {
        lcd_gotoxy(1,1);
        printf(lcd_putc, "index = %d", i );
        }
    }
}
Try this and tell whats now happening..
 



Hello,the error remains the same I think the problem lies on the call of the function because the conditional statement below the call of the function is not being executed that is why the system is printing only "Error Frequency"
 

The problem is the function call frequency(). I tried calling frequency() but it doesn't return any value. If the code inside frequency() is used as I have used in the while(TRUE) loop then it works.


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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <16f877a.h>
 
#DEVICE ADC=10
#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"
#include <stdio.h>
#define ARRAY_SIZE 201
float value,freq,l,p1,p2,p3,v1,v2,v3;
int q,p,t,found,sizek, sizej;
 
 
float tt,diff,diff1,value1;
int m;
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,
};
 
 
main()
{
     
  lcd_init();
  lcd_gotoxy(1,1);
  p = 0;
  q = 0;
  
  while(TRUE)
  {
      set_timer1(0);
      setup_timer_1(T1_EXTERNAL | T1_DIV_BY_8);
      delay_ms(1000); 
      setup_timer_1(T1_DISABLED);
      freq = get_timer1() * 8;
      printf(lcd_putc, "\f%7.2f", freq);
      
      if((freq >= 10120) && (freq <= 12349))
            while(k[p++] > freq);
            p = p - 2;
    
      if((freq >= 10124.99) && (freq <= 12359))
            while(j[q++] > freq);        
            q = q - 1;
            
      lcd_gotoxy(1,2);
      printf(lcd_putc, "k[%d] j[%d]", p,q);
      p = 0;
      q = 0;
        
  }
}

 


The problem here is that I want to compare the frquency I read with a value of array j (maximum) and another value of array k then print the index of that number of j or k array.
And also the proposed codes here are not giving the real frequency;I am inputting 1.1M and the LCD shows me 51424Hz
What is the matter here??Can you plz help me just to print the index of the number but using the boundaries of the differents arrays

minimum value(array k) <=frequency<= maximum value( array j)
k<=frequency<=j
so print the index of that j or the value of k[ki]
the index i must be the same as we use it for all arrays.

Thanks again.

Thanks.
 
Last edited:

the circuit is the one posted above on #33 so the frquency is given by a function generator which gives a square wave,the measurement is taken when the button on RC4 is pressed.
 

All the values of freq in your arrays are in KHz. Range 10120 to 12359 KHz. If you give 1.1 MHz then due to the if conditions the code inside if coditions never get executed and that is why you are getting Error Frequency.

If somebody has provided you to do this project then post all the documents provided for the project. I still don't understand what you exactly want to do.


Calculate and see if you can measure 1 MHz or greater using T1CKi with the settings used. Tey using T0CKI and see if you can measure 1 or 2 MHz.
 
Last edited:




I make a simple collection on :
PHP:
if( (k[i] <= value) && (j[i] >= value) ) // find the match (k is the low value and j is the big value boundries )
		{		
		}
because of the error which was being printed by proteus saying that there is stack undeflow error.....;but now here with the below complete codes:
PHP:
#include <16f877a.h>

#DEVICE ADC=10
#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"
#include <stdio.h>
#define ARRAY_SIZE 201

float value,freq,l,p1,p2,p3,v1,v2,v3;
int q,p,t,found,sizek, sizej;
 
 
float tt,diff,diff1,value1;
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};
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,
};


main()
{
  int i,size;
  char str[16];

  lcd_init();
  lcd_gotoxy(1,1);
  //printf(lcd_putc, "Error Frequency");
  size = (sizeof(k)/sizeof(float));
  //value = 11000;
  while(1)
    {
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<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)
        {
        lcd_gotoxy(1,1);
        printf(lcd_putc, "index = %d", i );
        }
    }
}
I am only printing the index=0 nothing else;can you please help me to solve the issue then print the real index;what I saw is that the instructions in:
PHP:
if( (k[i] <= value) && (j[i] >= value) ) // find the match (k is the low value and j is the big value boundries )
		{
		printf(lcd_putc, "\f%f", value );
		delay_ms(1500);
		printf(lcd_putc, "index = %d", i );
		delay_ms(1500);
		}
are not being executed because for example here above the numerical value of value is not being printed out and that index following;so the index=0 which is being printed out is that of the last line in the following codes:
PHP:
if(i != size)      // some value match found (if no value matches i will reach size and no need to print wrong info)
        {
        lcd_gotoxy(1,1);
        printf(lcd_putc, "index = %d", i );
        }
.How can I make those codes executables so the compiler reads them.

Thanks.
 

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…