movlw b'00000101'
movwf ccp1con ;start with rising CAPTURE
bcf pir1,2
movlw b'00000001'
movwf t1con ; on timer
Wait
btfss pir1,2
goto Wait
Hi,
Nice try, but your code is a little bit off the mark, have a look at this long thread, it contains lots of information and code examples for doing what you want down on pages 4 and 5. Can CCP do this on 16F876A?
Dear All
Can I have more reply on this
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 List p=16f877A ; List directive mentioning the PIC Microcontroller part number #include p16f877A.inc ; file having standard definitions __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF ; code assumes 20meg xtal cblock 0x020 ;start of general purpose registers CCP1aH ; first leading edge timer1 CCP1aL CCP1bH ; second leading edge timer1 CCP1bL endc ; Start at the reset vector org 0x000 goto Start Start org 0x010 clrf PORTB clrf PORTD clrf PORTC clrf TMR1H clrf TMR1L clrf CCPR1H clrf CCPR1L bsf STATUS,RP0 ;bank 1 movlw b'00000100' ; RC2 set as input movwf TRISC movlw b'00000000' movwf TRISB ;portb outputs movlw b'00000000' movwf TRISD ;portd output bcf STATUS,RP0 ;bank 0 Main movlw b'00000000' ;timer 1 using to capture, prescaler 1:1 movwf T1CON bsf T1CON,TMR1ON ; start imer bcf PIR1,CCP1IF ; clear flag movlw b'00000101' movwf CCP1CON ;start with CCP1 rising CAPTURE Wait btfss PIR1,CCP1IF ; wait for rising edge on ccp1 goto Wait movf CCPR1H,W ;save the value in CCP1aH and CCP1aL {lower value} movwf CCP1aH movf CCPR1L,W movwf CCP1aL bcf PIR1,CCP1IF Wait1 btfss PIR1,CCP1IF ; wait for 2nd rising edge goto Wait1 movf CCPR1H,W ; save now the value in CCP1bH and CCP1bL movwf CCP1bH movf CCPR1L,W movwf CCP1bL bcf PIR1,CCP1IF ;clr flag CCP1 bcf PIR1,CCP1IF loop goto loop ; knowing the osc freq of 20meg you can uses the 2 sets of timer1 vlaues to calculate the time / frequency of the pulses end
dayanpad said:thanks your reply
in mplab sim, how we give the input to RC2 pin
how know that data captured
Dear wp
as I know. we canot give Stmuli in mplab sim for RC2
Dear WP
unclear how add Stimulus while it is simulating please kindly advice me
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?