This code;
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 = 0 ' clear TMR0 count
Main:
IF TMR0 < K THEN
' Keep the valve open...do nothing..let water flow
ELSE
PULSOUT PORTC.3,1000 ' Generate required 10 msec pulse to RC3
WRITE 7, TMR0 ' write count if you need to?
TMR0 = 0 ' clear TMR0 count
HIGH PORTC.0 ' LED toggle stuff
PAUSE 500
LOW PORTC.0
ENDIF
GOTO Main
END
With the schematic attached - works. It writes 15 to EEPROM after precisely
15 press/release actions on the switch.
Tested on the PICkit 2 low pin count demo board.
The cap on RA3 is 0.01uF, which helps eliminate contact bounce from the switch.
The switch on the PICkit 2 demo board connects to RA3, so a wire runs directly from
RA3 to RA2. Remove the cap, and switch bounce causes problems. It's a really simple
fix.
If your circuit is powered from 5V, and you measure 5V between the PIC VDD/VSS pins,
and you only see 3.2V on RA2 with a pull-up to VDD, then check your circuit. There's a
problem somewhere with your wiring or connections.
Bookmarks