Re: UART
Have a look at this is piece of code (supposed you did all necessary initializations at a prior level): we are going to the Timer0 in 16-bit mode
movlw 0x0F ;initialize countH
movwf countH
movlw 0xA0 ;initialize countL
movwf countL
movlw 0x08 ;Timer0, 16-bit, int. clock, no prescaler
movwf T0CON ;load T0CON
movlw 0x0F ;initialize the timer0 registers TMR0H and TMR0L. The initialization
movwf TMR0H ;value is 0FA0. That correspond to 4mS delay
movlw 0xA0
movwf TMR0L
bcf INTCON,TMR0IF ;clear timer0 interrupt flag
Loop1:
btfss PIR1,RCIF ;serial data received?
bra Loop1 ;no, wait
bsf T0CON, TMR0ON ;yes, start Timer0
movff RCREG,TEMP1 ;read RCREG to make the way free for the next data
; and clear the RCIF flag
Loop2:
btfss PIR1,RCIF ;serial data received?
bra Loop2 ;no, wait
bcf T0CON,TMR0ON ; yes, stop the Timer0
At that point the Timer0 contain a value that you will compare with countH and countL. If countH=TMR0H AND countL=TMR0L, then the amount of time between
the reception of two serial bytes is equal to 4mS=> means you can implement one or more of your functions right here....
If they are not equal, then you implement another function....
It should be easier to implement.....
I didn't re-read my post. If you have any question, don't hesitate...
Hope it helps.
Best regards
Kabanga