这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 通讯及无线技术 » 无线接收Ev1527的pic单片机软件接收解码程序

共1条 1/1 1 跳转至

无线接收Ev1527的pic单片机软件接收解码程序

菜鸟
2011-12-02 15:25:12     打赏
用于汽车遥控的Ev1527的pic单片机软件接收解码程序,密码采用I2C总线方式存在EEPROM中-Remote control for automotive Ev1527 the pic Singlechip software decoder to receive the procedure, the password using I2C bus EEPROM in ex   LIST      P=16f57           #INCLUDE "p16F5X.INC"            __CONFIG _CP_OFF&_WDT_OFF&_XT_OSC ;说明:SCL接单片机   RC0 ;    : SDA接单片机   RC1      ;------------------------------------------------------------         ;寄存器定义                        ;------------------------------------------------------------        BY_COUNT  EQU 14H         ;I2C COUNT_T0 EQU 12H                COUNT_T1 EQU 13H COUNT    EQU 11H STATUS   EQU 3H PORTB    EQU 6H PORTC    EQU 7H EEPROM   EQU 08H ADDR     EQU 09H BUFIN    EQU 0AH BUFOUT   EQU 0BH SLAVE    EQU 0CH TXBUF    EQU 0DH BIT      EQU 0EH DLY1     EQU 0FH DLY2     EQU 10H ;******************************************   FLAG      EQU 20H IN_DATA_0 EQU 19H IN_DATA_1 EQU 1AH IN_DATA_2 EQU 1BH COUNTER0       EQU     15H                            ;计数器 COUNTER1       EQU     16H COUNTER2       EQU     17H COUNTER3       EQU     18H CAR_STATUS     EQU 1CH                        ;       W_SHADOW       EQU 1DH                        ;函数调用时传送参数 COUNTER        EQU 1EH                         DATA1       EQU 1FH         ;保留四位按键信息 DEVICE_W       EQU B'10100000'        ; DEVICE_R       EQU B'10100001'        ;                ADR_LOCK       EQU 0x00                       ;存储器锁门指令入口 ADR_UNLOCK     EQU 0x10                       ;存储器开门指令入口                DATA_2         EQU     B'11001111' DATA_1         EQU     B'00100111' DATA_U         EQU     B'10111000' DATA_L         EQU     B'10110100'                ;都为反码 与上位机通信 COMC_LOCK      EQU     B'11110111'            ;开锁指令              00001000B      COMC_UNLOCK    EQU     B'11110001'            ;锁门指令              00001110B COMC_RELAY     EQU     B'11110010'            ;继电器指令            00001101B PORTA_S EQU     B'11110001' DI       EQU 7 DO       EQU 6 SDA      EQU 1 SCL      EQU 0 ACKF     EQU 0     ;--------------------------------------------------------------   ;定义管脚         ;-------------------------------------------------------------           #define    STUDY    PORTC,6           #define    SIGNAL   PORTC,3           #define    LIGHT    PORTC,5                              ORG      00H           GOTO     INT_INIT ;********************** BSTART        BSF   PORTC,SDA        BSF    PORTC,SCL        MOVLW B'11001000'        TRIS   PORTC        NOP        NOP        NOP        NOP        NOP        NOP        BCF    PORTC,SDA        NOP        NOP        NOP        NOP        NOP        BCF    PORTC,SCL        NOP        NOP        RETLW 0 ;********************** BSTOP        BCF    PORTC,SDA        MOVLW B'11001000'        TRIS   PORTC        BCF    PORTC,SDA        NOP        NOP        NOP        BSF    PORTC,SCL        NOP        NOP        NOP        BSF    PORTC,SDA        NOP        NOP        BCF    PORTC,SCL        NOP        NOP        RETLW 0 ;********************** TX            MOVLW D'8'        MOVWF BIT TXLP   BCF    EEPROM,DO        BTFSC TXBUF,7        BSF    EEPROM,DO        CALL   BITOUT        RLF    TXBUF,1        DECFSZ BIT,1        GOTO   TXLP        CALL   BITIN        BTFSC EEPROM,DI        BSF    PORTC,ACKF        RETLW 0 ;************************ RX        CLRF   BUFIN        MOVLW D'8'        MOVWF BIT        BCF    STATUS,0 RXLP   RLF    BUFIN,1        BCF    BUFIN,0        CALL   BITIN        BTFSC EEPROM,DI        BSF    BUFIN,0        DECFSZ BIT        GOTO   RXLP        NOP        RETLW 0 ;********************** BITOUT        MOVLW   B'11001000'        tris    PORTC        BTFSS   EEPROM,DO        GOTO    BITLOW        BSF     PORTC,SDA        GOTO    CLKOUT BITLOW BCF     PORTC,SDA CLKOUT BSF     PORTC,SCL        NOP        NOP        NOP        NOP        BCF     PORTC,SCL        RETLW   0 ;********************** BITIN        BSF     EEPROM,DI        MOVLW   B'11001010'        TRIS    PORTC        BSF     PORTC,SCL        NOP        NOP        NOP        NOP        NOP        BTFSS   PORTC,SDA        BCF     EEPROM,DI        BCF     PORTC,SCL        RETLW   0 ;--------------------------------- ;延时1s ;---------------------------------`           DELAY_1S:                                                    ;延时1s                MOVLW 04H                                     ;3+1                MOVWF COUNTER1                MOVLW 0AH                                     ;10                MOVWF COUNTER2                MOVLW 031H                                    ;49                MOVWF COUNTER3                                                                      ;49*5+(256*5+5)*10+[(256*5+5)*256+5]*3+10=1,000,000us DELAY_1S_WAIT                NOP                           NOP                DECFSZ COUNTER3,F                GOTO DELAY_1S_WAIT                NOP                NOP                DECFSZ COUNTER2,F                GOTO DELAY_1S_WAIT                NOP                CLRWDT                DECFSZ COUNTER1,F                GOTO DELAY_1S_WAIT                ;DECFSZ COUNTER0,F                ;GOTO DELAY_WAIT DELAY_RET                RETLW 0              ;****************************************   DELAY_10MS        MOVLW D'13'        MOVWF DLY1        MOVLW 0FFH        MOVWF DLY2 LP0    DECFSZ DLY2,1        GOTO   $-1        DECFSZ DLY1,1        GOTO   $-5        RETLW 0     ;********************************************       WR_EEPROM        BTFSC FLAG,1        GOTO   OUT1        MOVLW B'00000000'        TRIS   PORTC        CLRF   PORTC          CLRF   PORTC        MOVLW B'10100000'        MOVWF SLAVE        MOVLW 13H        MOVWF FSR          ;IN_DATA_0地址        MOVLW B'10101100'        MOVWF BUFOUT        CLRF   ADDR        CALL   BSTART        MOVF   SLAVE,0        MOVWF TXBUF        CALL   TX        MOVF   ADDR,0        MOVWF TXBUF        CALL   TX        MOVF   INDF,0        MOVWF TXBUF        CALL   TX        INCF   FSR        MOVF   INDF,0        MOVWF TXBUF        CALL   TX        INCF   FSR        MOVF   INDF,0        MOVWF TXBUF        CALL   BSTOP OUT1   RETLW 0 ;*****************************************   XIANSHI        MOVLW    08H       MOVWF    COUNT LOOP   BTFSC    BUFIN,7        BSF      PORTC,5        CALL     DELAY_1S              BCF      PORTC,5               CALL     DELAY_1S        RLF      BUFIN,1        DECFSZ   COUNT,1        GOTO     LOOP        BCF      PORTC,5        RETLW    0  ;********************************          ;------------------------------------------------------------ ;25ms计时子程序 ;------------------------------------------------------------          DELAY_25            MOVLW     20H          MOVWF     COUNT_T0 DELAY    CLRWDT          MOVLW     0FFH          MOVWF     COUNT_T1 DELAY1   DECFSZ    COUNT_T1,1          GOTO      DELAY1          DECFSZ    COUNT_T0,1          GOTO      DELAY          RETLW     0 ;------------------------------------------------------------ ;250ms计时子程序 ;------------------------------------------------------------         DELAY_250          MOVLW     0F2H          MOVWF     COUNT_T0 DELAY2   CLRWDT                                 MOVLW     0FFH          MOVWF     COUNT_T1 DELAY21 NOP                           ;内层循环1024us          DECFSZ    COUNT_T1,1                  GOTO      DELAY21          DECFSZ    COUNT_T0,0          GOTO      DELAY2          RETLW     0           ;------------------------------------------------------------- ;主程序开始 ;-------------------------------------------------------------                    ORG      100H INT_INIT                               BANKSEL PORTC                MOVLW B'11001000'                     TRIS PORTC                CLRF PORTC         CLRF FLAG                MOVLW 00H         MOVWF IN_DATA_0                MOVWF IN_DATA_1                MOVWF IN_DATA_2                MOVWF COUNTER                MOVWF COUNTER0                MOVWF COUNTER1                MOVWF COUNTER2                        SIGNAL_SERVICE                                ;COUNTERX 计数器分配混乱,需要调整                BTFSS SIGNAL                GOTO SIGNAL_RET                CLRF COUNTER0 SIGNAL_SYN_HIGH                  CLRWDT                BTFSS SIGNAL                GOTO SIGNAL_SYN_HIGH_TEST                            INCF COUNTER0,F                BTFSS STATUS,Z                GOTO SIGNAL_SYN_HIGH                GOTO SIGNAL_RET                SIGNAL_SYN_HIGH_TEST           ;210us                MOVLW D'30'                    ;30?这个取值需要重新计算                SUBWF COUNTER0,W                BNC SIGNAL_RET                CLRF COUNTER1   SIGNAL_SYN_LOW                                       GOTO $+1                GOTO $+1                GOTO $+1                GOTO $+1                GOTO $+1                GOTO $+1                CLRWDT                BTFSC SIGNAL                GOTO SIGNAL_RET                DECFSZ COUNTER1,F                GOTO SIGNAL_SYN_LOW                SIGNAL_SYN_LOW_WAIT                CLRWDT                BTFSS SIGNAL                GOTO SIGNAL_SYN_LOW_WAIT                             MOVLW D'24'                MOVWF COUNTER2   SIGNAL_PERIOD_START                CLRF COUNTER0                CLRF COUNTER3   SIGNAL_PERIOD_LOW_WAIT                CLRWDT                GOTO $+1                BTFSC SIGNAL                GOTO SIGNAL_PERIOD_HIGH                INCFSZ COUNTER0,F                GOTO SIGNAL_PERIOD_LOW_WAIT                GOTO SIGNAL_RET   SIGNAL_PERIOD_HIGH                                           ;6个时钟周期                CLRWDT                BTFSS SIGNAL                GOTO SIGNAL_PERIOD_VALUE_JUDGE                INCFSZ COUNTER3,F                GOTO SIGNAL_PERIOD_HIGH                GOTO SIGNAL_RET                SIGNAL_PERIOD_VALUE_JUDGE                            MOVLW D'20'                                           ;高电平小于120us 退出                SUBWF COUNTER3,W                BNC SIGNAL_RET                BCF FLAG,0                MOVLW D'80'                                           ;高电平大于120us 小于480us判断为‘0’                SUBWF COUNTER3,W                              ;              大于480us 判断为‘1’                BNC SIGNAL_PERIOD_VALUE_SAVE                BSF FLAG,0                SIGNAL_PERIOD_VALUE_SAVE                                               RLF IN_DATA_0,F                RLF IN_DATA_1,F                RLF IN_DATA_2,F                BCF IN_DATA_0,0                BTFSC FLAG,0                BSF IN_DATA_0,0                DECFSZ COUNTER2,F                GOTO SIGNAL_PERIOD_START                                                                            BSF LIGHT                    ;收到信号,闪3下                CALL DELAY_1S                BCF LIGHT                CALL DELAY_1S                               BSF LIGHT                CALL DELAY_1S                BCF LIGHT                CALL DELAY_1S                               BSF LIGHT                CALL DELAY_1S                BCF LIGHT                CALL DELAY_1S             MOVLW    0FH                                           ANDWF    IN_DATA_0,W                MOVWF    DATA1            ;屏蔽低4位,保留地址码值                MOVLW    0F0H                ANDWF    IN_DATA_0,F      ;屏蔽高4位,保留键码值 ;-------------------------------------------------------------------------------------------           ;对接收到的数据进行处理,若为初始化(学习),则将数据存入EEPROM;否则,给出开锁或者上锁信号 ;------------------------------------------------------------------------------------------ SIGNAL_PROCESSING        BCF      PORTC,0        BCF      PORTC,1                  ;BTFSC    STUDY        ;GOTO     WRITE                  MOVLW 40H        MOVWF FSR        MOVLW 03H         ;3次读        MOVWF BY_COUNT        CLRF   PORTC        MOVLW B'10100000'        MOVWF SLAVE        CLRF   ADDR        CALL   BSTART        MOVF   SLAVE,0        MOVWF TXBUF        CALL   TX        MOVF   ADDR,0        MOVWF TXBUF        CALL   TX        CALL   BSTART        MOVLW B'10100001'        MOVWF TXBUF        CALL   TX RBYTE CALL   RX        MOVF   BUFIN,0        MOVWF INDF        INCF   FSR        DECFSZ BY_COUNT,1        GOTO   LOWACK        BSF    EEPROM,DO        CALL   BITOUT        CALL   BSTOP        GOTO   OUT2        LOWACK BCF    EEPROM,DO        CALL   BITOUT        CALL   XIANSHI        GOTO   RBYTE        NOP                                          OUT2      MOVLW    B'11001000'           TRIS     PORTC           BSF      LIGHT               ;读完闪1次           CALL     DELAY_1S           BCF      LIGHT           GOTO     CHECK_AD WRITE     CALL     WR_EEPROM           BSF      FLAG,1          BSF      LIGHT           CALL     DELAY_250           BCF      LIGHT               ;进入写EEPROM           GOTO     EXIT                                ;----------------------------------------------------------- ;比较地址码 ;-----------------------------------------------------------               CHECK_AD MOVLW    40H                                   MOVWF    FSR           MOVF     IN_DATA_0,0           XORWF    INDF,0           BTFSS    STATUS,Z           GOTO     EXIT           INCF     FSR,1           MOVF     IN_DATA_1,0           XORWF    INDF,0           BTFSS    STATUS,Z           GOTO     EXIT           INCF     FSR,1           MOVF     IN_DATA_2,0           XORWF    INDF,0           BTFSS    STATUS,Z           GOTO     EXIT           ;地址码不对,跳出 ;------------------------------------------------------------------ ;检查指令 ;-------------------------------------------------------------------                   GOTO     OPEN DONE      MOVF     DATA1,0                         XORLW    00H           BTFSS    STATUS,Z           GOTO     OPEN           GOTO     EXIT OPEN      BSF      PORTC,5           CALL     DELAY_250           BCF      PORTC,5           CALL     DELAY_250           BSF      PORTC,5           CALL     DELAY_250           BCF      PORTC,5 EXIT                NOP                            SIGNAL_RET                GOTO SERVICE_END SERVICE_END                                 NOP                NOP                BTFSC SIGNAL                          ;SIGNAL =1外部有信号输入                GOTO SIGNAL_SERVICE                NOP                                       NOP                NOP                NOP                NOP                NOP                               GOTO SERVICE_END               END                                                                                                                                                          深圳市晶美润科技有限公司                 
        销售工程师:尤竹旺 QQ820693572 0755 – 88351224 13728989126



关键词: 无线     接收     Ev1527     单片机     软件     解码     程序    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]