> Hi, > > I mentioned here a while back that I was going to make a clock, and now > it's > almost finished. It's based on a 16F690, and works great so far. > > I'm just completing the alarm functionality. The alarm needs to sound > when > the current time matches the alarm time, and these are stored as: > ; current time: > secs res 1 ; seconds > mins res 1 ; minutes (BCD) > hrs res 1 ; hours (BCD) > ; alarm time: > alm_mins res 1 ; minutes (BCD) > alm_hrs res 1 ; hours (BCD) > > AM/PM for current and alarm time at stored as single bits within a flag > register: > > flags res 1 > constant PM=0 ; time AM (0) / PM (1) > constant STANDBY=1 ; sleep mode (1) > constant DSP_OFF=2 ; display blanked during dimming (1) > constant ALM_ON=3 ; alarm on (1) > constant ALM_PM=4 ; alarm AM (0) / PM (1) > constant ALM_PRS=5 ; debounced ALARM button press (1) > constant FAST=6 ; fast time adjust mode (1) > > Most of the code sits within (or is called by) a timer ISR running every 1 > ms, which multiplexes the display and reads and responds to buttons. > Within > that timer ISR, the following routine tests for and sounds the alarm (a > piezo speaker): > > alarm ; Sound alarm if set and current time = alarm time > btfss flags,ALM_ON ; skip time test if alarm is off > goto alm_end > banksel mins ; if min = alm_mins > movf mins,w > xorwf alm_mins,w > btfss STATUS,Z > goto alm_end > movf hrs,w ; and hrs = alm_hrs > xorwf alm_hrs,w > btfss STATUS,Z > goto alm_end > banksel TMR1H ; sound alarm by beeping every other > second > btfsc TMR1H,6 ; TMR0<6> cycles at 1 Hz > goto alm_end ; so if TMR0<6> = 0 > movlw 1< xorwf sPORTA,f ; (via shadow) > > alm_end > goto display ; copy shadow regs to output and exit ISR > > Ok, so the problem with that is that I'm not checking for AM/PM. I need > to > add an "if PM = ALM_PM" to this logic, but those are bits within the > "flags" > register. > > I could of course achieve this with a series of btfss/c instructions. But > whichever way I try, it looks ugly. Frankly, C never looked better! > > So finally to the point. Does anyone know an elegant way to compare (XOR) > two bits in the same register, using midrange PIC instructions? > > > Thanks, > > David Meiklejohn > www.gooligum.com.au The following will work because of the convenient locations of the two flags PM and ALM_PM: swapf FLAGS,w xorwf FLAGS,w andlw 1 btfss STATUS,Z goto alm_end -- Bob Ammerman RAm Systems -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist