单片机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2319|回复: 2
打印 上一主题 下一主题
收起左侧

pic单片机驱动SM311电源开关汇编程序

[复制链接]
跳转到指定楼层
楼主
;LIST P=SM311, CLOCK=4MHZ, WDT=DISBALE,INT=ENABLE
;-----------------------------------------------------------
;     LOUDOUT  RA0  1             14  RA1  WHITE_BULB
;   SIGNAL_IN  RB7  2             13  RA2  BLUE_BULB
;        READ  RB6  3             12  RA3  BROWN_BULB
;              VDD  4             11  VSS  
;          K1  RB5  5             10  RB0  YELLOW_BULB
;          K2  RB4  6             9   RB1  BUZ  
;       RESET  RB3  7             8   RB2  POWER_CUT  
;-----------------------------------------------------------
INDF            EQU    00H
TMR0            EQU    01H
PCL             EQU    02H
STATUS          EQU    03H
FSR             EQU    04H
RA              EQU    05H
;-----------------------------------------------------------
LOUDOUT            EQU    0
WHITE_BULB        EQU    1
BLUE_BULB        EQU    2
BROWN_BULB        EQU    3
;-----------------------------------------------------------
RB              EQU    06H
;-----------------------------------------------------------
YELLOW_BULB            EQU    0
BUZ                EQU    1
POWER_CUT        EQU    2
K2                EQU    4
K1                EQU    5
READ                EQU    6
SIGNAL_IN        EQU    7
;-----------------------------------------------------------
IRQM            EQU    09H
;-----------------------------------------------------------
TM0M            EQU    0
PBM             EQU    1
INTM            EQU    7
;-----------------------------------------------------------
IRQF            EQU    0AH
;-----------------------------------------------------------
TM0F            EQU    0
PBF             EQU    1
;-----------------------------------------------------------
PA_PDM          EQU    0BH
PB_PUP          EQU    0CH
PB_PDM          EQU    0DH
PB_POD          EQU    0EH
WAKEUP          EQU    0FH
;-----------------------------------------------------------
A               EQU    0
M               EQU    1  
;---STATUS REG----------------------------------------------
C               EQU    0
DC              EQU    1
Z               EQU    2
PD              EQU    3
TO              EQU    4
GP0             EQU    5
GP1             EQU    6
GP2             EQU    7
;---OPTION REG----------------------------------------------
PS0             EQU    0
PS1             EQU    1
PS2             EQU    2
PSA             EQU    3
T0SE            EQU    4
T0CS            EQU    5
INTEDG          EQU    6
;---PA_PDM REG----------------------------------------------
DB0                    EQU    0
DB1                    EQU    1
DB2                    EQU    2
EXTEN                  EQU    6
RTCEN                  EQU    7
;---PB_POD REG----------------------------------------------
OB0                    EQU    0
OB1                    EQU    1
OB2                    EQU    2
OB4                    EQU    4
OB5                    EQU    5
OB6                    EQU    6
OB7                    EQU    7
;---WAKEUP REG----------------------------------------------
EN0                    EQU    0
EN1                    EQU    1
EN2                    EQU    2
EN4                    EQU    4
EN5                    EQU    5
EN6                    EQU    6
EN7                    EQU    7
;-----------------------------------------------------------
;CONSUMER REGISTER
;-----------------------------------------------------------
MAXDATA              EQU    .250     ; 高低电平宽度最大值
;-----------------------------------------------------------
CODE_TOTAL         EQU          20H
LCODE           EQU            21H            ; 记录一帧码的低8位数据
MCODE           EQU            22H            ; 记录一帧码的中8位数据
HCODE           EQU            23H            ; 记录一帧码的高8位数据                                                            
;-----------------------------------------------------------
LBIT            EQU            25H     ; 记录'0'和'1'码的低电平宽度
HBIT            EQU           26H     ; 记录'0'和'1'码的高电平宽度

LCODE_EE         EQU           27H     ; 记录EEPROM低8位数据
MCODE_EE         EQU           28H     ; 记录EEPROM中8位数据
HCODE_EE         EQU           29H     ; 记录EEPROM高4位数据

MODEREG          EQU           2AH     ; 按键定时器
SHIFT            EQU           2BH

KEYREG           EQU           2CH
CNT_LW           EQU           2DH     ; 定时寄存器
CNT_HI           EQU           2EH
;-----------------------------------------------------------
FRAME            EQU           2FH     ;
;-----------------------------------------------------------
CNT                EQU            30H
CNT2                EQU            31H
DEL1                EQU        32H
CNT_32MS        EQU        33H
CNT_4S                EQU        34H
CNT_1M                EQU        35H

