Created
December 16, 2015 00:13
-
-
Save JHeld07/bb99cc115ca836b403d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enter file contents here// 10/21/2015 Fall Microcontrolers | |
#include <18f4520.h> | |
#use delay(clock=20000000) | |
#fuses HS, NOWDT, NOLVP | |
#include "../Library/18f4520ptr.h" | |
#include "../Library/modifiedlcd.h" | |
unsigned int OFCnt=0; | |
#INT_TIMER1 // Counter Overflows | |
void Int_timer1_isr(){ | |
OFCnt++; | |
} | |
unsigned int32 tstart, tstop, dT; | |
#INT_CCP2 | |
void int_ccp2_isr(){ | |
tstop = *CCPR2; //Get the time off the system... | |
dT = (OFCnt*0x10000)-tstart+tstop; | |
tstart = tstop; | |
OFCnt = 0; | |
} | |
main(){ | |
float time; | |
lcd_init(); | |
// Assuming your prescaler is = to 1 & your clock cycle is 20,000,000 | |
// Setup Overflow | |
T1CON->TMR1ON=1; | |
T1CON->TMR1CS=0; | |
T1CON->T1CKPSx=0; // Setting PS to 1 | |
// Setup my Capture | |
CCP2CON->CCPxMx=4; | |
// Setup my Interrupts | |
PIE1->TMR1IE=1; // Overflow Interupt | |
PIE2->CCP2IE=1; | |
INTCON->GIE=1; | |
INTCON->PEIE=1; | |
while(1){ | |
time=dT*0.2e-6; // PS 1 and Fosc 20m | |
printf(lcd_putc,"\f Freq=%f", 1/time); | |
delay_ms(300); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment