;; ;; $Id: sprinkler.asm,v 1.5 2001/10/28 12:54:28 james Exp $ ;; ;; sprinkler.asm, a PIC 16F84/12C509 based watering solenoid distributor ;; Copyright (C) 2001 James Cameron (quozl@us.netrek.org) ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2 of the License, or ;; (at your option) any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ;; processor 12c509 list f=inhx8m include "p12c509a.inc" __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC ;; ;; PIC 12C509 ;; +----------+ ;; 1 | | 8 ;; 5V ---| Vdd Vss |--- GND ;; | | ;; 2 | | 7 ;; N/C ---| GP5 GP0 |--- MOSFET Gate ;; | | ;; 3 | | 6 ;; N/C ---| GP4 GP1 |--- MOSFET Gate ;; | | ;; 4 | | 5 ;; N/C ---| GP3 GP2 |--- MOSFET Gate ;; | | ;; +----------+ ;; b_0 equ 0 ; bit numbers for solenoids b_1 equ 1 b_2 equ 2 b_input equ 3 ; bit number for input (future) m_in equ 1<>shift&0xff subwf register,f endm sub32b macro register ; initial carry, after subtract btfss status,c decf register,f endm sub32c macro register ; carry after a previous carry incf register-1,w btfsc status,z decf register,f endm sub32 macro register,constant sub32a register+3,constant,d'24' sub32a register+2,constant,d'16' sub32b register+3 sub32a register+1,constant,d'8' sub32b register+2 sub32c register+3 sub32a register,constant,d'0' sub32b register+1 sub32c register+2 sub32c register+3 endm check: sub32 r_tc_0,k_time ; try subtracting time limit btfsc r_tc_3,7 ; test result sign bit goto main ; it is negative, loop ;; result after subtracting time limit is positive, ;; therefore more than k_limit microseconds have passed, ;; store the remainder after subtraction into the counter. mov32 r_tc_0,r_us_0 ;; time is up, select next output incf r_which,f ;; branch back to the counter check, in case random data is in ;; the counter as a result of a power up, so as to prevent a ;; round-robin jitter at 15Hz. At other times, the check will ;; fail, and we'll go to main loop. goto check end