W_REG                EQU        36H
S_REG                EQU        37H
R_BUZ                EQU        38H
;-----------------------------------------------------------
LREG                EQU        3DH        ; 手动开关瞬间按灯闪烁顺序
                                ; LREG值为"1":白灯亮
                                ; LREG值为"2":白灯+蓝灯亮
                                ; LREG值为"3":白灯+蓝灯+棕灯亮
                                ; LREG值为"4":白灯+蓝灯+棕灯+黄灯亮
;-----------------------------------------------------------
FREG_1            EQU            3EH
UP_FLAG                EQU        7        ; FREG_1.7 上电标志位。
DELAY_FLAG         EQU          6        ; FREG_1.6 按键延时1分钟标志
DELAY200MS_FLAG EQU          5          ; FREG_1.5 延时10秒标志位。  
REMOTE_FLAG          EQU           4          ; FREG_1.4 遥控按键成功标志位。
OUT4_FLAG        EQU        3          ; FREG_1.3 4路输出状态标志位。
OUT3_FLAG        EQU            2          ; FREG_1.2 3路输出状态标志位。
OUT2_FLAG           EQU            1          ; FREG_1.1 2路输出状态标志位。
OUT1_FLAG           EQU            0          ; FREG_1.0 1路输出状态标志位。
;-----------------------------------------------------------
FREG_2                EQU        3FH
R_K1                EQU        0        ;'0'->延时1路输出不闪动,'1'->延时1路输出闪动
R_K2                EQU        1        ;'0'->四路遥控输出,'1'->三路输出
R_LOADOUT        EQU        2        ;'0'->无负载输出,'1'->有负载输出
R_80M                EQU        3        ;80分钟定时器,'0'->
R_AGAINST        EQU        4        ;'0'->防盗功能未开启,'1'->防盗功能已开启
R_AGAINST_L1        EQU        5        ;'0'->L1灯闪两次,'1'->L1灯闪一次
OUT_ONOFF        EQU        6        ;ON/OFF松键标志
OUT_DLEY        EQU        7        ;DLEAY松键标志
;=======================================================
;=======================================================
        ORG     3FFH
        LGOTO   0X00
        ORG        0X00
        LGOTO        BOOT
        ORG     3FEH
        LGOTO   INTERRUPT_TMR0
;=======================================================
;2262,8位地址码
;=======================================================
        ORG        001H
LOW_ADDRESS:
        RETLA        0X30
HIGH_ADDRESS:
        RETLA        0XEF
;========================================================
;中断子程序
;========================================================
        ORG        004H
INTERRUPT_TMR0:
        MOVAM        W_REG
        SWAP        STATUS,A
        MOVAM        S_REG

INT_TMR0_START:
        BTSC        IRQF,TM0F
        LGOTO        INT_TMR0_DEAL

INT_TMR0_END:
        BC        IRQF,TM0F
        SWAP        S_REG,A
        MOVAM        STATUS
        SWAP        W_REG,M
        RETI
       
INT_TMR0_DEAL:
        MOVLA        .250
        MOVAM        TMR0
       
        INC        CNT_32MS,M
        BTSC        FREG_1,REMOTE_FLAG
        INC        MODEREG,M        ;按键松键时间寄存器

;        BTSC        FREG_1,DELAY200MS_FLAG
;        INC        R_BUZ,M
       
        MOVLA        .125
        SUB        CNT_32MS,A
        BTSS        STATUS,Z
        LGOTO        INT_TMR0_END

        CLR        CNT_32MS
        INC        CNT_4S,M
;        MOVLA   .1
        MOVLA        .15
        SUB        CNT_4S,A
        BTSS        STATUS,Z
        LGOTO        INT_TMR0_END

        CLR        CNT_4S
        INC        CNT_1M,M
        MOVLA        .100                ;80分钟定时器
        SUB        CNT_1M,A
        BTSS        STATUS,Z
        LGOTO        INT_TMR0_END

        CLR        CNT_32MS
        CLR        CNT_4S
        CLR        CNT_1M
        LGOTO        INT_TMR0_END
;=======================================================       
;延时子程序
;=======================================================
DELAY:
       MOVLA    0XFF
       MOVAM    DEL1
LOOP_DELAY:
       CLRWDT
       LGOTO        $+1
       LGOTO        $+1
       LGOTO        $+1
       LGOTO        $+1
       LGOTO        $+1
       DECSZ    DEL1,M
       LGOTO    LOOP_DELAY
       RETLA    0X00      
;----------------------------------
DELAY1:
        LGOTO        $+1                ;2
        LGOTO        $+1             ;2
DELAY2: NOP                     ;1
DELAY3: NOP                     ;1
DELAY4: NOP                     ;1
DELAY5: NOP                     ;1
DELAY6: NOP                     ;1
DEALY7: LGOTO        $+1             ;2
DELAY8: NOP                     ;1
DELAY9: NOP                     ;1
DEALYA: NOP                     ;1
DELAYB: NOP                     ;1
        RETLA   0X00
