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

PIC16F628红外接收程序

点击数:7626 次   录入时间:03-04 11:44:18   整理:http://www.55dianzi.com   PIC单片机
    MOVwf    trisb
    bcf    option_reg,7    ; enable portb weak pullups
    Bank_0

; configuration of analog comparators -------------------------------------------------------------

    MOVlw    b’00000110’    ; two common reference comparators with outputs
    MOVwf    cmcon
    Bank_1
    MOVlw    b’11100110’    ; Vref = 1.25 volts, connected to RA2
    MOVwf    vrcon
    Bank_0

; timer0 ------------------------------------------------------------------------------------------

    Bank_1
    MOVlw    b’01000000’     ; timer0 internal clock, prescaler 1:2, enable portb weak pullups
        MOVwf    option_reg    ;
    Bank_0

; timer1 ------------------------------------------------------------------------------------------

    MOVlw    b’00110001’    ; prescaler = 8, internal clock, enabled
    MOVwf    t1con

;**************************************************************************************************
; Main program
;**************************************************************************************************

start
    clrf    FLAGS           ; clear all flags
    call    copy_ee        ; copy default eeprom values to RAM registers

main_loop
    btfsc    ATX_C_out    ; check if ATX is standby
    goto    green        ; on --> LED green
    LED_red            ; standby --> LED red
    goto    pwr_sw
green
    LED_grn

pwr_sw
    btfss    PWRin        ; test PWRin (active low)
    goto    pwr_sw_1    ; if low goto pwr_sw_1

    btfss    IR_C_out    ; wait for high level at IR_C_out
    goto    main_loop    ;
    call    rc5_rx        ; call rc5_rx subroutine
    btfsc    RC5_Flag    ; RC5 code OK?
    goto    main_loop       ; no, goto main_loop

    LED_off            ; turn off green LED for 50ms each time a valid code
    call    delay_t4    ; has been received
    LED_grn

pwr_key                ; check if pwr key of remote control is pressed
    MOVfw    RC5_ADR        ; load RC5_ADR into w
    subwf    PWR_KEY_ADR,w    ;
    btfss    status,z    ; does PWR_KEY_ADR match?
    goto    no_match    ;  - no, goto no_match
                                ;
    MOVfw    RC5_CMD        ;  - yes, load RC5_CMD into w
    andlw    b’01111111’    ;    and clear toggle bit
    subwf    PWR_KEY_CMD,w    ;
    btfss    status,z    ; does PWR_KEY_CMD match?
    goto    no_match    ;  - no, goto no_match
                                ;
    MOVfw    RC5_CMD_TMP    ;  - yes, toggle bit also unchanged?
    subwf    RC5_CMD,w    ;
    btfss    status,z    ;
    goto    no_match    ;  - no, goto no_match
                                ;
    btfsc    ATX_C_out    ; activate PWRout only if ATX is standby to power up PC
    goto    vdr_pwr_down    ; if on, VDR’s shutdown script will turn off PC

                                ; ATX is standby, now check if pwr key of remote control is
                                ; pressed long enough (approx. TurnOnDelay * 114ms)

    incf    KEYCOUNT,f    ; - yes, unchanged, increment KEYCOUNT

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


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