Hi guys,
I have a problem with following prog to measure a period. I cannot read the real value of CCPR1L and CCPR1H. When I write the eeprom on-chip (16F877A) the value stored is zero.
How can read and store the real value? I'm using the MPLAB SIM to simulate the prog.
Regards
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
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
Bookmarks