Frekans metre ccs compiler (alıntı)
#include <16F628A.h>
#fuses INTRC_IO,NOLVP,MCLR
//#fuses WDT
#use delay(clock=4M)
#define ONE_SEC_TICKS 3907
//3907
#define LCD_ENABLE_PIN PIN_B2
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_DATA4 PIN_B3
#define LCD_DATA5 PIN_B4
#define LCD_DATA6 PIN_B5
#define LCD_DATA7 PIN_B7
#include<LCD.c>
volatile unsigned int16 T1=0;
volatile unsigned int16 T0_INT_CNT=0;
volatile unsigned int16 T1_INT_CNT=0;
volatile unsigned int32 FREQ=0;
volatile float PRD=0;
void main()
{
LCD_INIT();
//setup_wdt(WDT_2304MS);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER1);
clear_interrupt(INT_TIMER0);
clear_interrupt(INT_TIMER1);
printf(LCD_PUTC," FREQUENCY METER");
printf(LCD_PUTC,"\n Please Wait");
set_timer1(0);
set_timer0(0);
while(TRUE){
//restart_wdt();
}
}
#INT_TIMER0
void TMR0_ISR(){
T0_INT_CNT++;
if(T0_INT_CNT==ONE_SEC_TICKS){
T0_INT_CNT=0;
T1=get_timer1();
FREQ=make32(T1_INT_CNT,T1); // make 32 bit value of input pulses
PRD=(1000000.0/FREQ)*1000; // nanoseconds range
///////////////////////////////////////////////////////
printf(LCD_PUTC,"\ff : %Lu Hz\n",FREQ);
if(PRD<1000)
printf(LCD_PUTC,"T : %0.3f nS",PRD);
else if(PRD>1000&&PRD<1000000){
PRD/=1000;
printf(LCD_PUTC,"T : %0.3f uS",PRD);
}
else {
PRD/=1000000;
printf(LCD_PUTC,"T : %0.3f mS",PRD);
}
hocam selamın aleyküm birkaç sorum olacaktı.
YanıtlaSil-ONE_SEC_TICKS tanımlamasını ve 3907 sayısını neden kullandık ?
-setup_wdt(WDT_2304MS); ayarını neden yaptık?
Aleykumselam kardesim bu devreyi netten alınti yapmistim. Galiba bir saniyedeki sabit deger almis.
YanıtlaSil