Non interrupt version;
With DT interrupts; Note that now you need to use the MPASMCode:@ device pic16F690, intrc_osc_noclkout, wdt_off, mclr_off, protect_off K CON 15 ' Calibration factor for flow meter = # pulses per gal ' Setup Timer0 as an 8-bit counter with the clock input on RA2. ' 1:1 TMR0 prescaler ' TMR0 counts on high-to-low transitions OPTION_REG = %00111000 ' A/D & Comparators disabled ANSEL=0 ' all digital ANSELH=0 ' analog module disabled CM1CON0=0 CM2CON0=0 ' Port setup PORTC = 0 ' LEDs off, PULSOUT RC3 provides a high-going pulse PORTA = 0 TRISC = %11110000 ' lower 4 pins outputs TRISA = %11111111 ' RA2 = TMR0 clock input for simulated meter pulse inputs TMR0 = 0 ' clear TMR0 count Main: IF TMR0 < K THEN ' Keep the valve open...do nothing..let water flow ELSE TMR0 = 0 ' clear TMR0 count PULSOUT PORTC.3,1000 ' Generate required 10 msec pulse to RC3 ' WRITE 7, TMR0 ' write count if you need to? HIGH PORTC.0 ' LED toggle stuff PAUSE 500 LOW PORTC.0 ENDIF GOTO Main END
assembler & config settings for MPASM.
Then of course, you can do pretty much the same by just watching the Timer0Code:@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR0_INT, _FlusO_Matic, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM K CON 15 ' Calibration factor for flow meter = # pulses per gal ' Setup Timer0 as an 8-bit counter with the clock input on RA2. ' 1:1 TMR0 prescaler ' TMR0 counts on high-to-low transitions OPTION_REG = %00111000 ' A/D & Comparators disabled ANSEL=0 ' all digital ANSELH=0 ' analog module disabled CM1CON0=0 CM2CON0=0 ' Port setup PORTC = 0 ' LEDs off, PULSOUT RC3 provides a high-going pulse PORTA = 0 TRISC = %11110000 ' lower 4 pins outputs TRISA = %11111111 ' RA2 = TMR0 clock input for simulated meter pulse inputs TMR0 = 241 ' preload TMR0 to overflow after 15 counts @ INT_ENABLE TMR0_INT ; enable TMR0 counter interrupt Main: PAUSE 1 GOTO Main FlusO_Matic: TMR0 = 241 ' reload TMR0 to overflow after 15 counts PULSOUT PORTC.3,1000 ' Generate required 10 msec pulse to RC3 ' WRITE 7, TMR0 ' write count if you need to? @ INT_RETURN END
interrupt flag;
And, last, but not least, there's the old stand-by ON INTERRUPT;Code:@ device pic16F690, intrc_osc_noclkout, wdt_off, mclr_off, protect_off K CON 15 ' Calibration factor for flow meter = # pulses per gal ' Setup Timer0 as an 8-bit counter with the clock input on RA2. ' 1:1 TMR0 prescaler ' TMR0 counts on high-to-low transitions OPTION_REG = %00111000 ' A/D & Comparators disabled ANSEL=0 ' all digital ANSELH=0 ' analog module disabled CM1CON0=0 CM2CON0=0 ' Port setup PORTC = 0 ' LEDs off, PULSOUT RC3 provides a high-going pulse PORTA = 0 TRISC = %11110000 ' lower 4 pins outputs TRISA = %11111111 ' RA2 = TMR0 clock input for simulated meter pulse inputs TMR0 = 241 ' preload TMR0 to overflow after 15 counts TMRO_INT_FLAG VAR INTCON.2 ' Timer0 overflow flag bit INTCON = 0 ' not using interrupts + clear Timer0 int flag Main: WHILE TMRO_INT_FLAG = 0 WEND PULSOUT PORTC.3,1000 ' Generate required 10 msec pulse to RC3 ' WRITE 7, TMR0 ' write count if you need to? TMRO_INT_FLAG = 0 ' clear overflow flag TMR0 = 241 ' reload TMR0 to overflow after 15 counts GOTO Main END
All kept really simple & fairly easy to follow/modify...;o}Code:@ device pic16F690, intrc_osc_noclkout, wdt_off, mclr_off, protect_off K CON 15 ' Calibration factor for flow meter = # pulses per gal ' Setup Timer0 as an 8-bit counter with the clock input on RA2. ' 1:1 TMR0 prescaler ' TMR0 counts on high-to-low transitions OPTION_REG = %00111000 ' A/D & Comparators disabled ANSEL=0 ' all digital ANSELH=0 ' analog module disabled CM1CON0=0 CM2CON0=0 ' Port setup PORTC = 0 ' LEDs off, PULSOUT RC3 provides a high-going pulse PORTA = 0 TRISC = %11110000 ' lower 4 pins outputs TRISA = %11111111 ' RA2 = TMR0 clock input for simulated meter pulse inputs TMR0 = 241 ' preload TMR0 to overflow after 15 counts TMRO_INT_FLAG VAR INTCON.2 ' Timer0 overflow flag bit INTCON = %10100000 ' enable global & Timer0 interrupt ON INTERRUPT GOTO FlushOMatic Main: PAUSE 1 GOTO Main DISABLE FlushOMatic: PULSOUT PORTC.3,1000 ' Generate required 10 msec pulse to RC3 ' WRITE 7, TMR0 ' write count if you need to? TMRO_INT_FLAG = 0 ' clear overflow flag TMR0 = 241 ' reload TMR0 to overflow after 15 counts RESUME ENABLE END




Bookmarks