;=======================================================
;重新计时子程序
;=======================================================
RESTART_TIME:
        MOVLA        .250
        MOVAM        TMR0
        CLR        CNT_32MS
        CLR        CNT_4S
        CLR        CNT_1M
        RETLA        0X00
;=======================================================
;L1灯即:WHITE_BULB,闪烁一次子程序
;=======================================================
WHITE_BULB_FLISH:
        MOVLA        0X02                                ;按键取反让其闪烁
        XOR        RA,M

        MOVLA        .168
        MOVAM        SHIFT

        MOVLA        .255
        MOVAM        CNT
       
        NOP
        NOP
        NOP
        NOP
       
        DECSZ        CNT,M
        LGOTO        $-3
       
        DECSZ        SHIFT,M
        LGOTO        $-7

        RETLA        0X00
;=======================================================
;按键延时1与延时80分钟定时关闭子程序
;=======================================================
TST_KEYDELAY:       
        MOVLA        .3                        ;去遥控器按键抖动
        SUB        MODEREG,A                ;松开键
        BTSS        STATUS,C
        LGOTO        TST_KEYDELAY_END
       
        MOVLA        0X07
        BTSS        FREG_2,R_K2                ;判断是三路或者是四路遥控
        MOVLA        0X0F
        AND        FREG_1,A
        BTSC        STATUS,Z
        LGOTO        OPEN_LOAD
        BC        RA,LOUDOUT
        LGOTO        LOAD_JUDGE_END
       
OPEN_LOAD:
        BS        RA,LOUDOUT                ;如果没有灯亮,打开负载
       
LOAD_JUDGE_END:       
;        BTSS        FREG_1,DELAY200MS_FLAG
;        LGOTO        BUZ100MS_END
;        MOVLA        .7
;        SUB        R_BUZ,A
;        BTSS        STATUS,C
;        LGOTO        OPEN_BUZPRO
;        LGOTO        OFF_BUZPRO
       
;OPEN_BUZPRO:
;        BS        RB,BUZ
;        LGOTO        BUZ100MS_END
;OFF_BUZPRO:
;        BC        RB,BUZ
;        CLR        R_BUZ
;        BC        FREG_1,DELAY200MS_FLAG
       
;BUZ100MS_END:
        BTSS        FREG_1,REMOTE_FLAG        ;遥控成功标志检测,
        LGOTO        DLEAY_START
               
;        BTSS        FREG_1,DELAY_FLAG
;        LGOTO        STATE_BEGIN
;
;        BTSS        FREG_2,R_K1                ;检测延时L1灯,是否闪烁
;        LGOTO        STATE_BEGIN                ;FREG_2.R_K1=0不闪烁
;       
;        BTSC        FREG_2,R_AGAINST
;        LGOTO        STATE_BEGIN                ;当防盗功能开启后灯不用再闪烁
;
;        BTSC        FREG_1,DELAY200MS_FLAG
;        LGOTO        STATE_BEGIN
;       
;        LCALL        WHITE_BULB_FLISH
;        MOVLA        0X02                        ;按键取反让其闪烁停止
;        XOR        RA,M

STATE_BEGIN:
        LCALL        RESTART_TIME
        BC        FREG_1,REMOTE_FLAG        ;设置按键松开标志
               

DLEAY_START:
        BTSC        FREG_1,DELAY_FLAG        ;延时按键标志=0
        LGOTO        DELAY_1M_PRO
        BTSS        FREG_2,R_AGAINST        ;检测防盗是否开启
            LGOTO        TST_KEYDELAY_END        ;防盗没有开启,直接返回
        LGOTO        AGAINST_80M_PRO                ;进入防盗功能子程序
       
DELAY_1M_PRO:
        MOV        CNT_1M,A
        BTSC        STATUS,Z
        LGOTO        TST_KEYDELAY_END        ;CNT_1M=0,未到1分钟返回

        MOVLA        0X1
        MOVAM        RA
        CLR        RB
        MOVLA        0XB0
        AND        FREG_1,M                ;清除四盏灯的点亮标志,和延时按键标志  
        LCALL        RESTART_TIME
        LGOTO        TST_KEYDELAY_END
       
AGAINST_80M_PRO:       
            BTSC        FREG_2,R_80M                ;0->应进入关闭的80分钟,1->应输出全部负载4分钟
            LGOTO        AGAINST_L1_SHINE4M

        MOVLA        .80                        ;80分钟定时
;       MOVLA   .4
        SUB        CNT_1M,A       
        BTSS        STATUS,Z
        LGOTO        TST_KEYDELAY_END
       
          BS        FREG_2,R_80M                ;80分钟,将R_80标志置1,
          MOVLA        0X0E
        MOVAM        RA                        ;点亮L1/L2/L3
        MOVLA   0X0F
        IOR     FREG_1,A
        MOVAM   FREG_1
        LGOTO        AGAINST_L1_SHINE_CHANGE
         
