# Making a frequency measurement meter with 7 segment dynamic display and pic18f4550

#### khatus

Joined Jul 2, 2018
68
C:
#define f_timer 2000000

const unsigned short DIGITOS[] =
{
0x3F,
0x06,
0x5B,
0x4F,
0x66,
0x6D,
0x7D,
0x07,
0x7F,
0x6F,
};

void VerDisplay( int Frequency )
{
unsigned short U;
unsigned short D;
unsigned short C;
unsigned short UM;
UM = Frequency/1000;
C = (Frequency-UM*1000)/100;
D = (Frequency-UM*1000-C*100)/10;
U = (Frequency-UM*1000-C*100-D*10);
PORTB = DIGITOS;
PORTA.F0=1;
delay_ms(10);
PORTA=0;
PORTB = DIGITOS[D];
PORTA.F1=1;
delay_ms(10);
PORTA=0;
PORTB = DIGITOS[C];
PORTA.F2=1;
delay_ms(10);
PORTA=0;
PORTB = DIGITOS[UM];
PORTA.F3=1;
delay_ms(10);
PORTA=0;
}
void main ( void )
{
unsigned long signal_period,data1,data2;
int Frequency=150;
TRISC.TRISC2=1;
OSCCON=0b1110000;
PIE1.CCP1IE=1;
PIR1.CCP1IF=0;
CCP1CON=0x05;
CCPR1=0x00;
PIR1.TMR1IF=0;
T1CON=0x80;
TMR1H=0;
TMR1L=0;
T1CON.TMR1ON=1;

TRISB = 0;
TRISA = 0;
PORTA = 0;

while( 1 )
{
void VerDisplay( Frequency );
while(!(PIR1.CCP1IF));
PIR1.CCP1IF=0;
data1 = CCPR1;
while(!(PIR1.CCP1IF));
PIR1.CCP1IF=0;
data2 = CCPR1;

if(data1 < data2)
{
signal_period = data2 - data1;
Frequency = ((float)f_timer / (float)signal_period);
while(1)
{
VerDisplay( Frequency );

}
TMR1H=0;
TMR1L=0;

}
}
}
Hello guys i am a beginner in programming .I want to build a frequency measurement meter with 7 segment dynamic display and pic18f4550 mcu. The above code compiled successfully while the display showing nothing.i need help for this project

Mod edit: code tags

Last edited by a moderator:

#### AlbertHall

Joined Jun 4, 2014
8,330
I don't see any code to display anything. You need to include all the code.

#### djsfantasi

Joined Apr 11, 2010
5,585
I don't see any code to display anything. You need to include all the code.
And learn to post code inside code tags.

The easiest way is to click on the mini icon that looks like a monitor. Then paste your code into the text box provided. After you do this, you can still edit the code within the post.

#### JohnInTX

Joined Jun 26, 2012
3,799
A few things:

You haven't set any of the PIC configuration bits (in the code at least) - that's necessary to run code on a chip. MikroC does it automatically, you have to add the config settings as #pragmas in XC8 so..
Which compiler/IDE are you using?
How are you debugging this?
Line 28 doesn't index the array of digit patterns.
Once you get to the 'while' in line 80, you will stay there forever without updating the frequency variables.
The display multiplexer should be done in a timer interrupt routine. Your successive delays will slow things down. Also, 10ms / digit will flicker.
On an 18F, all outputs should be done to LATx, not PORTx.

Haven't looked at the CCP stuff in detail..

EDIT: it looks like you used MicroC. It actually does not compile because of line 28. Also, to make the delays work as you have named them, you have to turn case-sensitivity OFF. That is a bad idea. Turn it back on (Project->Edit Project -> General Output Settings) and use the proper names and cases i.e. Delay_ms.

You are enabling the CCP1IE interrupt enable but you have no interrupt service routine. **BOOM!**
I commented out //PIE1.CCP1IE=1; and simulated two rising edge captures and it seems like it gets digits for the frequency. But only once with the while loop as it is.

Have fun!

Last edited:

#### MrChips

Joined Oct 2, 2009
19,270
Lines 80-84 constitute an endless loop. Lines 85,86 are never reached.

#### khatus

Joined Jul 2, 2018
68
anybody can correct my code??

#### djsfantasi

Joined Apr 11, 2010
5,585
anybody can correct my code??
Probably not. With the information missing as mentioned in previous posts, there is no way to debug code without knowing how you’ve initialized (or want to initialize) the system.

Plus, some people have told you how to correct the code as far as we can. Have you fixed the infinite loop? Have you removed updates to LATx? Have you fixed indexing your digit arrays? Show us your changes, please.

#### MrChips

Joined Oct 2, 2009
19,270
Begin with basic coding and debugging techniques.
Can you write code to make an LED blink?