Timer1 usage in PIC18F252


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Yes, here is a quick code example:


    FastLoop:
    IF PIR1.0 = 1 THEN
    PIR1.0 = 0
    TMR1H = TimerPreloadValue.Highbyte
    TMR1L = TimerPreloadValue.Lowbyte
    GOSUB MainProgram
    ENDIF
    IF PIR1.5 = 1 THEN
    Gosub KeyboardInputRoutine ' HSERIN clears PIR1.5
    ENDIF

    GOTO FastLoop

    MainProgram:

    'Do something here every time the timer rolls over

    RETURN




    ' This works perfectly as long as your 'Main Program' never takes as long as the timer period. The code sits in the FastLoop waiting for either a keyboard input or a timer timeout. When the timer timeout occurs, then the MainProgram is executed. If you output data in your MainProgram, that data will be output at a regular interval regarless of the length of your program.
    Just remember - stay away from PAUSEs in your main program whenever possible!
    Charles Linquist

  2. #2
    EShatara's Avatar
    EShatara Guest


    Did you find this post helpful? Yes | No

    Default Thanks again

    Thanks Charles...you've been most helpful....Chris

Similar Threads

  1. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 11:49
  2. Help with TIMER1 + SLEEP
    By Yodoad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2009, 15:07
  3. Time Period of Timer1
    By arnol34 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 00:31
  4. Timer1 and Interupt wierdness
    By mind in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd August 2005, 01:24
  5. Use of Timer1 with 16F819
    By Barry Johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th January 2005, 16:25

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