shams-_-m
New Member
Hi every body
i'm working on wireless car project, and use the IR communication , as start point
i used pic16f877a for the tx & rx , i wrote the tx & rx code
the code is (8 bit code that travil in serial by the IR to the RX)
these the two codes
first tx
Code:
BUTTON_TEST ; Test The Push Button On PortB To Select The Right Code .
BUTTON_RB0
btfsc PORTB,0
CALL RB0_CODE
;LOOP_RB0
; btfsc PORTB,0
; GOTO LOOP_RB0
BUTTON_RB1
btfsc PORTB,1
CALL RB1_CODE
;LOOP_RB1
; btfsc PORTB,1
; GOTO LOOP_RB1
;BUTTON_RB2
; btfsc PORTB,2
; CALL RB2_CODE
;LOOP_RB2
; btfsc PORTB,2
; GOTO LOOP_RB2
;BUTTON_RB3
; btfsc PORTB,3
; CALL RB3_CODE
;LOOP_RB3
; btfsc PORTB,3
; GOTO LOOP_RB3
GOTO BUTTON_TEST
;********************************************************************************************************$
; Reload The Code In CODE_REG Register .
RB0_CODE
movlw b'01010101'
movwf CODE_REG
CALL SEND_CODE
return
RB1_CODE
movlw b'10101010'
movwf CODE_REG
CALL SEND_CODE
return
RB2_CODE
movlw b'11110000'
movwf CODE_REG
CALL SEND_CODE
return
RB3_CODE
movlw b'00001111'
movwf CODE_REG
CALL SEND_CODE
return
;********************************************************************************************************$
; TX Subroutine That Send The Code As Serial On PIN RC0 .
SEND_CODE
; Start Bit .
bsf PORTC,0
movlw .2
CALL DELAY_XMS
bcf PORTC,0
; 8-Bit Data Code .
DATA_CODE
btfss CODE_REG,7
bcf PORTC,0
btfsc CODE_REG,7
bsf PORTC,0
rlf CODE_REG,F
movlw .4
CALL DELAY_XMS
incf POINTER,F
movlw .8
subwf POINTER,W
btfss STATUS, Z
GOTO DATA_CODE
clrf POINTER
; Stop Bit .
bsf PORTC,0
movlw .2
CALL DELAY_XMS
bcf PORTC,0
return
and the rx
Code:
;********************************************************************************************************$
; Check For The Vaidity OF The Code And Store It If Yes .
CODE_TEST
;********************************************************************************************************$
; Check For The Start Bit .
movlw .1
CALL DELAY_XMS
btfss PORTD,0
GOTO LOOP_RD0
movlw .1
CALL DELAY_XMS
;********************************************************************************************************$
; Check For The 8-Bit Code .
CODE_ST
movlw .2
CALL DELAY_XMS
btfsc PORTD,0
bsf CODE_REG,7
btfss PORTD,0
bcf CODE_REG,7
movlw .2
CALL DELAY_XMS
movlw .2
CALL DELAY_XMS
btfsc PORTD,0
bsf CODE_REG,6
btfss PORTD,0
bcf CODE_REG,6
movlw .2
CALL DELAY_XMS
movlw .2
CALL DELAY_XMS
btfsc PORTD,0
bsf CODE_REG,5
btfss PORTD,0
bcf CODE_REG,5
movlw .2
CALL DELAY_XMS
movlw .2
CALL DELAY_XMS
btfsc PORTD,0
bsf CODE_REG,4
btfss PORTD,0
bcf CODE_REG,4
movlw .2
CALL DELAY_XMS
movlw .2
CALL DELAY_XMS
btfsc PORTD,0
bsf CODE_REG,3
btfss PORTD,0
bcf CODE_REG,3
movlw .2
CALL DELAY_XMS
movlw .2
CALL DELAY_XMS
btfsc PORTD,0
bsf CODE_REG,2
btfss PORTD,0
bcf CODE_REG,2
movlw .2
CALL DELAY_XMS
movlw .2
CALL DELAY_XMS
btfsc PORTD,0
bsf CODE_REG,1
btfss PORTD,0
bcf CODE_REG,1
movlw .2
CALL DELAY_XMS
movlw .2
CALL DELAY_XMS
btfsc PORTD,0
bsf CODE_REG,0
btfss PORTD,0
bcf CODE_REG,0
movlw .2
CALL DELAY_XMS
;********************************************************************************************************$
; Check For The Stop Bit .
movlw .1
CALL DELAY_XMS
btfss PORTD,0
GOTO LOOP_RD0
movlw .1
CALL DELAY_XMS
movlw b'10101010'
subwf CODE_REG,W
btfsc STATUS, Z
CALL SET_I
movlw b'01010101'
subwf CODE_REG,W
btfsc STATUS, Z
CALL SET_II
return
SET_I
movlw b'10000000'
movwf PORTB
return
SET_II
movlw b'01000000'
movwf PORTB
return
the rx is too long , i try to do it as the same way as tx but i couldn 't
if any one have ideas , i realy need it please....
thanxx.........
Shams........