Ccpr1 Register


Closed Thread
Results 1 to 6 of 6

Thread: Ccpr1 Register

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Run this in the MPLAB sim. Have the stimulus window open, click animate, and when it stops on "IF (capture = 0) Then loop" ' Wait here until captured click the stimulus "fire button" to toggle RC2.
    Code:
    DEFINE LOADER_USED 1 ' Optional, allows use of melabs Loader
    DEFINE osc 20
    
    capture VAR PIR1.2 ' CCP1 capture flag
    overflow VAR PIR1.0 ' Timer1 overflow flag
    
    A VAR WORD ' Word variable that stores the value
    I VAR BYTE
    period var WORD
    
    T1CON=%00000000 ' Timer1 reset
    TMR1L=0 ' Reset Timer 
    TMR1H=0 ' Remember Timer is OFF 
    TRISC.2 = 1
    CCP1CON=%00000000 
    CCPR1L=0 
    CCPR1H=0
    
    pir1.2=0 ' Reset Capture Flag 
    pir1.0=0 ' TMR1 register did not overflow
    
    CCP1CON = %00000101 ' Enable the CCP1 capture, RISING edge
    PIE1=%00101111 ' Enables:USART-SSP-CCP1-TMR2 to PR2 match -
    ' TMR1overflow interrupt
    
    '********************* MAIN *************************
    loop:
    IF (capture = 0) Then loop ' Wait here until captured 
    
    T1CON = %00000001 ' TMR1 prescale=1, and turn it on (1uS per count)
    CCP1CON = %00000100 ' Enable the CCP1 capture, FALLING edge
    pir1.2=0
    
    PERIOD.lowBYTE = CCPR1L ' Store the captured value in
    PERIOD.highBYTE = CCPR1H ' period variable
    
    capture = 0 ' Clear the capture flag
    
    write 0,PERIOD.lowbyte
    goto Loop
    If you're running this with animate, then go have yourself a cup of coffee because it's going to take a while before the EEPROM write happens.

    If you use the run button, then click the stimulus fire button a few times while it's running, then click stop after a few seconds. In the EEPROM window, you'll see location 00 holding the captured value.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    battlechess's Avatar
    battlechess Guest


    Did you find this post helpful? Yes | No

    Thumbs up Ccpr1 Register

    Bruce,
    Tks a lot!!!!
    It finally working!!!!

    tks a lot again

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. Can anyone help a newcomer?
    By scopit in forum Schematics
    Replies: 18
    Last Post: - 20th October 2009, 09:23
  3. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  4. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  5. MX7705 or AD7705 experience
    By FM11 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th January 2006, 21:54

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