Help whit tmr1 on pic16f877a


Results 1 to 16 of 16

Threaded View

  1. #12
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Help whit tmr1 on pic16f877a

    IMHO = In My Humble Opinion, good luck. Funny I don't even use cell phone . . .

    do I have to do the hole code in assy?
    No ooooooo

    Here is a timer1 demo I made tonight for 16F690
    Code:
    @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BOR_OFF & _FCMEN_OFF & _IESO_OFF 
    INCLUDE "DT_INTS-14.bas"    ; Darrel Taylors instant interrupts
    DEFINE OSC 4 
    
    ; * * * * * * * * * * * * * Setup Darrel's Instant Interrupts * * * * * * * *
    
    ASM
    INT_LIST  macro   ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    TMR1_INT,    _Flash,   ASM,  no
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    @   INT_ENABLE   TMR1_INT     ; enable external (INT) interrupts
    
    ; * * * * * * * * * * * * * Provide system variables to save return address' * * * *
    ;wsave   VAR BYTE    $20     SYSTEM      ; location for W if in bank0
    wsave   VAR BYTE    $70     SYSTEM      ; alternate save location for W 
    ; * * * * * * * * * * * * SETUP DEBUG Parameters * * * * * * * * * * * * *
    DEFINE DEBUG_MODE  0    ' Debug sending True serial data
    DEFINE DEBUG_REG_PORTA  ' Debug Port = PortA as required by PICKIT2 serial Monitor
    DEFINE DEBUG_BIT 0      ' Debug.bit = PortA.0
    DEFINE DEBUG_BAUD 19200  ' Default baud rate = 9600
    DEFINE DEBUGIN_REG PORTA' Debug Port = PortA as required by PICKIT2 serial Monitor 
    DEFINE DEBUGIN_BIT 1    ' Debugin bit PortA.1
    DEFINE DEBUGIN_BAUD 19200' Default baud rate = 9600
    DEFINE DEBUGIN_MODE 0   ' Debugin receiving data true = 0 inverted = 1
    
    ; * * * * * * * * * * * * Setup Timer 1 registers  * * * * * * * * * * *
    
    TMR1IF var PIR1.0       ' Explain to PBP which bit is the T1IF bit 
    INTCON     = %11010000   ; GIE,PEIE,T0IE,INTE set RABIE,T0IF,INTF,RABIF cleared
    PIR1       = %00000000
    PIE1       = %00000001   ;      -,ADIE  ,RCIE ,TXIE ,SSPIE  ,CCP1IE,TMR2IE,TMR1IE
    T1CON      = %01000101   ; T1GINV,TMR1GE,T1CKP,T1CKP,T1OSCEN,T1SYNC,TMR1CS,TMR1ON
    CM2CON1    = %00000000
    
    
    temp     var word
    overFlow var word
    overFlow      = 0
    temp.highbyte = 0
    temp.lowbyte  = 0
    
    main:
       if temp.lowbyte >= 255 then
            temp.highbyte = temp.highbyte +1
            endif
       if temp >= 65535 then
          overFlow = overFlow + 1 ;track number of temp roll overs
       endif
    debug " Temp Var High = ",#temp.highbyte," Temp Var Low = ",#Temp.Lowbyte," ",10
    
    debug "OverFlow = ",#overFlow," temp var ",#temp,10
    
    
    
     goto main
    ; * * * * * * * * * * * * * End of Main Function * * * * * * * * * * * * *
    
    @ INT_DISABLE  TMR1_INT
    Flash:
            if TMR1IF  then       ; Flash is the ISR 
                temp = temp + 1 ; add 1 to timer roll over count
        endif
    TMR1L = 0                   ; preload timer 0 with ? of 255 allows you to set counts until reset
    TMR1H = 0
    TMR1IF = 0                    ; Clear T1 Interrupt flag bit
     
    @  INT_ENABLE  TMR1_INT
    @  INT_RETURN
    All this does is overflow the timer and display the results in PICKit2 USART display. It has Darrel's Instant Interrupts installed so you can pretty much copy paste, then use your registers as required
    Last edited by Archangel; - 23rd July 2013 at 10:00.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Control de puertos PIC16F877A / Port Control PIC16F877A
    By martintorres in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th October 2013, 03:49
  2. Tmr1
    By BobSpencerr in forum General
    Replies: 7
    Last Post: - 13th May 2008, 20:19
  3. Replies: 9
    Last Post: - 4th February 2008, 19:12
  4. problem whit pic18f452
    By ocastrillo in forum General
    Replies: 3
    Last Post: - 9th March 2007, 16:18
  5. TMR1 How it works?
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 12th January 2007, 14:24

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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