AGAINST_L1_SHINE4M:
        MOVLA        .4
;        MOVLA   .1
        SUB        CNT_1M,A                ;4分钟定时
        BTSS        STATUS,Z
        LGOTO        TST_KEYDELAY_END
       
        BC        FREG_2,R_80M
        MOVLA        0X00
        MOVAM        RA
        MOVLA        0XF8
        AND        FREG_1,A                ;清除灯的标志
        MOVAM        FREG_1
       
AGAINST_L1_SHINE_CHANGE:
        BC        FREG_1,REMOTE_FLAG
        LCALL        RESTART_TIME
        LGOTO        TST_KEYDELAY_END

;=======================================================
;掉电子程序
;=======================================================
POWER_CUT_PRO:
        MOVLA        00H                ;关闭中断
        MOVAM        IRQM

        MOVLA        0X00
        MOVAM        RA                        ;熄灭白/蓝/棕三盏灯
        MOVAM        RB                        ;熄灭黄灯
       
        MOVLA        .8
        MOVAM        CNT
        LCALL        DELAY
        LCALL        DELAY
       
        DECSZ        CNT,M
        LGOTO        $-3
       
               BTSC    RB,POWER_CUT
        LGOTO        HAND_SWITCH_PRO_END
       
POWER_CUT_PRO_LOOP:
        BTSS        RB,POWER_CUT
        LGOTO        POWER_CUT_PRO_LOOP
       
        BTSS        FREG_1,UP_FLAG                ;检测掉电标志,
        LGOTO        POWER_CUT_PRO_END        ;"0"表示未掉电,"1"表示掉电
       
               INC        LREG,M                        ;手动开关的4个状态
               MOVLA        .5                        ;四路遥控
               BTSC        FREG_2,R_K2                ;判断是三路和四路遥控
               MOVLA        .4                        ;三路遥控
               SUB        LREG,A
               BTSS        STATUS,C
               LGOTO        HAND_SWITCH_PRO
               MOVLA        .1
               MOVAM        LREG
               LGOTO        HAND_SWITCH_PRO
              
POWER_CUT_PRO_END
        BS        FREG_1,UP_FLAG                ;将掉电标志设为"1"
;        MOVLA        0X00
;        MOVAM        RA                        ;熄灭白/蓝/棕三盏灯
;        MOVAM        RB                        ;熄灭黄灯
        LGOTO        POWER_CUT_PRO_LOOP   
;=======================================================
;掉电上电后灯状态
;=======================================================
HAND_SWITCH_PRO:
        BC        FREG_1,UP_FLAG                ;将掉电标志值为"0"
        BC        FREG_1,DELAY_FLAG        ;清除按键延时标志
        BC        FREG_2,R_AGAINST
       
        MOVLA        .1
        MOVAM        CNT
        LCALL        DELAY
        LCALL        DELAY
       
        DECSZ        CNT,M
        LGOTO        $-3
       
        MOVLA        .1
        SUB        LREG,A
        BTSC        STATUS,Z
        LGOTO        SWITCH_1_PRO

        MOVLA        .2
        SUB        LREG,A
        BTSC        STATUS,Z
        LGOTO        SWITCH_2_PRO

        MOVLA        .3
        SUB        LREG,A
        BTSC        STATUS,Z
        LGOTO        SWITCH_3_PRO

;        MOVLA        0X0E                        ;点亮白/蓝/棕三盏灯
;        MOVAM        RA
;        MOVLA        0X01                        ;点亮黄灯
;        MOVAM   RB
        BS        RA,WHITE_BULB
        BS        RA,BLUE_BULB
        BS        RA,BROWN_BULB
        BS        RB,YELLOW_BULB
       
        MOVLA        0X0F
        IOR        FREG_1,A
        MOVAM        FREG_1
        LGOTO        HAND_SWITCH_PRO_END
       
SWITCH_1_PRO:
;        MOVLA        0X00
;        MOVAM        RB
;        MOVLA        0X02
;        MOVAM        RA                        ;点亮白灯
        BS        RA,WHITE_BULB                ;点亮白灯
        MOVLA        0XF1
        AND        FREG_1,A
        MOVAM        FREG_1
        BS        FREG_1,OUT1_FLAG
        LGOTO        HAND_SWITCH_PRO_END
       
SWITCH_2_PRO:
;        MOVLA        0X00
;        MOVAM        RB
;        MOVLA        0X06                        ;点亮白/蓝两盏灯
;        MOVAM        RA
        BS        RA,WHITE_BULB                ;点亮白/蓝两盏灯
        BS        RA,BLUE_BULB
        MOVLA        0XF3
        AND        FREG_1,A
        MOVAM        FREG_1
        MOVLA        0X03
        IOR        FREG_1,A
        MOVAM        FREG_1
        LGOTO        HAND_SWITCH_PRO_END
       
