Alarm code

Status
Not open for further replies.

johnl69

Member
Hello all

I have written a program for an alarm clock using assembly language for a pic16f874a with DS1307 RTC.

The time from the 1307 is stored in "Hours" and "Minutes" and the alarm time is stored in "HoursL1" and "MinutesL1".

The problem is I cant seem to figure out how I can compare the time with the alarm time to get it to trigger an event.

Can anyone point me in the right direction

thanks John
 
How are the variables "Hours", "Minutes", "HoursL1", and "MinutesL1" declared? If they are just 8bit variables, then just compare the "Hours" and "HoursL1" first. If they don't match then return from subroutine. If they match, then compare "Minutes" and "MinutesL1". If the minutes match then sound the alarm; otherwise return from subroutine.
 
Hi,

To 'compare' the two times there are a few ways - try SUBWF then BTFSS STATUS to see if the result is zero / equal
 
Thanks for your quick replies,

Hours and HoursL1 are 8 bit BCD to match the output from the 1307.

I tried the following code but the output to RD1 (which should be the alarm trigger) is on permently.

Code:
 CHECK_ALARM
           BANKSEL       HOURSL1
           MOVF           HOURSL1,W
           SUBWF         HOURS
           BTFSS          STATUS,2
           BSF              PORTD,1
           GOTO           SWITCH_MENU
 
Last edited:
Do you realise that the subwf HOURS is placing the result back in HOURS? Hours will therefore be changing rapidly and inadvertently matching hoursl1. Change it to subwf HOURS,W to keep the result in W.

Mike.
 
Last edited:
Do you realise that the subwf HOURS is placing the result back in HOURS? Hours will therefore be changing rapidly and inadvertently matching hoursl1. Change it to subwf HOURS,W to keep the result in W.

Mike.


No I never realised that,

I changed it so that it would keep the result in W but its made no different when I watch the STATUS reg the Z flag is perminently set(1) so RD1 is alwasys on.
 
No I never realised that,
I changed it so that it would keep the result in W but its made no different when I watch the STATUS reg the Z flag is perminently set(1) so RD1 is alwasys on.
If the status flag was set then the instruction to set RD1 would always be skipped. You have no instruction in the code to clear RD1. Try this code:

Code:
CHECK_ALARM
           BANKSEL       HOURSL1
           MOVF          HOURSL1,W
           SUBWF         HOURS,W
           BANKSEL       PORTD
           BTFSC         STATUS,Z
           BSF           PORTD,1
           BTFSS         STATUS,Z
           BCF           PORTD,1
           GOTO          SWITCH_MENU
 
Last edited:
The code to turn RD1 off is in another part of the program (another alarm that turns it off)

Ive played around with the code and if I change BTFSS to BTFSC the it works as it should but isnt this the wrong way around?
 
Last edited:
Ive got it now and is all working THANKs for all your help

This is the full routine;

Code:
CHECK_ALARM
      BTFSC      PORTD,1
      GOTO       ALARM_OFF1
ALARM_ON1
      BANKSEL      HOURSL1
      MOVF       HOURSL1,W
      SUBWF      HOURS,W
      BTFSC      STATUS,Z
      BSF         PORTD,1
      GOTO       SWITCH_MENU
ALARM_OFF1
      BANKSEL      HOURSL1OFF
      MOVF       HOURSL1OFF,W
      SUBWF      HOURS,W
      BTFSC      STATUS,Z
      BCF        PORTD,1
      GOTO       SWITCH_MENU
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…