:: مهندس ::
تاريخ التسجيل: May 2010
المشاركات: 5
|
|
نشاط [ Mohamed2015 ]
قوة السمعة:0
|
|
08-05-2010, 01:34 PM
المشاركة 6
|
|
اخي ممكن من تبدأ من هنا
لما المرسل يجد Ra0 = 0 يبدأ يشتغل المرسل والعكس
emit_mode:
movf PORTB, 0
movwf RXTX_BUFFER
call tx
; Attente pour emission trame suivante
call delay_100000
goto emit_mode
;; Send a message in RXTX_BUFFER
tx:
movlw 8
movwf CNT_BIT
call send_one
call send_one
call send_chk
call send_one
call send_zero
call send_zero
tx_loop:
btfsc RXTX_BUFFER, 7 ; MSB bit First
goto tx_set
call send_zero
goto tx_next
tx_set:
call send_one
goto tx_next
tx_next:
rlf RXTX_BUFFER, 1 ; MSB -> LSB
decfsz CNT_BIT, 1
goto tx_loop
return
;;
;; RECEIVE MODE
;;
receive_mode:
call rx
call rx_action
goto receive_mode
;; Receive a message in RXTX_BUFFER
rx:
movlw 8
movwf CNT_BIT
w_1:
btfss PORTA, 1
goto w_1
w_0:
btfsc PORTA, 1
goto w_0
bsf PORTA, 3
bcf PORTA, 3
call delay_9936
rx_next:
bsf PORTA, 3
bcf PORTA, 3
rlf RXTX_BUFFER, 1
btfsc PORTA, 1
goto set_bit
clear_bit:
bcf RXTX_BUFFER, 0
goto rx_end
set_bit:
bsf RXTX_BUFFER, 0
rx_end:
;rlf RXTX_BUFFER, 1
call delay_1728
decfsz CNT_BIT, 1
goto rx_next
return
rx_action:
movf PORTB, 0
xorwf RXTX_BUFFER, 0
btfss STATUS, 2
goto wrong_key
movlw 0x01
xorwf SORTIE, 1
btfsc SORTIE, 0
goto s_1
bcf PORTA, 0
goto good_key
s_1:
bsf PORTA, 0
goto good_key
wrong_key:
call delay_40000
return
good_key:
call delay_864000
return
;; -----------
;; MODULATIONS
;; -----------
;; Send 1
send_one:
call mod_none
call mod_36k
return
;; Send 0
send_zero:
call mod_36k
call mod_none
return
send_chk:
call mod_none
call mod_none
return
;; Modulation : 32 x 27us
mod_36k:
movlw 0x20 ; 32 pulses
movwf R1
mod_36k_cont:
bsf PORTA, 0 ; bit TX a 1
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
bcf PORTA, 0 ; bit TX a 0
nop
nop
nop
nop
nop
nop
nop
nop
nop
decfsz R1, 1
goto mod_36k_cont
return
;; No modulation : 864us
mod_none:
movlw 0x8C
movwf R1
mod_none_cont:
nop
nop
nop
decfsz R1, 1
goto mod_none_cont
return
delay_100000:
movlw d'168'
movwf R1
movlw d'98'
movwf R2
movlw 1
movwf R3
goto delay
delay_40000:
movlw d'16'
movwf R1
movlw d'40'
movwf R2
movlw 1
movwf R3
goto delay
delay_864000:
movlw d'240'
movwf R1
movlw d'74'
movwf R2
movlw 3
movwf R3
goto delay
delay_1728:
movlw d'169'
movwf R1
movlw 2
movwf R2
movlw 1
movwf R3
goto delay
delay_9936:
movlw d'171'
movwf R1
movlw d'10'
movwf R2
movlw 1
movwf R3
goto delay
delay:
nop
decfsz R1, 1
goto delay
decfsz R2, 1
goto delay
decfsz R3, 1
goto delay
return
END
|