SWITCH_3_PRO:
;        MOVLA        0X00
;        MOVAM        RB
;        MOVLA        0X0E                        ;点亮白/蓝/棕三盏灯
;        MOVAM        RA
        BS        RA,WHITE_BULB
        BS        RA,BLUE_BULB
        BS        RA,BROWN_BULB
        BC        FREG_1,OUT4_FLAG
        MOVLA        0X07
        IOR        FREG_1,A
        MOVAM        FREG_1
        LGOTO        HAND_SWITCH_PRO_END
       
HAND_SWITCH_PRO_END:
        BTSC        FREG_1,OUT1_FLAG
        BS        RA,WHITE_BULB
        BTSC        FREG_1,OUT2_FLAG
        BS        RA,BLUE_BULB
        BTSC        FREG_1,OUT3_FLAG
        BS        RA,BROWN_BULB
        BTSC        FREG_1,OUT4_FLAG
        BS        RB,YELLOW_BULB
        LCALL        RESTART_TIME
        MOVLA        81H
        MOVAM        IRQM
        LGOTO        MAIN
;=======================================================
;接收读码器发送的码型
;=======================================================
RX:
        CLR        LBIT
       
REC_LOW_LEVEL:                                ;接收电平信号,并记录其宽度
        BTSC        RB,READ               
        LGOTO        RX_TOTAL
        DECSZ        LBIT,M                        ;所接收到的为,2262,A0低电平宽度
        LGOTO        REC_LOW_LEVEL
       
RX_ERROR:                                ; STATUS.C=1,返回错误信息。
        BS        STATUS,C
        RETLA        0X00
       
;----------------------------------       
RX_TOTAL:
        MOVLA        0X08
        MOVAM         CNT
       
RX_LOOP:       
        CLR        HBIT
       
RX_HIGH_LEVEL:       
        BTSS        RB,READ
        LGOTO        RX_JUDGE
        DECSZ        HBIT,M                        ;记录高电平的宽度
        LGOTO        RX_HIGH_LEVEL
        LGOTO        RX_ERROR
       
RX_JUDGE:       
        MOV        LBIT,A
        SUB        HBIT,A                        ;HBIT>LBIT,则:A=1
        RR        MCODE,M
        RR        LCODE,M
        CLR        HBIT
       
RX_LOW_LEVEL:                                ;低电平持续时间检测
        BTSC        RB,READ
        LGOTO        RX_JUDGE_1                ;高电平,跳转RX_JUDGE_1
        DECSZ        HBIT,M
        LGOTO        RX_LOW_LEVEL
        LGOTO        RX_ERROR                ;低电平时间过长,错误返回。
       
RX_JUDGE_1:       
        MOV        LBIT,A
        SUB        HBIT,A
        RR        MCODE,M
        RR        LCODE,M
        DECSZ        CNT,M
        LGOTO        RX_LOOP
RX_OK:   
        BC        STATUS,C
        RETLA        0X00
       
;=======================================================
;发送码型给外在读码器
;=======================================================
TX:  
               BS      RB,READ
               MOVLA   0X84
               IODIR   RB
               MOVLA   0X07
               MOVAM   CNT
               BC      RB,READ
               LCALL   DELAY9
               DECSZ   CNT,M
               LGOTO   $-2
               BS      RB,READ
               MOVLA   0X10
               MOVAM   CNT
BIT_OUT:
               MOVLA   0X03
               BTSC    LCODE,0
               MOVLA   0X09
               MOVAM   CNT2
               RR      MCODE,M
               RR      LCODE,M

               LCALL   DELAY9
               DECSZ   CNT2,M
               LGOTO   $-2

        CLRWDT
               MOVLA   0X40
               XOR     RB,M
               DECSZ   CNT,M
               LGOTO   BIT_OUT
               LCALL   DELAY1
               RETLA   0X00       
;=======================================================
;程序开始
;=======================================================  
BOOT:
        MOVLA        0X80
        MOVAM        FREG_1                        ;上电时,将上电标志置"1"

        CLR     CNT_32MS
        CLR        CNT_4S
        CLR        CNT_1M
        CLR     LREG

        CLR        RA
        MOVLA        0X00                        ;RA0上电检测/RA1白灯/RA2蓝灯/RA3棕灯
        IODIR        RA
        CLR     RB
        MOVLA        0XF4                        ;RB6读码输入/R7信号输入/R2电源检测
        IODIR        RB

;        MOVLA        0X04                        B2 掉电检测下拉
;        MOVAM        PB_PDM               
;        MOVLA        0X70                        ;RB6 读码上拉
;        MOVAM        PB_PUP

        MOVLA        0X74                        ;RB6 读码上拉
        MOVAM        PB_PUP

        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        LCALL          DELAY
        BTSS           RB,READ
        LGOTO        SEND_CODE_PRO

