Вы находитесь на странице: 1из 4

PIC16F PIC16F PIC18F org 0 ;clrf STATUS clrf PCLATH goto Main org 0 ;clrf STATUS pagesel Main

goto Main org 0 goto Main

__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _MYCRYSTAL & _DEBUG_OFF __CONFIG _CONFIG2, _WRT_OFF & _BOR21V

#include "main.h" #priority CCP1, TIMER1 #define BytePtr(var, offset) #byte PIR1 = 0xF9E #bit TMR1IF = PIR1.0 int8 gc_timer1_extension = 0; int8 gc_capture_flag = FALSE; int32 g32_ccp_delta; //-----------------------------------------------------#int_timer1 void timer1_isr(void) { gc_timer1_extension++; } //-----------------------------------------------------#int_ccp1 void ccp1_isr(void) { char timer_ext_copy; int32 current_ccp; static int32 old_ccp = 0; gc_capture_flag = TRUE; current_ccp = (int32)CCP_1; (char *)(&(char *)var + offset)

// Get local copy of the timer ext. timer_ext_copy = gc_timer1_extension; if(TMR1IF) { if(*BytePtr(current_ccp, 1) < 2) // Was CCP captured after Timer1 wrapped? timer_ext_copy++; // If so, inc the copy of the timer ext. // Since we know a timer interrupt is pending, let's just // handle it here and now. That saves a little load off // the processor. gc_timer1_extension++; // Increment the real timer extension TMR1IF = 0; // Then clear the Timer1 interrupt } // Insert the timer extension into the proper place in the 32-bit // CCP value. // ie., Insert it into location "EE" as follows: 0x00EEnnnn // (nnnn = the CCP). *BytePtr(current_ccp, 2) = timer_ext_copy; g32_ccp_delta = (current_ccp > old_ccp) ? current_ccp - old_ccp : current_ccp + (0x1000000 - old_ccp); // Save the current ccp value for next time. old_ccp = current_ccp; } //======================= void turometru() { int16 frecventa; int16 frequency; int32 current_ccp_delta; set_timer1(0); setup_timer_1(T1_INTERNAL T1_DIV_BY_1); setup_ccp1(CCP_CAPTURE_RE); // Enable interrupts. clear_interrupt(INT_TIMER1); enable_interrupts(INT_TIMER1); clear_interrupt(INT_CCP1); enable_interrupts(INT_CCP1); enable_interrupts(GLOBAL); //while(1) // { disable_interrupts(GLOBAL); current_ccp_delta = g32_ccp_delta;; enable_interrupts(GLOBAL); if(gc_capture_flag == TRUE) { frequency = (int16)((5000000L + (current_ccp_delta >> 1)) / current_ccp_delta ); frecventa = (frequency * 60)/2;

lcd_gotoxy(5,1); printf(lcd_putc,"%lu\n", frecventa); printf("%lu\n\r", frecventa); // printf(lcd_putc,"%lu Hz, delta = %lx \n\r", frequency, current_ccp_delta ); gc_capture_flag = FALSE; } else { lcd_gotoxy(5,1); printf(lcd_putc,"0 \n"); printf("0 \r"); } delay_ms(100); //} }

//main.h #ifndef h_main #define h_main #include <16f887.h> #device *=16 #device adc=10 #FUSES NOWDT //No Watch Dog Timer #FUSES XT //High speed Osc (> 4mhz) #FUSES NOPUT //No Power Up Timer #FUSES NOPROTECT //Code not protected from reading #FUSES NODEBUG //No Debug mode for ICD #FUSES BROWNOUT //Reset when brownout detected #FUSES LVP //Low Voltage Programming on B3(PIC16) or B5(PIC 18) #FUSES NOCPD //No EE protection #FUSES NOWRT //Program memory not write protected #use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8) #include "flex_lcd.c" extern void porturi() { setup_adc_ports(sAN0 sAN1 sAN2); setup_adc(ADC_CLOCK_DIV_32); } #endif //main.c #include "main.h" #include "voltmetru.c" #include "meniu.c" //#include "ds1820.c"

//#include "termometru.c" #include "turometru.c" void main() { lcd_init(); //porturi(); while(1) { //front_display2(); //temperatura(); //ccp1_isr(); ccp1_isr(); turometru(); //voltmetru(); //rezervor(); //alternator(); //temperatura(); } }

//

Вам также может понравиться