INCLUE for continuous clock


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2005
    Location
    Newcastle, Australia
    Posts
    19

    Default INCLUE for continuous clock

    Hi all,
    I have been using this little include on PIC16F876A's for ages without a flaw.
    But, for some reason it wont work in an 877A.
    Any tips or clues would be much appreciated.

    cheers
    Woodzy

    ========================================

    'FILENAME : INT.BAS
    'PROGRAM : INCLUE for continuous clock
    'DATE : 01NOV2005

    DEFINE INTHAND ROLLOVER

    wsave var BYTE $020 SYSTEM
    wsave1 var BYTE $0a0 SYSTEM
    wsave2 var BYTE $120 SYSTEM
    wsave3 var BYTE $1a0 SYSTEM
    ssave var BYTE BANK0 SYSTEM
    psave var BYTE BANK0 SYSTEM
    i_hour var BYTE
    i_minu var BYTE
    i_sec var BYTE
    i_tic var BYTE


    GOTO AFTERINT 'Jump past interrupthandler

    asm

    ROLLOVER

    ;************************************************* ****************************************
    ;************************************************* ****************************************
    ;
    ; If you are using a PIC with 2K or less,
    ; you MUST unremarke the lines that follow.
    ;
    ; movwf wsave ;only for PICs with 2k or less
    ; swapf STATUS,w ;only for PICs with 2k or less
    ; clrf STATUS ;only for PICs with 2k or less
    ; movwf ssave ;only for PICs with 2k or less
    ; movf PCLATH,w ;only for PICs with 2k or less
    ; movwf psave ;only for PICs with 2k or less
    ;
    ;************************************************* ****************************************
    ;************************************************* ****************************************

    ; interrupcode follows here


    movlw 0x58
    movwf TMR1L
    movlw 0x9e ;restart timer from ffff - 9e58 => 5Hz if using 4MHz
    movwf TMR1H
    decfsz _i_tic,f
    goto slutint
    incf _i_sec,f
    movlw 5 ;5 = 1Hz if using 4MHz (change to 10 for 8MHz and so on)
    movwf _i_tic

    movf _i_sec,w
    sublw 60
    btfss STATUS,Z ;check for 60 sec
    goto slutint ;no
    clrf _i_sec ;yes
    incf _i_minu,f

    movf _i_minu,w
    sublw 60
    btfss STATUS,Z ;check for 60 minutes
    goto slutint ;no
    clrf _i_minu ;yes
    incf _i_hour

    movf _i_hour,w
    sublw 24
    btfss STATUS,Z ;check for 24 hours
    goto slutint ;no
    clrf _i_hour ;yes

    slutint
    bcf PIR1,0 ;zero tmr1 interrupt flag


    ;end of interruptcode
    ; restorecode follows here

    movf psave,w ;restore
    movwf PCLATH
    swapf ssave,w
    movwf STATUS
    swapf wsave,f
    swapf wsave,w
    retfie

    endasm


    AFTERINT:

    INTCON = %00000000 'all interrupts off
    PIR1 = %00000000 'zero tmr1 interrupt flag
    PIE1 = %00000001 'enable timer1 interrupt
    TMR1L = $58
    TMR1H = $9e
    i_hour = 0
    i_minu = 0
    i_sec = 0
    i_tic = 5 'this value should be the same as the value of line 8 in the ISR
    T1CON = %00110001 'timer1 on, prescaler=1/8
    INTCON = %11000000 'interrupt on

    '-----------------------------------------------------------------------------------------

    ================================================

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The ASM routine assumes that the time variables are in BANK0.

    If the program has grown in size, there may be more variables which push i_hour, i_minu, i_sec and i_tic into a different Bank.

    Adding BANK0 modifiers to the variable declarations may help, but it's a long shot without knowing the rest of the code.
    If the variables are still in BANK0, I see no reason why it shouldn't work with a 16F877A.
    Code:
    i_hour var BYTE BANK0
    i_minu var BYTE BANK0
    i_sec  var BYTE BANK0
    i_tic  var BYTE BANK0
    DT

  3. #3
    Join Date
    Nov 2005
    Location
    Newcastle, Australia
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Darrel,
    Thanks mate for your quick reply.
    I will give your suggestion a go and get back to you.
    cheers
    Woodzy

  4. #4
    Join Date
    Nov 2005
    Location
    Newcastle, Australia
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Darrel,
    Thankyou sir,
    your advice worked a treat. ticking away happily now.
    cherss
    Woodzy

Similar Threads

  1. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  2. UberNewbie can't set his clock...
    By Byte_Butcher in forum General
    Replies: 19
    Last Post: - 7th January 2009, 04:22
  3. EM4095 Chip, get Clock and Data signals?
    By mindthomas in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 19th August 2008, 06:27
  4. Shiftout/in
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd August 2007, 11:48
  5. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts