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

PIC16F628红外接收程序

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

r_flash
    LED_red            ; turn on red LED
    call    tim_sub         ; call timer subroutine and check if any remote key is pressed
    LED_off            ; turn off LED
    call    tim_sub         ; call timer subroutine and check if any remote key is pressed
    decfsz    COUNT,f
    goto    r_flash        ; and loop
    goto    main_loop    ; timeout after approx. 30 seconds (if shutdown fails)

tim_sub                ;
    clrf    tmr1h        ; clear timer1 registers
    clrf    tmr1l        ;

ir_chk
    btfss    IR_C_out    ; high level at IR?
    goto    tim_chk        ;  - no, check timer1
    call    rc5_rx        ;  - yes, call rc5_rx subroutine
    btfsc    RC5_Flag    ; RC5 code OK?
    goto    tim_chk        ;  - no, check timer1

    MOVfw    RC5_CMD        ; copy RC5_CMD to w and
    andlw    b’01111111’    ; clear toggle bit
    bcf    status,c    ; clear carry bit
    subwf    PWR_KEY_CMD,w     ; check if command is pwr key; this will be ignored
    btfss    status,z    ;
    goto    main_loop    ; key pressed, abort shutdown and goto main_loop

tim_chk                ;
    btfss    tmr1h,7        ; check timer1 h register bit 7 (set after 262ms)
    goto    ir_chk        ; loop if not yet set

atx_chk
    btfsc    ATX_C_out    ; wait until ATX is standby
    return            ; still on, continue flashing

    goto    main_loop    ; now standby, goto main_loop

;**************************************************************************************************
; Program mode
;**************************************************************************************************

pgm_mode
    MOVlw    d’4’
    MOVwf    COUNT

rg_flash
    LED_red            ; flash bicolor LED aLTErnately green/red
    call    delay_t6    ; (either for 250 ms) 4 times to indicate
    LED_grn                 ; that the program mode has been entered
    call    delay_t6
    decfsz    COUNT
    goto    rg_flash
    LED_off            ; now ready to learn codes (LED off)

learn_1
    call    ir_chk1        ; wait for high level at IR_C_out, timeout if idle for > 5s
    call    rc5_rx        ; call rc5_rx subroutinee
    btfsc    RC5_Flag    ; RC5 code OK?
    goto    learn_1        ; no, try again

    MOVfw    RC5_CMD        ; copy RC5_CMD to w and
    andlw    b’01111111’    ; clear toggle bit
    MOVwf    TMP1        ; copy to TMP1 and TMP2
    MOVwf    TMP2        ;
    bsf    status,c    ; check if command is 0...9
    sublw    d’9’
    btfss    status,c
    goto    learn_1        ; no, try again

    LED_grn            ; turn on green LED for 250ms if a
    call    delay_t6    ; valid code has been received
    LED_off

    MOVfw    RC5_CMD        ; copy RC5_CMD to temporary register
    MOVwf    RC5_CMD_TMP    ; for the next toggle bit comparison

    bcf    status,c    ; multiply TMP1 by 10

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


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