aihe的笔记 https://bbs.21ic.com/?255601 [收藏] [复制] [RSS]

日志

修改后的程序

已有 846 次阅读2007-5-10 10:23 |系统分类:单片机| PIC

;***********************************************************
;AIHE   于2007年五一假期中断续写成
;4MHz晶振,1微秒每个指令周期
;内部定时器256×16=4.096mS查询
;主要功能定时控制电动阀开关
;起始延时由四个拨动开关设定,全关为5分钟
;以后就是开一分钟,关一小时
;任何时间按下开、或关执行开或关动作
;阀动作时间最大30S,或者执行到位信号控制
;动作时LED闪动,OUT输出,到位时LED常亮,OUT关闭
;***********************************************************
        list        p=16c54
#INCLUDE        P16C5X.INC
;字节定义  
#DEFINE     MS500           08H             ;分秒
#DEFINE     S1              09H             ;秒
#DEFINE     S30             0AH             ;30秒
#DEFINE     M               0BH             ;分
#DEFINE     START_YS        0CH
#DEFINE     FLAG1           0DH             ;
;A口输出位 
#DEFINE     CLOSE_OUT       00H             ;开阀
#DEFINE     OPEN_OUT        01H             ;关阀
#DEFINE     CLOSE_LED       02H             ;开
#DEFINE     OPEN_LED        03H             ;关
;B口输入定义
#DEFINE     S1_1            00H             ;启动
#DEFINE     S1_2            01H             ;延时
#DEFINE     S1_3            02H             ;选择
#DEFINE     S1_4            03H             ;开关
#DEFINE     OPEN            04H             ;开按钮
#DEFINE     CLOSE           05H             ;关按钮
#DEFINE     OPEN_CILCK      06H             ;开到位
#DEFINE     CLOSE_CILCK     07H             ;关到位
;标帜FLAG1位定义
#DEFINE     ST_YS_FG        00H
#DEFINE     OPEN_FG         01H             ;
#DEFINE     VT_FG           02H             ;阀门延时标帜
#DEFINE     BB              03H             ;关标帜
#DEFINE     O_FG            04H             ;开按钮标帜
#DEFINE     C_FG            05H             ;关按钮标帜
#DEFINE     OC_FG           06H             ;开到位标帜
#DEFINE     CC_FG           07H             ;关到位标帜
;      
       
            ORG         00H
               
            BTFSS       STATUS,NOT_PD
            GOTO        WAIT
            BTFSS       STATUS,NOT_TO
            GOTO        DOG


START       MOVLW       08H                 ;w=08h
            MOVWF       FSR                 ;FSR=08H
XH1         CLRF        INDF                    ;08单元处被清零
            INCF        FSR,F               ;FSR=FSR+1,指向下一单元
            MOVLW       1FH                 ;准备检查FSR是否为1FH
            XORWF       FSR,W               ;FSR和W异或,FSR保持不变
            BTFSS       STATUS,Z            ;检测Z标志是否为1,是则循环结束
            GOTO        XH1                 ;继续循环


SET_ST      MOVF        PORTB,0             ;读开机延时状态
            MOVWF       START_YS            ;
            MOVLW       B'00001111'
            ANDWF       START_YS,1          ;
            INCF        START_YS,1          ;开机延时加1
            MOVF        START_YS,0          ;延时分钟数n×5
            ADDWF       START_YS,1
            ADDWF       START_YS,1
            ADDWF       START_YS,1
            ADDWF       START_YS,1
                                   
DOG         MOVLW       00H                 ;PA为输出
            TRIS        PORTA               ;
            CLRF        PORTA               ;PA为低电平
            MOVLW       0FFH                ;PB为输入
            TRIS        PORTB


SET_RTCC    MOVLW       10H                 ;0.5秒
            MOVWF       MS500
            MOVLW       02H                 ;1秒
            MOVWF       S1
            MOVLW       1EH                 ;30秒
            MOVWF       S30
            MOVLW       02H                 ;1分钟
            MOVWF       M
            CLRF        TMR0                ;
            MOVLW       B'00001011'         ;定义1/16,RTCC为内部计数方式
            OPTION                          ;
            BCF         FLAG1,OPEN_FG
            BSF         PORTA,CLOSE_OUT
            BSF         FLAG1,VT_FG


WAIT        MOVLW       05H                 ;31.25mS处理一次外部事务
            SUBWF       TMR0,0
            BTFSC       STATUS,C       
            GOTO        WAIT               
            CLRWDT                          ;清看门狗
            BSF         STATUS,C
               
B1          BTFSS       PORTB,OPEN          ;开按键检测
            GOTO        B2                  ;
            BTFSC       FLAG1,O_FG          ;延时确认
            GOTO        B3                  ;
            BSF         FLAG1,O_FG          ;


