A/B Long Term Timer - PIC ASM Code Example - Joe's Cat Website


This is a timer circuit which measures time in hours, minutes, seconds, and toggles two controls. The code is provided here"as is" as an example of PIC macro assembler code and is here for anyone wishing to make use of it for their own projects.

This code here was part of a project which required time events to happen at approximately 6 hours and 25 minutes apart, and to happen only once. As you can see, the code shown here is rather simple, does not make use of the watch dog timer, or do anything else after reaching "done", but it can serve as a code example for anyone interested in asm code for the pic10 or pic12 type chips.

If you are wondering what sort of circuit would make use of such a program, think of devices that require run-once timing, such as drains, gas or air vents, or anything that requires a slow sequence of power control events to happen where timing is NOT critical. This circuit can be improved by syncing to some external event (for example, sprinkler control using sun setting as an event), or using a crystal or 60Hz/50Hz power-line for timing. Basically, potential ideas can be plentiful for those who are curious and interested.

...and Good Luck with your project. I'd also be interested to hear about it.


GET THE FILE

You can download 6-Hour A/B-Timer, or you can copy and paste the code shown below into your ASM code editor.

	title	'Simple A/B timer by Jose Da Silva, 1999mar01'
	radix	dec
	list	P=12C508
	list	C=120,T=on
#include <P12C508.INC>
	__fuses _MCLRE_OFF&_CP_OFF&_WDT_OFF&_IntRC_OSC
	__idlocs h'9904'	;date code 1999, March

w	equ	0
f	equ	1

	org	8		;start of ram area
hours	res	1
mins	res	1
secs	res	4
;---------------------------------------------------------------
;
;	    pic12c508
;	+5v--|1  8|--gnd
;	gp5<-|2  7|->gp0 (A)__/^^^^^^^^^\____
;	gp4<-|3  6|->gp1 (B)_________/^^^^^\_
;	gp3->|4  5|->gp2
;
;***************************************************************
;Time Down Macro
;This macro counts down hours,minutes,seconds
;before continuing to next step
;enter: hours,minutes,seconds
;exit : ?
TmeDwnM macro	v1,v2,v3
	movlw	v1+1		;store hours to go
	movwf	hours
	movlw	v2+1		;store minutes to go
	movwf	mins
	movlw	v3+1		;store seconds to go
	movwf	secs
	call	CntDwn		;loop until everthing at zero
	endm
;***************************************************************
;Program start vector location
	org	0
Start	movlw	07fh
	movwf	OSCCAL
	movlw	b'11011111'	;set options register
	option
	clrf	GPIO		;set-up outputs
	movlw	b'00001000'	;..GPIO3 always an input
	tris	GPIO
;---------------------------------------------------------------
;Flip outputs according to specs
	movlw	b'00000001'	;set bit A and wait 6 hours
	movwf	GPIO
	TmeDwnM 6,0,0

	movlw	b'00000011'	;set bits AB and wait 25 minutes
	movwf	GPIO
	TmeDwnM 0,25,0

	movlw	b'00000010'	;set bit B and wait 25 minutes
	movwf	GPIO
	TmeDwnM 0,25,0

	movlw	b'00000000'	;turn everthing off
	movwf	GPIO
Done	goto	Done		;loop forever or until reset
;***************************************************************
;Count Down Subroutine
;Slightly longer than required, but good enough for this project
CntDwn	movlw	244		;setup 1 second loop
	movwf	secs+1
CntDwn0	movlw	0
	movwf	secs+2
CntDwn1 movlw	4		;loop for 1 second
	movwf	secs+3
CntDwn2	decfsz	secs+3,f
	goto	CntDwn2
	decfsz	secs+2,f
	goto	CntDwn1
	decfsz	secs+1,f
	goto	CntDwn0

CntDwnS decfsz	secs,f		;count down seconds left
	goto	CntDwn
	movlw	60		;setup for another 60 seconds
	movwf	secs

	decfsz	mins,f		;count down minutes left
	goto	CntDwn
	movlw	60		;setup for another 60 minutes
	movwf	mins

	decfsz	hours,f		;count down hours left
	goto	CntDwn
	return
;***************************************************************
	dt	"Copyright Jose Da Silva 1999mar01 Vancouver BC"
;***************************************************************
	org	01ffh
osc_set movlw	07fh		;load osc calibration value
	end

If you find this code (or sections of this code) useful for yourself, or a project, I will appreciate a little credit for providing it here for your use/project (for example, in your source code comments, or even a web link back to this web page is great if you have a project that uses it that you want to show/demonstrate). Thanks.

Other PIC Related Pages On This Web Site
Home Page ASCII To MorseCode Clear RAM Macro Cylon Eye Delay Macro
Random Number Generator (RNG) 7.96Hz Sinewave Generator Software RS232 Table Array FSR Macro PicDis Disassembler


Copyright© 2000..2022 Joe's Cat
counter