Hey, no problem, i think that the "TIMER" registers are all too often overlooked, and only ever used for a regular interval.
Basically TMR0 (its a zero, not an o) is a 8 bit counter, it can be set to automatically increment in the OPTION_REG, the pre-scaler is also controlled here. Basically the pre-scaler controls how many internal clock cycles have to happen before TMR0 is incremented. Remeber by that i mean an instruction cycle, ie resinator / 4.
To enable the increment from instruction cycle, BCF OPTION_REG, T0CS; (timer zero, clock source)
The pre-scaler is enabled on TMR0 with PSA (1 = on, 0 = on the watchdog timer)
The pre-scaler is controlled with PS0 , PS1 , PS2.
to enable the pre-scaler with a 1:8 ratio the code would look like
Code:
BCF OPTION_REG, T0CS
BSF OPTION_REG, PSA
BCF OPTION_REG, PS0
BSF OPTION_REG, PS1
BCF OPTION_REG, PS2
What we use this for is to determine how long it has been between high pulses
Code:
__ __
| | | |
___| |________| |____
__ __ __
| | | | | |
___| |__| |__| |____
So, we have some code that waits for the rising edge, then magnitude test the value of the TMR0 register, we need to make sure the TMR0 register won't overflow, carefull use of the pre-scaler is important here
Code:
rxreloop:
MOVLW 0x08
MOVWF LOOPREG
rxloop:
CLRF TMR0
BTFSS PORTA, 0 ; first "mark"
GOTO $-1
; First mark has passed, now wait for what is either going to be a signal high, or the next mark
BTFSS PORTA, 0
GOTO $-1
MOVLW 0x10 ; this constant must be worked out, so the time between marks (stored in tmr0)
; plus this constant is going to overflow, but a signal high, won't.
ADDWF TMR0, W
BTFSC STATUS, C
GOTO BitHigh
RFL RXREG, F
BCF RXREG, 0
DECFSZ LOOPREG, F
GOTO rxloop
AllRecived:
; Your code ere! the byte has been recived, do with it what u wish, the world is urs, knowledge is power etc.
GOTO rxreloop
BitHigh:
RFL RXREG, F
BSF RXREG, 0
DECFSZ LOOPREG, F
GOTO rxloop
GOTO AllRecived
I hope this code is correct, i haven't tested it just tapped it up here in reply.
out of intrest what is this for? it seams a rather strange project!