BOOT_CONTR:

        CLR     RB
        MOVLA        0XF4                        ;RB6读码输入/R7信号输入/R2电源检测
        IODIR        RB

        CLR        FREG_2
       
        MOVLA        0X02                        ;三路
        BTSS        RB,K2                        ;三路遥控或四路遥控选择
        MOVLA        0X00                        ;四路
        MOVAM        FREG_2

        MOVLA        0X01                        ;L1闪烁
        BTSS        RB,K1                        ;延时,L1灯是否闪烁
        MOVLA        0X00                        ;L1不闪烁
        IOR        FREG_2,A
        MOVAM        FREG_2
       
        MOVLA   .250
        MOVAM   TMR0
        MOVLA        0XC6                        ;1:128分频
        SELECT
        MOVLA        81H
        MOVAM        IRQM
        BS        RA,WHITE_BULB
        INC        LREG,M                        ;手动开关的4个状态
        BS        FREG_1,OUT1_FLAG
;=======================================================         
MAIN:       
        LGOTO   TST_KEYDELAY

TST_KEYDELAY_END:
        LCALL   RECEIVE_2262
        BTSS        STATUS,C
        LGOTO        M_COMPARE

        BTSS        RB,POWER_CUT                ;如上电状态断电状态则,
        LGOTO        POWER_CUT_PRO                ;进入断电状态子程序
       
        LGOTO        MAIN      
;=======================================================
;HS2262, 接收,用两个位标识2262中的一个位,因有"F"码存在
;=======================================================
RECEIVE_2262:
        BTSS        RB,SIGNAL_IN
        LGOTO   RECEIVE_2262_ERROR_END
        CLR     CODE_TOTAL
        CLR     HBIT
       
RECEIVE_2262_HIGH:
             INC     HBIT,M
             MOVLA   MAXDATA
             SUB     HBIT,A
             BTSC    STATUS,C
             LGOTO   RECEIVE_2262_ERROR_END           
             BTSC    RB,SIGNAL_IN
             LGOTO   RECEIVE_2262_HIGH  
            
             CLR     LBIT

RECEIVE_2262_JUDGE:
             INC     CODE_TOTAL,M
             MOVLA   .25
             SUB     CODE_TOTAL,A
             BTSC    STATUS,Z
             LGOTO   RECEIVE_2262_END
            
RECEIVE_2262_LOW:
             INC     LBIT,M
             MOVLA   MAXDATA
             SUB     LBIT,A
             BTSC    STATUS,C
             LGOTO   RECEIVE_2262_ERROR_END
             BTSS    RB,SIGNAL_IN
             LGOTO        RECEIVE_2262_LOW

             MOV     LBIT,A
             SUB     HBIT,A
             RR      HCODE,M
             RR      MCODE,M
             RR      LCODE,M
             CLR     HBIT
             LGOTO   RECEIVE_2262_HIGH

RECEIVE_2262_ERROR_END:
             BS      STATUS,C                ;通过STATUS.C位置,来判断是否有遥控,或解码是否真确
             RETLA   0X00                        ;"1",表示不正确
RECEIVE_2262_END:     
             BC      STATUS,C                ;STATUS.C=0,解码成功
             RETLA   0X00
;=======================================================
;接收到的2262码型进行比较
;=======================================================
M_COMPARE:
        MOV     HCODE,A
        MOVAM   KEYREG

        LCALL   LOW_ADDRESS
        XOR     LCODE,A
        BTSS    STATUS,Z
        LGOTO   MAIN

        LCALL   HIGH_ADDRESS
        XOR     MCODE,A
        BTSS    STATUS,Z
        LGOTO   MAIN

REMOTE_KEY_JUDGE:
        CLR        MODEREG
;        CLR        R_BUZ
        BTSC    FREG_1,REMOTE_FLAG
        LGOTO   MAIN
        BS        FREG_1,REMOTE_FLAG
;        BS        FREG_1,DELAY200MS_FLAG

        MOVLA   0XC0                        ;按键"A",键值"1",两位标识即="0XC0"
        XOR     KEYREG,A
        BTSC    STATUS,Z
        LGOTO   KEY1_PRO

        MOVLA   0X03                        ;按键"B",键值"8",两位标识即="0X03"
        XOR     KEYREG,A
        BTSC    STATUS,Z
        LGOTO   KEY2_PRO

        MOVLA   0X0C                        ;按键"C",键值"4",两位标识即="0X0C"
        XOR     KEYREG,A
        BTSC    STATUS,Z
        LGOTO   KEY3_PRO

        MOVLA   0XCC                        ;按键"D",键值"5",两位标识即="0XCC"
        XOR     KEYREG,A
        BTSC    STATUS,Z
        LGOTO   KEY4_PRO

        MOVLA        0X30                        ;按键"ON/OFF",键值"2",两位标识即="0X30"
        XOR        KEYREG,A
        BTSC        STATUS,Z
        LGOTO        KEY5_ON0FF_PRO

        MOVLA   0X0F                        ;按键"延时"或者"按键(B+C)",键值"5",两位标识即="0X0F"
        XOR     KEYREG,A
        BTSC    STATUS,Z
        LGOTO   KEY6_DELAY_PRO
        LGOTO   MAIN
