| Electronics > Beginners |
| PC 18f2550 timer0 problem |
| (1/1) |
| khatus:
https://www.electronicwings.com/pic/pic18f4550-timer-capture /* Frequency Measurement using Input Capture Mode in PIC18F4550 http://www.electronicwings.com */ #include <stdio.h> #include <stdlib.h> #include <p18f4550.h> #include "osc_config.h" #include "LCD_8bit_file.h" #include <string.h> #define f_timer 2000000 void main() { unsigned long signal_period,data1,data2; unsigned long frequency_Hz[20]; float Frequency; TRISCbits.TRISC2=1; OSCCON=0x72; /* set internal clock to 8MHz */ LCD_Init(); memset(frequency_Hz,0,20); LCD_String_xy(0,1,"Pulse"); PIE1bits.CCP1IE=1; PIR1bits.CCP1IF=0; CCP1CON=0x05; /* Capture mode is selected for detecting Rising edge */ CCPR1=0x00; /*CCPR1 is capture count Register which is cleared initially*/ TMR1IF=0; T1CON=0x80; /* Enable 16-bit TMR1 Register,No pre-scale,use internal clock,Timer OFF */ TMR1=0; TMR1ON=1; /* Turn-On Timer1 */ while(1) { while(!(PIR1bits.CCP1IF)); /*Wait for Interrupt flag which is generated when edge is detected*/ PIR1bits.CCP1IF=0; data1 = CCPR1; /*Copy count of 1st edge detected*/ while(!(PIR1bits.CCP1IF)); /*Wait for Interrupt flag which is generated when edge is detected*/ PIR1bits.CCP1IF=0; data2 = CCPR1; /*Copy count of 2nd edge detected*/ if(data1 < data2) { /*Calculation for Frequency Measurement*/ signal_period = data2 - data1; Frequency = ((float)f_timer / (float)signal_period); /*Count for 1 cycle*0.5us gives period */ sprintf(frequency_Hz,"%.3f ",Frequency); LCD_String_xy(2,0,frequency_Hz); } TMR1=0; memset(frequency_Hz,0,20); } } this is the code which measure Frequency of the input signal and display it on 16x2 LCD. I want to convert this code from mplab to mikroc .But i mikroc when i declare TMR1=0; it shows error.How i can overcome this problem?? |
| ggchab:
And check the doc: TMRxH might have to be initialized before TMRxL The high value is stored in a temporary register and really loaded in TMRxH when TMRxL is written. |
| MarkF:
And please use the code tag "#" button while editing in the future. It places the code in a small frame using a mono spaced font. :-+ |
| Navigation |
| Message Index |