; chargetimer.asm
; David Rowe Dec 2009
;
; Sets PowerSwitch H for 90 minutes, then takes it low for 30 seconds.
; Cycle repeats indefinately.  Purpose is to reset AGM charger logic which
; times out after about 2 hours when charging Lithiums.
;
; PIC12F510 Assembler program, MPLAB V8.10 IDE used to build.
;;
;---------------------------------------------------------------------
; Copyright (C) 2009 David Rowe
;
; 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
;---------------------------------------------------------------------
;
; PINOUT
; ======
;                   ____  ____
;                  |    \/    |   
;            N/C --| 1      8 |-- Spare Input
;                  |          |
;            VCC --| 2      7 |-- GND
;                  |          |
;      Spare I/O --| 3      6 |-- N/C 
;                  |          |
;      Spare I/O --| 4      5 |-- PowerSwitch (out)
;                  |__________|
;
;
;             Pin | Function    | PIC Name
;            -----|-------------|---------
;              3  | Spare I/O   |  GP2
;              4  | Spare I/O   |  GP1
;              5  | PowerSwitch |  GP0
;              8  | Spare Input |  GP3
;
; 
; PIC PROGRAMMING OPTIONS
; =======================
;
; MCLRE=I/O, INTOSC, disable Watchdog timer

#include <p10f200.inc>
 __CONFIG _CP_OFF & _WDT_OFF & _MCLRE_OFF

; VARIABLES ---------------------------------------------------------------------

; 2 second delay variables

d1		equ	0x10
d2		equ	0x11
d3		equ	0x12

; 1 minute delay variable

d4		equ	0x13

; outer loop delay variable

d5		equ	0x14

; START PROGRAM ----------------------------------------------------------------

; configure GP[0] as digital output  (PowerSwitch)

	movlw	b'00001110'
	tris	GPIO

main

	bsf	GPIO,0		; turn on PowerSwitch 
	movlw	90		; 90 minute delay
	movwf	d5	
l_on
	call	one_minute_delay	
	decfsz	d5, f
	goto	l_on

	bcf	GPIO,0		; turn off powerswitch
	movlw	10		; 30 second delay
	movwf	d5	
l_off
	call	two_sec_delay
	decfsz	d5, f
	goto	l_off

	goto	main

; START FUNCTIONS ------------------------------------------------------------

; http://www.piclist.com/techref/piclist/codegen/delay.htm
; Delay measured as 2.8 seconds usog internal clock

; Actual delay = 2 seconds = 2000000 cycles
; Error = 0 %

two_sec_delay
			;1999996 cycles
	movlw	0x11
	movwf	d1
	movlw	0x5D
	movwf	d2
	movlw	0x05
	movwf	d3
l_two
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	l_two

			;4 cycles
	goto	$+1
	goto	$+1

	retlw	0

; one minute delay -------------------------------
	
one_minute_delay
	movlw	20
	movwf	d4
l_one
	call	two_sec_delay
	decfsz	d4, f
	goto	l_one

	retlw	0
	
	end