;=======================================================
;遥控按键, 遥控功能处理
;=======================================================
KEY1_PRO:
;        LCALL        BUZZ_200MS
;        BS        FREG_1,DELAY200MS_FLAG
        BC        FREG_1,DELAY_FLAG        ;清除按键延时标志
        BC        FREG_2,R_AGAINST
        BTSS        FREG_1,OUT1_FLAG
        LGOTO        WHITE_BULB_ON
       
        BC        RA,WHITE_BULB
        BC        FREG_1,OUT1_FLAG
        LGOTO        MAIN
       
WHITE_BULB_ON:
        BS        RA,WHITE_BULB
        BS        FREG_1,OUT1_FLAG
        LGOTO        MAIN
;----------------------------------       
KEY2_PRO:
;        LCALL        BUZZ_200MS
;        BS        FREG_1,DELAY200MS_FLAG
        BC        FREG_1,DELAY_FLAG        ;清除按键延时标志
        BC        FREG_2,R_AGAINST
        BTSS        FREG_1,OUT2_FLAG
        LGOTO        BLUE_BULB_ON

        BC        RA,BLUE_BULB
        BC        FREG_1,OUT2_FLAG
        LGOTO        MAIN
       
BLUE_BULB_ON:
        BS        RA,BLUE_BULB
        BS        FREG_1,OUT2_FLAG
        LGOTO        MAIN
;----------------------------------       
KEY3_PRO:
;        LCALL        BUZZ_200MS
;        BS        FREG_1,DELAY200MS_FLAG
        BC        FREG_1,DELAY_FLAG        ;清除按键延时标志
        BC        FREG_2,R_AGAINST
        BTSS        FREG_1,OUT3_FLAG
        LGOTO        BROWN_BULB_ON

        BC        RA,BROWN_BULB
        BC        FREG_1,OUT3_FLAG
        LGOTO        MAIN
       
BROWN_BULB_ON:
        BS        RA,BROWN_BULB
        BS        FREG_1,OUT3_FLAG
        LGOTO        MAIN
;----------------------------------
KEY4_PRO:
;        LCALL        BUZZ_200MS
        BC        FREG_1,DELAY_FLAG        ;清除按键延时标志
        BTSC        FREG_2,R_K2                ;"三路"或"四路"电路判断
        LGOTO        AGAINST_THEFT_PR0        ;进入"三路电路"防盗键程序
        BC        FREG_2,R_AGAINST
        BTSS        FREG_1,OUT4_FLAG
        LGOTO        YELLOW_BULB_ON

        BC        RB,YELLOW_BULB
        BC        FREG_1,OUT4_FLAG
;        BS        FREG_1,DELAY200MS_FLAG
        LGOTO        MAIN
       
YELLOW_BULB_ON:       
        BS        RB,YELLOW_BULB
        BS        FREG_1,OUT4_FLAG
;        BS        FREG_1,DELAY200MS_FLAG
        LGOTO        MAIN
       
AGAINST_THEFT_PR0:
        BTSC        FREG_2,R_AGAINST
        LGOTO        AGAINST_THEFT_OFF
        LCALL        WHITE_BULB_FLISH
        LCALL        WHITE_BULB_FLISH
        LCALL        WHITE_BULB_FLISH
        MOVLA        0X02                        ;按键取反让其闪烁停止
        XOR        RA,M       
       
        MOVLA        0X07                        ;FREG_1,OUT1_FLAG/2/3/4
        AND        FREG_1,A                ;判断是否有负载输出
        BTSS        STATUS,Z
        BS        FREG_1,DELAY_FLAG        ;表有负载输出,延时1分钟后关闭
        BS        FREG_2,R_AGAINST
        LGOTO        AGAINST_THEFT_PR0_END
       
AGAINST_THEFT_OFF:
        LCALL        WHITE_BULB_FLISH
        MOVLA        0X02                        ;按键取反让其闪烁停止
        XOR        RA,M
        BC        FREG_2,R_AGAINST
        LGOTO        AGAINST_THEFT_PR0_END
       
AGAINST_THEFT_PR0_END:
;        LCALL        RESTART_TIME
        CLR        MODEREG
;        CLR        R_BUZ
;        BS        FREG_1,DELAY200MS_FLAG
        LGOTO        MAIN
