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

PIC16F628红外接收程序

点击数:7626 次   录入时间:03-04 11:44:18   整理:http://www.55dianzi.com   PIC单片机
    call    delay_t6    ; that a valid code has been received
    LED_off

    clrf    KEYCOUNT_1    ; clear KEYCOUNT_1 to reset zero key detection delay
    goto    main_loop

ir_chk1                ; wait for high level at IR_C_out, timeout if idle for > 5s
    clrf    tmr1h        ; clear timer1 registers
    clrf    tmr1l
    MOVlw    d’19’           ; set COUNT to d’19’, this makes 19 x 262ms = approx. 5 seconds
    MOVwf    COUNT

ir_chk2
    btfsc    IR_C_out    ; wait for high level at IR_C_out
    return            ; and return

    btfsc    tmr1h,7        ; check timer1 h register bit 7 (set after 262ms)
    goto    dec_cnt
    goto    ir_chk2

dec_cnt
    clrf    tmr1h        ; clear timer1 registers
    clrf    tmr1l
    decfsz    COUNT,f
    goto    ir_chk2        ; not yet 5s, loop
    clrf    KEYCOUNT_1    ; clear KEYCOUNT_1 to reset zero key detection delay
    goto    main_loop    ; timeout after approx. 5s


;**************************************************************************************************
; RC5 transmit subroutine
;**************************************************************************************************

rc5_tx                ; we have: RC5 address ’000AAAAA’ and command ’0CCCCCCC’
    bsf    RC5_TX_2,7    ; set 1st start bit
    btfss    RC5_TX_1,6    ; check command bit #6 and
    bsf    RC5_TX_2,6    ; set 2nd start bit if necessary
    bcf    status,c    ; clear carry bit
    rlf    RC5_TX_1    ; left shift RC5_TX_1 twice to bring command MSB to
    bcf    status,c    ; left-most position
    rlf    RC5_TX_1    ; now the 16-bit shift register is ready for
                ; shifting out: RC5_TX_2 1S0AAAAA   RC5_TX_1 CCCCCC00

    bsf    IRin        ; set port register bit IRin high before setting to output
    Bank_1            ; to avoid a 1祍 spike
    bcf    IRinTris    ; set IRin as output
    Bank_0            ;

    call    delay_t6    ; 250ms delay for time decoupling (LIRC might still be busy with
                ; processing IR codes from the receiver and would not react to the
                                ; the code generated below)

    MOVlw    d’14’        ; set BITCOUNT to 14
    MOVwf    BITCOUNT    ;

bit_test
    btfss    RC5_TX_2,7    ; test all bits
    goto    out_low_high    ; remember that we have to invert them

out_high_low
    bsf    IRin        ; output a high-low sequence at IRin
    call    delay_t5    ; either state is 889祍
    bcf    IRin        ;
    call    delay_t5    ;
    goto    next_bit    ; goto next_bit

out_low_high
    bcf    IRin        ; output a low-high sequence at IRin
    call    delay_t5    ; either state is 889祍
    bsf    IRin        ;
    call    delay_t5    ;

next_bit
    rlf    RC5_TX_1    ; left shift the 16-bit register
    rlf    RC5_TX_2    ;
    decfsz    BITCOUNT    ; until all 14 bits are out
    goto    bit_test    ;

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


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