![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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.
__________________ --- The days of the digital watch are numbered. --- | |
| |
| | (permalink) |
| Hi, To 'compare' the two times there are a few ways - try SUBWF then BTFSS STATUS to see if the result is zero / equal | |
| |
| | (permalink) |
| 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 by johnl69; 18th August 2008 at 01:09 AM. | |
| |
| | (permalink) |
| 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 by Pommie; 18th August 2008 at 01:24 AM. Reason: typo | |
| |
| | (permalink) | |
| Quote:
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. | ||
| |
| | (permalink) | |
| Quote:
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
__________________ --- The days of the digital watch are numbered. --- Last edited by kchriste; 18th August 2008 at 02:05 AM. Reason: banksel portb | ||
| |
| | (permalink) |
| 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 by johnl69; 18th August 2008 at 02:09 AM. | |
| |
| | (permalink) |
| 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 | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Idea for writing code for an Alarm system | pic_programm3r | Micro Controllers | 2 | 2nd April 2008 04:36 PM |
| Need assembly code or other source code of a "Miniature digital pin number lock"... | chunei | Micro Controllers | 1 | 13th August 2007 06:45 PM |
| 16F84A project... need source code for an alarm system im making | wazza_d | Electronic Projects Design/Ideas/Reviews | 0 | 16th May 2007 10:33 AM |
| some testing code.... of code of 89C51 for LCD | kumar_3k | Electronic Projects Design/Ideas/Reviews | 0 | 5th November 2003 06:23 PM |
| ADT Alarm | midas10000 | General Electronics Chat | 3 | 13th March 2003 11:30 PM |