Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 17th August 2008, 11:36 PM   (permalink)
Default Alarm code

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
johnl69 is offline  
Old 17th August 2008, 11:51 PM   (permalink)
Default

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. ---
kchriste is offline  
Old 17th August 2008, 11:57 PM   (permalink)
Default

Hi,

To 'compare' the two times there are a few ways - try SUBWF then BTFSS STATUS to see if the result is zero / equal
richard.c is offline  
Old 18th August 2008, 01:07 AM   (permalink)
Default

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.
johnl69 is offline  
Old 18th August 2008, 01:24 AM   (permalink)
Default

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
Pommie is offline  
Old 18th August 2008, 01:33 AM   (permalink)
Default

Quote:
Originally Posted by Pommie View Post
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.
johnl69 is offline  
Old 18th August 2008, 01:54 AM   (permalink)
Default

Quote:
Originally Posted by johnl69 View Post
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
__________________
--- The days of the digital watch are numbered. ---

Last edited by kchriste; 18th August 2008 at 02:05 AM. Reason: banksel portb
kchriste is offline  
Old 18th August 2008, 02:04 AM   (permalink)
Default

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.
johnl69 is offline  
Old 18th August 2008, 02:12 AM   (permalink)
Default

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
johnl69 is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
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



All times are GMT. The time now is 07:50 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker