-- -- Copyright (c) 2005 Riad S. Wahby -- -- This file is part of the Weston voltmeter clock code. -- -- The Weston voltmeter clock code 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. -- -- Foobar 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 Foobar; if not, write to the Free Software -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -- procedure intrh is -- this is the interrupt handler pragma interrupt assembler local dofwd local doffwd local docounter local setpwm local setrealpwm local theend bcf intcon_gie -- disable interrupts bcf status_rp1 -- in bank 0 bcf status_rp0 -- ... -- see what kind of interrupt we got btfss intcon_rbif -- if it's not a change on RB4-7 goto docounter -- then it's a counter interrupt -- handle port b btfsc pin_b4 -- if FWD goto dofwd btfsc pin_b5 -- else if not FFWD goto doffwd -- back to normal movlw 0xC4 -- increment on every 60th input movwf clkset -- movlw 1 -- increment seconds by 1 movwf sincr -- goto theend dofwd: movlw 0xFF -- increment on every input movwf clkset -- movlw 1 -- increment seconds by 1 movwf sincr -- goto theend doffwd: movlw 0xFF -- increment on every input movwf clkset -- movlw 60 -- increment seconds by 60 movwf sincr -- goto theend docounter: -- handle a counter interrupt movf clkset,w -- read in the initial counter value movwf tmr0 -- setup the next timing cycle movf sincr,w -- read in the increment addwf seclo,f -- add the increment to the seconds counter btfsc status_c -- if there was a carry incf sechi,f -- increment the high byte movf sechi,w -- load the high byte xorlw 0xA8 -- are we over 12 hours? btfss status_z -- if not goto setpwm -- just keep going movlw 0xBF -- seconds for the low byte subwf seclo,w -- subtract BF from seconds btfss status_c -- if seclo < BF goto setpwm -- just keep going clrf sechi -- else high byte is zero movwf seclo -- low byte is overflow setpwm: movf port_b,w -- read in port_b xorlw 0b_0000_0100 -- flip pin_b2 movwf port_b -- write it into port_b btfss pin_b0 -- unless in calibration mode goto setrealpwm -- put in the real data movlw 0XA8 -- otherwise put in calib data movwf ccpr1l -- high 8 bits bsf cp1x -- 2nd lsb bcf cp1y -- lsb goto theend -- and we're done setrealpwm: movf sechi,w -- load the high bits of the duty cycle movwf ccpr1l -- put them in the duty cycle register bcf cp1x -- clear p1x btfsc seclox -- but if we should set it bsf cp1x -- do so bcf cp1y -- clear p1y btfsc secloy -- but if we should set it bsf cp1y -- do so theend: bcf intcon_t0if -- clear t0if bsf intcon_t0ie -- enable timer interrupt bcf intcon_rbif -- clear rbif bsf intcon_rbie -- enable rb4:7 interrupt -- intcon_gie is set upon RETFIE end assembler end procedure