I have been reading a good example of somewhat what I need (requires modifications) at this page: http://home.citycable.ch/flotulopex/...I_Frames_e.htm
Few questions have arisen in my mind about this code:
1) Why in this code IRM_OUT is an output but being used as an input?
Code:
IRM_Out VAR PORTA.1 'IR RX Module VDD (OUT)
TRISA = %00000000 'Set Input/Output
IRM_Out = 1 'set port HIGH
WHILE IRM_Out = 1 : WEND 'Wait here until a LOW signal is incoming
FOR Ctr_A = 1 TO Max_Bit
TMR1H = 0 'Reset Timer
TMR1L = 0 'Reset Timer
T1CON.0 = 1 'Start Timer
WHILE IRM_Out = 0 : WEND 'stay here as long as input signal is LOW
T1CON.0 = 0 'Stop Timer
V_Tmr.LowByte = TMR1L ' \
V_Tmr.HighByte = TMR1H ' > Store data to LOW_BIT var
L_Bit[Ctr_A] = V_Tmr ' /
TMR1H = 0 'Reset Timer
TMR1L = 0 'Reset Timer
T1CON.0 = 1 'Start Timer
WHILE IRM_Out = 1 : WEND 'stay here as long as input signal is HIGH
T1CON.0 = 0 'Stop Timer
V_Tmr.LowByte = TMR1L ' \
V_Tmr.HighByte = TMR1H ' > Store data to HIGH_BIT var
H_Bit[Ctr_A] = V_Tmr ' /
NEXT Ctr_A
C_Led = 0
PAUSE 1000 'wait before continue
2) It is declared that 'factor is a constant =0', then what does this routine do?
Code:
'______________________________________________________________
' Factorise (time compensation due to BASIC operations latency)
FOR Ctr_A = 1 TO Max_Bit
IF L_Bit[Ctr_A] >= Factor THEN L_Bit[Ctr_A] = L_Bit[Ctr_A] + Factor
IF H_Bit[Ctr_A] >= Factor THEN H_Bit[Ctr_A] = H_Bit[Ctr_A] + Factor
NEXT Ctr_A
3) Also it will be much appreciated if someone can explain the following three routines as well, as this purpose is not clear to me
Code:
'_______________________________________________
' Rescale values (according to acquiring method???)
FOR Ctr_A = 1 TO Max_Bit
IF L_Bit[Ctr_A] > 0 THEN L_Bit[Ctr_A] = L_Bit[Ctr_A]/2
IF H_Bit[Ctr_A] > 0 THEN H_Bit[Ctr_A] = H_Bit[Ctr_A]/2
NEXT Ctr_A
'______________________________________
' Find the longest H_Bit = interval bit
' This to determine how many bits in pattern
FOR Ctr_A = 1 TO Max_Bit
IF H_Bit[Ctr_A] > Itv_Bit THEN
Itv_Bit = (H_Bit[Ctr_A] + 100) 'store the highest H_Bit value in Itv_Bit
Bit_Cnt = Ctr_A 'is the count of bits in the original pattern --- How can bit_cnt count the bits in the original pattern if it only enters this loop if H_Bit[Ctr_A] > Itv_Bit
ENDIF
NEXT Ctr_A
'___________________________________________________
' Replace all "after pattern" bits with value "zero"
FOR Ctr_A = (Bit_Cnt + 1) TO Max_Bit
L_Bit[Ctr_A] = 0
H_Bit[Ctr_A] = 0
NEXT Ctr_A
Bookmarks