B2          BTFSS       PORTB,CLOSE         ;关按键检测
            GOTO        A1                  ;
            BTFSC       FLAG1,C_FG          ;延时确认
            GOTO        B4                  ;关
            BSF         FLAG1,C_FG          ;
            GOTO        A1                  ;


B3          BTFSS       FLAG1,C_FG          ;同时按下停止
            GOTO        B5                  ;
            BCF         PORTA,OPEN_OUT      ;
            BCF         PORTA,OPEN_LED
            BCF         PORTA,CLOSE_OUT     ;
            BCF         PORTA,CLOSE_LED
            GOTO        A1                  ;


B4          BCF         FLAG1,OPEN_FG       ;关
            BCF         PORTA,OPEN_OUT      ;
            BCF         PORTA,OPEN_LED
            BSF         PORTA,CLOSE_OUT
            GOTO        A3                 


B5          BSF         FLAG1,OPEN_FG       ;开
            BCF         PORTA,CLOSE_OUT     ;
            BCF         PORTA,CLOSE_LED
            BSF         PORTA,OPEN_OUT
            GOTO        A2
               
A1          BTFSS       FLAG1,OPEN_FG       ;
            GOTO        A2             
            GOTO        A3
           
A2          DECFSZ      MS500,1
            GOTO        WAIT                   
            MOVLW       10H                 ;0.5秒
            MOVWF       MS500
           
            BTFSS       FLAG1,VT_FG         ;
            GOTO        C3                  ;
            BTFSS       PORTB,CLOSE_CILCK   ;
            GOTO        C1                  ;
            BTFSC       FLAG1,CC_FG         ;延时确认
            GOTO        C1                  ;
            BCF         FLAG1,VT_FG         ;关到位
            BCF         PORTA,CLOSE_OUT
            BSF         PORTA,CLOSE_LED
            GOTO        C3


C1          BTFSS       PORTA,CLOSE_LED     ;关闭灯 闪烁
            GOTO        C2
            BCF         PORTA,CLOSE_LED
            GOTO        C3
C2          BSF         PORTA,CLOSE_LED


C3          DECFSZ      S1,1
            GOTO        WAIT                   
            MOVLW       02H                 ;1秒
            MOVWF       S1
            DECFSZ      S30,1
            GOTO        WAIT                   
            MOVLW       1EH                 ;30秒
            MOVWF       S30


            BTFSS       FLAG1,VT_FG         ;
            GOTO        $+4
            BSF         PORTA,CLOSE_LED
            BCF         PORTA,CLOSE_OUT
            BCF         FLAG1,VT_FG         ;


            DECFSZ      M,1
            GOTO        WAIT
            MOVLW       02H                 ;1分钟
            MOVWF       M


            DECFSZ      START_YS,1          ;5分钟×n
            GOTO        WAIT
            MOVLW       3CH                 ;1小时
            MOVWF       START_YS
           
            BCF         PORTA,CLOSE_LED
            BSF         PORTA,OPEN_OUT
            BSF         FLAG1,OPEN_FG
            BSF         FLAG1,VT_FG         ;
            GOTO        WAIT
               
A3          DECFSZ      MS500,1
            GOTO        WAIT                   
            MOVLW       10H                 ;0.5秒
            MOVWF       MS500
           
            BTFSS       FLAG1,VT_FG         ;
            GOTO        D3                  ;
            BTFSS       PORTB,OPEN_CILCK    ;
            GOTO        D1                  ;
            BTFSC       FLAG1,OC_FG         ;延时确认
            GOTO        D1                  ;
            BCF         FLAG1,VT_FG         ;开关到位
            BCF         PORTA,OPEN_OUT
            BSF         PORTA,OPEN_LED

            GOTO        D3


D1          BTFSS       PORTA,OPEN_LED      ;开启灯 闪烁
            GOTO        D2
            BCF         PORTA,OPEN_LED
            GOTO        D3
D2          BSF         PORTA,OPEN_LED


D3          DECFSZ      S1,1
            GOTO        WAIT                   
            MOVLW       02H                 ;1秒
            MOVWF       S1
            DECFSZ      S30,1
            GOTO        WAIT                   
            MOVLW       1EH                 ;30秒
            MOVWF       S30


            BTFSS       FLAG1,VT_FG         ;
            GOTO        $+4
            BSF         PORTA,OPEN_LED
            BCF         PORTA,OPEN_OUT
            BCF         FLAG1,VT_FG         ;


            DECFSZ      M,1
            GOTO        WAIT
            MOVLW       02H                 ;1分钟
            MOVWF       M


            BCF         PORTA,OPEN_LED
            BSF         PORTA,CLOSE_OUT
            BCF         FLAG1,OPEN_FG              
            BSF         FLAG1,VT_FG         ;
            GOTO        WAIT
               
            END


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)