Hello, here is some spaghetti, you can remove the extra junk but it counts.
Code:'******************************************************************************* ' 'jellis00 ' File...... Toilet_Meter.BAS * ' Compiler.. PICBASIC PRO Compiler from microEngineering Labs * ' Purpose... PIC16F690 microcontroller for Toilet Meter Project * ' Author.... John R. Ellis, * ' Started... 2/20/2009 * ' * ' Updated... Version 1.0.6 on 5/2/2009 * '******************************************************************************* ' ' ' ' -----[ Device Declaration ]--------------------------------------------------* ' __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF @ __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 ' -----[ Variables Initialization ]--------------------------------------------* ' k CON 15 ' Calibration factor for flow meter = # pulses per gal i VAR Byte ' Index used in Gallon counter Repeat...Until loop ' -----[ Initialization of Registers ]-----------------------------------------* ' 'Register Settings TRISA = %00001010 ' Set PORTA pins RA1 and RA3 to inputs, others as outputs TRISB = %00000000 ' Set PORTB pins as outputs TRISC = %01000000 ' Set PORTC pin RC6 to input, all others as outputs PORTC = %0000000 ' Pre-set PORTC LED pins low, turning LEDs off 'A/D & Comparators disabled ADCON1 = %01110000 ' Set PORTA to digital I/O & FRC (clock derived from a ' dedicated internal oscillator) ANSEL=0 ' Set PortA to digital I/O ANSELH=0 ' Analog module disabled CM1CON0=0 CM2CON0=0 TRISA.1 = 1 ' Set RA1 as input port for simulated meter pulse inputs TRISA.3 = 1 ' Set RA3 as Master Reset input port PORTA.1 = 1 ' Pre-set RA1 at High value GIE VAR INTCON.1 OPTION_REG = %01110000 ' CLOCK ON RISING EDGE 'enable timer 0 count mode on RA.2 ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT_INT, _Interrupt_Handler, PBP, yes endm INT_CREATE ; Creates the interrupt processor INT_ENABLE TMR0_INT ; enable Timer 0 interrupts INT_ENABLE INT_INT ; enable external (INT) interrupts ENDASM ' Setup Interrupts INTCON = %10011000 ' Enable RA2/Int external interrupt and PORTA interrupts on ' change 'IOCA = %00000010 ' Enable RA1 for interrupt on change for pulses received ' from momentary switch, activation which simulates external HS1 sensor pulses 'on interrupt goto Int_Handler i=0 ' Initialize counter index to zero GIE = 0 ' Clear interrupt flags ' -----[ Main Code ]-----------------------------------------------------------* flush:if portA.1 = 1 then goto main else endif goto flush MAIN: IF i < k Then goto main 'k is 15 pulse threshold Else if i >= k then PULSOUT PORTC.3,1000 ' Generate required 10 msec pulse to RC3 WRITE 7,i 'Store updated count result I=0 ' CLEAR COUNTER FOR NEXT FLUSH ENDIF endif GOTO flush 'Main program loops while waiting for RA1 on change interrupt to count pulses Disable Interrupt_Handler: ' only get here if interrupt occured PULSOUT PORTC.0,500 ' Blink the LED once i = i + 1 'Increment pulse count value GIE = 0 @ INT_RETURN ; Resume ' Return to main program Enable END




Bookmarks