;----------------------------------
KEY5_ON0FF_PRO:
;        LCALL        BUZZ_200MS
;        BS        FREG_1,DELAY200MS_FLAG
        BC        FREG_1,DELAY_FLAG        ;清除按键延时标志
        BC        FREG_2,R_AGAINST
        MOVLA        0X0F                        ;FREG_1,OUT1_FLAG/2/3/4
        AND        FREG_1,A
        BTSS        STATUS,Z
        LGOTO        WHOLE_BULB_OFF                ;只要有一盏灯亮,则跳,全熄灭

       
        MOVLA        0X0E                        ;点亮白/蓝/棕三盏灯,关闭负载
        MOVAM        RA
        MOVLA        0X00
        BTSS        FREG_2,R_K2
        MOVLA        0X01                        ;点亮黄灯
        MOVAM        RB
        MOVLA        0X0F
        IOR        FREG_1,M                ;打开四盏灯的点亮标志       
        LGOTO        MAIN
       
WHOLE_BULB_OFF:
        MOVLA        0X01
        MOVAM        RA                        ;熄灭白/蓝/棕三盏灯
        CLR        RB                        ;熄灭黄灯
        MOVLA        0XF0
        AND        FREG_1,M                ;清除四盏灯的点亮标志
        LGOTO        MAIN
;----------------------------------
KEY6_DELAY_PRO:
;        LCALL        BUZZ_200MS
        BC        FREG_2,R_AGAINST
;        BS        FREG_1,DELAY200MS_FLAG
        BS        FREG_1,DELAY_FLAG        ;按键延时标志

        BTSS        FREG_2,R_K1                ;检测延时L1灯,是否闪烁
        LGOTO        STATE_BEGIN                ;FREG_2.R_K1=0不闪烁
       
        LCALL        WHITE_BULB_FLISH
        MOVLA        0X02                        ;按键取反让其闪烁停止
        XOR        RA,M

        CLR        MODEREG
       
        LGOTO        MAIN
;=======================================================
;读码子程序
;=======================================================
SEND_CODE_PRO:
               MOVLA   0XC4                        ;0010,0011,READ脚设置输入
               IODIR   RB
               LGOTO   $+1

               BTSC    RB,READ                        ;检测低电平,高电平跳出
               LGOTO   $-1

               BTSS    RB,READ                        ;检测高电平,低电平跳出
               LGOTO   $-1

               MOVLA   0X84                        ;0010,0001,READ脚设置输输出
               IODIR   RB
               BC      RB,READ                        ;输出电平信号,给读码器件
               MOVLA   0X21                        ;低电平延时33(21H)*3指令周期
               MOVAM   CNT

               DECSZ   CNT,M
               LGOTO   $-1

               MOVLA   0XC4                        ;1000,1100,READ脚设置输入       
               IODIR   RB
              
               MOVLA   0X14                        ;20(14H)*5个指令周期是否接收
               MOVAM   CNT                        ;到读码器发送出的高电平
               BTSS    RB,READ
               LGOTO   READ_CODE_SEND
              
               DECSZ   CNT,M
               LGOTO   $-3
               LGOTO   SEND_CODE_PRO                ;20*5指令周期未能收到高电平,返回重读
              
READ_CODE_SEND:                                       
               BTSS    RB,READ                        ;检测低电平,高电平逃过
               LGOTO   $-1                        ;其高电平为2262,A0

               BTSC    RB,READ                        ;检测高电平,低电平跳过
               LGOTO   $-1                        ;其低电平为2262,A0

               LCALL   RX
               BTSC    STATUS,C
               LGOTO   SEND_CODE_PRO

        BTSS    RB,READ                        ;检测高电平,低电平跳出
               LGOTO   $-1
              
        MOVLA        0X00
               MOVAM        RB
               MOVLA   0X84
        IODIR   RB
       
               MOVLA   0XA3
               XOR     LCODE,C
               BTSS    STATUS,Z
               LGOTO   SEND_CODE_PRO

               LCALL   DELAY1

               LCALL   LOW_ADDRESS
               MOVAM   LCODE
               LCALL   HIGH_ADDRESS
               MOVAM   MCODE
              
               LCALL   TX
        LGOTO   BOOT_CONTR
;=======================================================
END
;=======================================================
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖 顶 踩
回复

使用道具 举报

无效楼层,该帖已经被删除
板凳
amw1688 发表于 2014-2-7 17:25 | 只看该作者
不错,顶呀,用力

]QVV[R[Z}S(QVLRSQK}FLX2.jpg (55.94 KB, 下载次数: 66)

]QVV[R[Z}S(QVLRSQK}FLX2.jpg
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|单片机论坛 |51hei电子论坛2群 联系QQ:125739409;技术交流QQ群219535678

Powered by 单片机教程网

快速回复 返回顶部 返回列表