您当前的位置:五五电子网电子知识单片机-工控设备PIC单片机PIC16F628红外接收程序 正文
PIC16F628红外接收程序

PIC16F628红外接收程序

点击数:7626 次   录入时间:03-04 11:44:18   整理:http://www.55dianzi.com   PIC单片机

    btfss    IRin            ; if the last bit was a high-low sequence, immediately set IRin
    bsf    IRin            ; high to terminate the RC5 code after the correct time

    call    delay_t6    ; 250ms delay for time decoupling (IR codes from the receiver chip
                ; occuring directly after the code generated above would destroy
                ; the integrity of this code)
    Bank_1
    bsf    IRinTris    ; set IRin to input again
    Bank_0

    return


;**************************************************************************************************
; RC5 receive routine
;**************************************************************************************************
;
; in:  14 bit data from IRin resp. DTRin
;
; out: RC5_ADR (8 bit, 000AAAAA)
;      RC5_CMD (8 bit, TCCCCCCC)
;      RC5_Flag (1 bit) 0: RC5 code valid, 1: RC5 code invalid
;
; Self-synchronizing code which tolerates inaccurate RC5 timings.
; Tolerance is achieved by polling +/- approx. 250祍 around each expected level change. To mark the
; received code as valid, the level before and after the edges must be opposite, no timer0 overflow
; (512祍) occurred, and two samples taken at 1200祍 and 1500祍 after each edge must be equal.

rc5_rx
    clrf    DATA_1        ; clear input shift register
    clrf    DATA_2        ;
    MOVlw    d’13’        ; set BITCOUNT to 13
    MOVwf    BITCOUNT    ;
    test            ; 1祍 mark
    call    delay_t1a    ; 1520祍 delay until approx. 256 祍 before next expected slope
    call    delay_t1b

pre_slope
    test            ; 1祍 mark

    clrf    tmr0            ; clear    timer0 register
        bcf       iNTCon,t0if     ; clear timer0 interrupt flag

    btfss    IR_C_out    ; IR_C_out high?
    goto    poll_lo_hi    ;

poll_hi_lo
    btfsc    intcon,t0if    ; check for timer0 overflow (after 512祍)
    goto    set_flag        ; and set ’invalid’ flag

    btfsc    IR_C_out
    goto    poll_hi_lo
    goto    next_bit1

poll_lo_hi
    bsf    DATA_1,0    ; set lsb in DATA_1

    btfsc    intcon,t0if    ; check for timer0 overflow (after 512祍)
    goto    set_flag    ; and set ’invalid’ flag

    btfss    IR_C_out
    goto    poll_lo_hi

next_bit1
    decfsz    BITCOUNT,1    ; if 0: all 14 bits received (1st was used for
    goto    shift        ; trigger and has not been recorded); do not
    goto    cleanup        ; shift any further and go on with cleanup

shift
    bcf    status,c    ; clear carry bit
    rlf    DATA_1,1    ; left shift the 16-bit register DATA_2/DATA_1
    rlf    DATA_2,1    ;

    call    delay_t1a    ; aquire sample #1
    clrf    DATA_TMP1    ; clear temporary register
    btfss    IR_C_out    ; IR_C_out low?
    bsf    DATA_TMP1,0    ; then set lsb in DATA_TMP1

    call    delay_t1b       ; aquire sample #2
    clrf    DATA_TMP2    ; clear temporary register
    btfss    IR_C_out    ; IR_C_out low?
    bsf    DATA_TMP2,0    ; then set lsb in DATA_TMP2

check                           ; check if samples are equal
    MOVfw    DATA_TMP1    ; copy DATA_1 to w,

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]  下一页


本文关键字:程序  PIC单片机单片机-工控设备 - PIC单片机