;******************************* ;;Handy Timer.asm ;1-10-2010 ;******************************* list p=12F629 radix dec include "p12f629.inc" errorlevel -302 ; Dont complain about BANK 1 Registers during assembly __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT ;Internal osc. ;_MCLRE_OFF - master clear must be off for gp3 to work as input pin ;**************************************************************** ; variables - names and files ;**************************************************************** temp1 equ 20h ; temp2 equ 21h ; temp3 equ 22h ; temp4 equ 23h ; _beepA equ 24h ;for beep tone _beepB equ 25h ;for beep tone _flash equ 26h ;for flashing the LED _potA equ 27h ;holds value 1-10 for x10minutes _potB equ 28h ;holds value 1-10 for minutes _loops equ 29h ; temp equ 2Ah ; del_x equ 2Bh ; del_y equ 2Ch ; xmin_1 equ 2Dh ; xmin_2 equ 2Eh ; xmin_3 equ 2Fh ; temp_10 equ 30h ;**************************************************************** ;Equates ;**************************************************************** status equ 0x03 rp1 equ 0x06 rp0 equ 0x05 GPIO equ 0x05 status equ 03h option_reg equ 81h ; bits on GPIO pin7 equ 0 ;GP0 out for x10mins pin6 equ 1 ;GP1 in for x10mins pin5 equ 2 ;GP2 out for mins pin4 equ 3 ;GP3 in for mins pin3 equ 4 ;GP4 piezo pin2 equ 5 ;GP5 LED ;bits rp0 equ 5 ;bit 5 of the status register ;**************************************************************** ;Beginning of program ;**************************************************************** org 0x00 nop nop nop nop nop SetUp bsf status, rp0 ;Bank 1 movlw b'11001010' ;Set TRIS GP0,2,4,5 out GP1,3,input movwf TRISIO ; bcf status, rp0 ;bank 0 movlw 07h ;turn off Comparator ports movwf CMCON ;must be placed in bank 0 call flash clrf GPIO ;Clear GPIO of junk goto Main ;**************************************************************** ;* Sub Routines and delays * ;**************************************************************** ;approx 150uS delay for loops for potA and PotB _150uS movlw .67 ;69 movwf temp1 _150u nop decfsz temp1,f goto _150u retlw 00 _20mS movlw .20 movwf temp2 _20 nop decfsz temp1,f goto _20 decfsz temp2,f goto _20 retlw 00 _500mS movlw 0FFh movwf temp2 _500 goto $+1 goto $+1 decfsz temp1,f goto _500 decfsz temp2,f goto _500 retlw 00 _x1beep movlw 80h movwf del_y movlw .45 movwf del_x nop decfsz del_x,1 goto $-2 movlw b'00010000' xorwf gpio,1 ;toggle GP4 decfsz del_y,1 goto $-8 call _500mS call _500mS retlw 00 beep movlw 0ffh movwf del_y movlw .45 movwf del_x nop decfsz del_x,1 goto $-2 movlw b'00010000' xorwf gpio,1 ;toggle GP4 decfsz del_y,1 goto $-8 call _500mS call _500mS retlw 00 longbeep movlw 0ffh movwf del_y movlw 0ffh movwf del_x nop decfsz del_x,1 goto $-2 movlw b'00010000' xorwf gpio,1 ;toggle GP4 decfsz del_y,1 goto $-8 call _500mS retlw 00 ;flash LED at start-up flash movlw 0ffh movwf _flash bsf gpio,5 nop decfsz _flash,1 goto $-2 bcf gpio,5 retlw 00 ;potA = x10minutes ;Detects position of potA ; _potA will have 0-9 potA clrf _potA clrf temp bcf gpio,0 ;to discharge 100n call _20mS call _20mS bsf gpio,0 ;to charge 100n call _150uS btfsc gpio,1 retlw 00 ;_potA & temp exits with 0-9 incf _potA,1 incf temp,1 goto $-5 potB clrf _potB clrf temp bcf gpio,2 ;to discharge 100n call _20mS call _20mS bsf gpio,2 ;to charge 100n call _150uS btfsc gpio,3 retlw 00 ;_potB & temp exits with 0-9 incf _potB,3 incf temp,1 goto $-5 ;x1min - 1 minute delay x1min movlw .78 movwf xmin_3 _1min goto $+1 goto $+1 goto $+1 goto $+1 decfsz xmin_1,f goto _1min decfsz xmin_2,f goto $+2 goto $+3 bcf gpio,5 ;give the LED illumination-time goto _1min decfsz xmin_3,f goto $+2 retlw 00 bsf gpio,5 ;flash LED goto $+1 goto $+1 goto $+1 goto $+1 goto _1min x10mins movlw .10 movwf temp_10 call x1min decfsz temp_10,1 goto $-2 retlw 00 ;**************************************************************** ;* Main * ;**************************************************************** Main call potA ;returns with value in _potA and temp movlw 00h xorwf temp,0 btfsc status,2 ;temp=00=zero "x10minutes" goto min_only call longbeep ;long beep to indicate x10minutes decfsz temp,1 goto $-2 ;temp destroyed ;only _potA 1-9 will be used call x10mins decfsz _potA,1 goto $-2 ;check for x1min set on potB call potB movlw 00h xorwf temp,0 btfsc status,2 ;temp=00=zero minutes goto $+4 ; no setting on pot call x1min decfsz _potB,1 goto $-2 call beep goto $-1 min_only call potB movlw 00h xorwf temp,0 btfsc status,2 ;temp=00=zero "x10minutes" goto Main ; no sound as no setting on pots call _x1beep ;x1_beep to indicate x1minutes decfsz temp,1 goto $-2 ;temp destroyed ;only _potB 1-9 will be used call x1min decfsz _potB,1 goto $-2 call beep goto $-1 END