打印

程序跑乱了

[复制链接]
1785|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
piao520|  楼主 | 2008-12-16 09:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
描                      述:                                                                       *
;*       HHD-PCZ-01 泡茶桌待用与使用功能切换控制.                      *
;*       P1.0(门电机开的驱动信号);  P1.1(门电机关的驱动信号)                 *
;*       P1.2(升降电机升的驱动信号);P1.3(升降电机降的驱动信号)               *
;*        P1.4(泡茶桌启动按键K1);    P1.5(关闭按键K2)                  *
;*        P1.6(泡茶桌停止按键K3);    P1.7(备用按键)                           *
;*        P3.0(备用);                P3.1(蜂鸣器驱动)                         *
;*          P3.2(门合到位感应器LS1);   P3.3(门开到位/升起启动感应器LS2)         *
;*          P3.4(升到位感应器LS3);     P3.5(降到位/门合启动感应器LS4)           *
;*          P3.6无引脚;                P3.7(备用)                               *
;*          K1键按下P1.4,启动使用。K2键按下P1.5,停止使用转待用。          *
;*          K3键按下P1.6, 暂停/反运行排除使用中遇到的问题                           *
;********************************************************************
;----------------------------------------------------------
                QY     BIT      22H.1   ;启动标示位
                TZ     BIT      22H.2   ;停用标示位
                JS     BIT      22H.4   ;夹手标示位
                ORG    0000H
                LJMP   MAIN             ;主程序入口地址
                ORG    0100H
;-----------------------------------------------------------
;               主程序软件复位入口地址
;-----------------------------------------------------------
MAIN:           ACALL  BZ              ;上电嘀一声
                MOV    P1,     #0FFH   ;I/O口软件复位
                MOV    P3,     #0FFH
                MOV    A,      #00H    ;A置0
                CLR    QY              ;标示位清零
                CLR    TZ
                CLR    JS
                MOV    SP,     #60H
;------------------------------------------------------------
;               判断工作状态
;------------------------------------------------------------
                JNB     P3.2,  QY_1    ;上电时P3.3等"0"转QY_1(LS1)
                SETB    TZ             ;置停止使用标示位
                CLR     QY             ;清启用标示位
                CLR     JS             ;清夹手标示位
                AJMP    START          ;转起用程序
QY_1:           SETB    QY             ;置启用标示位
                CLR     TZ             ;清停止标示位
                CLR     JS             ;清夹手标示位
;----------------------------------------------------------------
;               标示位判断
;----------------------------------------------------------------
START:          JNB     P1.6,  ZT_1
                AJMP    QY_2
ZT_1:           ACALL   DELAY10MS
                JB      P1.6,  QY_2
                ACALL   BZ
                ACALL   ZT_STOP
QY_2:           JNB     QY,    TZ_1    ;QY为"0"转TZ_1
                ACALL   OPEN_K1        ;QY为"1"启用泡茶桌
TZ_1:           JNB     TZ,    JS_1    ;TZ为"0"转JS_1
                ACALL   DON_K1         ;TZ为"1"停止使用泡茶桌
JS_1:           JNB     JS,    START_RET
                ACALL   BJ             ;调用夹手报警程
                AJMP    MAIN
START_RET:      AJMP    START
;------------------------------------------------------------
;          启用主程程序
;-------------------------------------------------------------
OPEN_K1:        JB      P1.4,   UP_LS1 ;P1.4等"0"说明有键按下转去抖处理
                ACALL   DELAY10MS
                JNB     P1.4,   K1_2   ;等"0"有键按下
                AJMP    OPEN_K1        ;没键按下返回
K1_2:           JNB     P1.4,   K1_2   ;等待键置放
                ACALL   BZ
                ACALL   OPEN           ;调用门开子程序
UP_LS1:         JB      P3.3,   UP_LS_STOP
                ACALL   UP             ;调用升起子程序
UP_LS_STOP:     JB      P3.4,   OPEN_K1_RET
                ACALL   OPEN_STOP      ;调用启用停止子程序
                AJMP    MAIN
OPEN_K1_RET:    RET
;------------------------------------------------------------------
;          停止主程序
;------------------------------------------------------------------
DON_K1:         JB      TZ,      DON_TZ
DON_TZ:         SETB    TZ
                CLR     QY
                CLR     JS
                JB      P1.5,   CLOSE_LS ;P1.5等"0"说明停止键按下转去抖处理
                ACALL   DELAY10MS
                JNB     P1.5,    K2_1    ;等"0"有键按下
                AJMP    DON_K1           ;没键按下返回
K2_1:           JNB     P1.5,    K2_1    ;等待键置放
                ACALL   BZ               ;调用蜂鸣器嘀一声
                ACALL   DON              ;调用降子程序
                JB      TZ,      CLOSE_LS
                SETB    TZ
                CLR     QY
                CLR     JS
CLOSE_LS:       JB      P3.5,    CLOSE_LS_STOP
                ACALL   CLOSE            ;调用门关子程序
CLOSE_LS_STOP:  JB      P3.2,    JS_2   ;门合到位感应器LS
                ACALL   CLOSE_STOP       ;调用泡茶桌停用停止程序
                AJMP    MAIN             ;返回开始程序
JS_2:           JB      P1.1,   CLOSE_K1_RET
                JB      P3.7,   CLOSE_K1_RET
                ACALL   BJ1              ;调用夹手处理子程序
CLOSE_K1_RET:   RET

;--------------------------------------------------------------------
;            启用子程序 OPEN
;---------------------------------------------------------------------
OPEN:           CLR     P1.0           ;驱动门电机OPEN
                SETB    P1.1           ;禁止门电机CLOSE驱动
                SETB    P1.2           ;禁止升降电机UP驱动
                SETB    P1.3           ;禁止升降电机DON驱动
                RET
;----------------------------------------------------------------------
;        启用子程序 UP
;----------------------------------------------------------------------
UP:             SETB    P1.0           ;关门电机OPEN驱动
                CLR     P1.2           ;驱动升降电机UP
                SETB    P1.1
                SETB    P1.3
                RET
;-------------------------------------------------------------------------
;        OPEN_STOP程序
;-------------------------------------------------------------------------
OPEN_STOP:      SETB   P1.0
                SETB   P1.1
                SETB   P1.2
                SETB   P1.3
                RET
;----------------------------------------------------------------------
;       停止程序DON
;----------------------------------------------------------------------
DON:            CLR     P1.3           ;驱动升降电机DON
                SETB    P1.1           ;禁止门电机CLOSE驱动
                SETB    P1.2           ;禁止升降电机UP驱动
                SETB    P1.0           ;禁止门电机OPEN驱动
                RET
;-------------------------------------------------------------------------
;       停止程序CLOSE
;-------------------------------------------------------------------------
CLOSE:          SETB    P1.3           ;关升降电机DON驱动
                CLR     P1.1
                SETB    P1.2
                SETB    P1.0
                RET
;---------------------------------------------------------------------------
;    CLOSE_STOP程序
;---------------------------------------------------------------------------
CLOSE_STOP:     SETB    P1.0
                SETB    P1.1
                SETB    P1.2
                SETB    P1.3
                RET                    ;子程序返回
;-----------------------------------------------------------------------------
;               夹到手反回程序BJ程序
;-----------------------------------------------------------------------------
BJ1:           SETB    P1.0
               SETB    P1.1
               SETB    P1.2
               SETB    P1.3
               ACALL   DELAY500MS
               CLR     QY
               CLR     TZ
               SETB    JS
               CLR     P1.0
BJ_1:          JB      P3.3,       BJ_1
               SETB    P1.0
               RET
;------------------------------------------------------------------------------
;              ZT_STOP
;------------------------------------------------------------------------------
ZT_STOP:      SETB    P1.0
              SETB    P1.1
              SETB    P1.2
              SETB    P1.3
               RET

;------------------------------------------------------------------------------
;            延时10MS程序
;------------------------------------------------------------------------------
DELAY10MS:   MOV       R7,         #50     ;延时的时间一般为5-20ms
D1:          MOV       R6,         #100
D2:          DJNZ      R6,         D2
             DJNZ      R7,         D1
             RET
;-------------------------------------------------------------------------------
;           延时500MS程序
;-------------------------------------------------------------------------------
DELAY500MS:  MOV       R4,         #00H
             MOV       R4,         #50D
D50:         ACALL     DELAY10MS
             DJNZ      R4,         D50
             RET
;--------------------------------------------------------------------------------
;           蜂鸣器嘀一声程序
;--------------------------------------------------------------------------------
BZ:         MOV        R5,        #00H
            MOV        R5,        #5D
            CLR        P3.1
BZ_1:       ACALL DELAY10MS
            DJNZ       R5,        BZ_1
            SETB       P3.1
            RET
;--------------------------------------------------------------------------------
;         蜂鸣器故障报警
;--------------------------------------------------------------------------------
BJ:       CPL         P3.1
          JNB         P1.5,        BZ2
          LCALL       DELAY
          SJMP        BJ
BZ2:      JB          TZ,           BJ_RET
          SETB        TZ
BJ_RET:   RET
DELAY:    MOV         60H,         #10H
DELAY0:   MOV         61H,         #7FH
DELAY1:   MOV         62H,         #7FH
          JNB         P1.5,        BZ2
          DJNZ        62H,$
          JNB         P1.5,        BZ2
          DJNZ        61H,         DELAY1
          JNB         P1.5,        BZ2
          JNB         P1.5,        BZ2
          RET
          END
各位大哥你们好!小弟用的是AT89C2051单片机,
如果没有按下K3(就是P1.6)整机工作就是好好的
当按下K3暂停键调用ACALL   ZT_STOP回来后程序就不听话了
调用完子程序返回后,还没有按下K1启动键或K2停止(P1.4,P1.5)就又开始动作了??
小弟真的不知道是什么原因??
因为小弟是初学者,请高手们指导一下

相关帖子

沙发
耕在此行| | 2008-12-16 21:03 | 只看该作者

楼主 帮你改了一点点 没改完.

                B_start     BIT      22H.1   ;启动标示位
                B_stop      BIT      22H.2   ;停用标示位
                B_err       BIT      22H.4   ;夹手标示位
                P_buzzer    EQU      P3.1    ;
                FLAG_byte   EQU      22H     ;

                ORG    0000H
                LJMP   MAIN             ;主程序入口地址
                ORG    0100H
;-----------------------------------------------------------
;               主程序软件复位入口地址
;-----------------------------------------------------------
MAIN:           
                MOV    SP,     #60H
                MOV    P1,     #0FFH        ;I/O口软件复位
                MOV    P3,     #0FFH
                ACALL  BZ                   ;上电嘀一声
                MOV    FLAG_byte,  #0;      ;标示位清零
;------------------------------------------------------------
;               判断工作状态
;------------------------------------------------------------
                JNB     P3.2,  QY_1         ;上电时P3.3等"0"转QY_1(LS1)
                SETB    B_stop              ;置停止使用标示位
                CLR     B_start             ;清启用标示位
                CLR     B_err               ;清夹手标示位
                AJMP    START               ;转起用程序
QY_1:           SETB    B_start             ;置启用标示位
                CLR     B_stop              ;清停止标示位
                CLR     B_err               ;清夹手标示位
;----------------------------------------------------------------
;               标示位判断
;----------------------------------------------------------------
START:          JNB     P1.6,      ZT_1
                AJMP    QY_2
ZT_1:           ACALL   DELAY10MS
                JB      P1.6,      QY_2
                ACALL   BZ
                orl     p1,        #0fh      ;ZT_STOP
QY_2:           JNB     B_start,   TZ_1      ;B_start为"0"转TZ_1
                ACALL   OPEN_K1              ;B_start为"1"启用泡茶桌
TZ_1:           JNB     B_stop,    JS_1      ;B_stop为"0"转JS_1
                ACALL   DON_K1               ;B_stop为"1"停止使用泡茶桌
JS_1:           JNB     B_err,     START_RET
                ACALL   BJ                   ;调用夹手报警程
                AJMP    MAIN
START_RET:      AJMP    START
;------------------------------------------------------------
;          启用主程程序
;-------------------------------------------------------------
OPEN_K1:        JB      P1.4,   UP_LS1 ;P1.4等"0"说明有键按下转去抖处理
                ACALL   DELAY10MS
                JNB     P1.4,   K1_2   ;等"0"有键按下
                AJMP    OPEN_K1        ;没键按下返回
K1_2:           JNB     P1.4,   K1_2   ;等待键置放
                ACALL   BZ
                ACALL   OPEN           ;调用门开子程序
UP_LS1:         JB      P3.3,   UP_LS_STOP
                ACALL   UP             ;调用升起子程序
UP_LS_STOP:     JB      P3.4,   OPEN_K1_RET
                orl     p1,    #0fh      ;调用启用停止子程序
                AJMP    MAIN
OPEN_K1_RET:    RET
;------------------------------------------------------------------
;          停止主程序
;------------------------------------------------------------------
DON_K1:         JB      B_stop,      DON_TZ
DON_TZ:         SETB    B_stop
                CLR     B_start
                CLR     B_err
                JB      P1.5,   CLOSE_LS ;P1.5等"0"说明停止键按下转去抖处理
                ACALL   DELAY10MS
                JNB     P1.5,    K2_1    ;等"0"有键按下
                AJMP    DON_K1           ;没键按下返回
K2_1:           JNB     P1.5,    K2_1    ;等待键置放
                ACALL   BZ               ;调用蜂鸣器嘀一声
                ACALL   DON              ;调用降子程序
                JB      B_stop,      CLOSE_LS
                SETB    B_stop
                CLR     B_start
                CLR     B_err
CLOSE_LS:       JB      P3.5,    CLOSE_LS_STOP
                ACALL   CLOSE            ;调用门关子程序
CLOSE_LS_STOP:  JB      P3.2,    JS_2   ;门合到位感应器LS
                orl     p1,    #0fh       ;调用泡茶桌停用停止程序
                AJMP    MAIN             ;返回开始程序
JS_2:           JB      P1.1,   CLOSE_K1_RET
                JB      P3.7,   CLOSE_K1_RET
                ACALL   BJ1              ;调用夹手处理子程序
CLOSE_K1_RET:   RET

;--------------------------------------------------------------------
;            启用子程序 OPEN
;---------------------------------------------------------------------
OPEN:           CLR     P1.0           ;驱动门电机OPEN
                SETB    P1.1           ;禁止门电机CLOSE驱动
                SETB    P1.2           ;禁止升降电机UP驱动
                SETB    P1.3           ;禁止升降电机DON驱动
                RET
;----------------------------------------------------------------------
;        启用子程序 UP
;----------------------------------------------------------------------
UP:             SETB    P1.0           ;关门电机OPEN驱动
                CLR     P1.2           ;驱动升降电机UP
                SETB    P1.1
                SETB    P1.3
                RET
;----------------------------------------------------------------------
;       停止程序DON
;----------------------------------------------------------------------
DON:            CLR     P1.3           ;驱动升降电机DON
                SETB    P1.1           ;禁止门电机CLOSE驱动
                SETB    P1.2           ;禁止升降电机UP驱动
                SETB    P1.0           ;禁止门电机OPEN驱动
                RET
;-------------------------------------------------------------------------
;       停止程序CLOSE
;-------------------------------------------------------------------------
CLOSE:          SETB    P1.3           ;关升降电机DON驱动
                CLR     P1.1
                SETB    P1.2
                SETB    P1.0
                RET
;-----------------------------------------------------------------------------
;               夹到手反回程序BJ程序
;-----------------------------------------------------------------------------
BJ1:           orl     p1,    #0fh
               ACALL   DELAY500MS
               CLR     B_start
               CLR     B_stop
               SETB    B_err
               CLR     P1.0
BJ_1:          JB      P3.3,       BJ_1
               SETB    P1.0
               RET

;------------------------------------------------------------------------------
;            延时10MS程序
;------------------------------------------------------------------------------
DELAY10MS:   MOV       R7,         #50     ;延时的时间一般为5-20ms
D1:          MOV       R6,         #100
D2:          DJNZ      R6,         D2
             DJNZ      R7,         D1
             RET
;-------------------------------------------------------------------------------
;           延时500MS程序
;-------------------------------------------------------------------------------
DELAY500MS:  MOV       R4,         #00H
             MOV       R4,         #50D
D50:         ACALL     DELAY10MS
             DJNZ      R4,         D50
             RET
;--------------------------------------------------------------------------------
;           蜂鸣器嘀一声程序
;--------------------------------------------------------------------------------
BZ:         MOV        R5,        #00H
            MOV        R5,        #5D
            CLR        P_buzzer
BZ_1:       ACALL      DELAY10MS
            DJNZ       R5,        BZ_1
            SETB       P_buzzer
            RET
;--------------------------------------------------------------------------------
;         蜂鸣器故障报警
;--------------------------------------------------------------------------------
BJ:       CPL         P_buzzer
          JNB         P1.5,        BZ2
          LCALL       DELAY
          SJMP        BJ
BZ2:      JB          B_stop,           BJ_RET
          SETB        B_stop
BJ_RET:   RET
DELAY:    MOV         60H,         #10H
DELAY0:   MOV         61H,         #7FH
DELAY1:   MOV         62H,         #7FH
          JNB         P1.5,        BZ2
          DJNZ        62H,$
          JNB         P1.5,        BZ2
          DJNZ        61H,         DELAY1
          JNB         P1.5,        BZ2
          JNB         P1.5,        BZ2
          RET
          END

使用特权

评论回复
板凳
ayb_ice| | 2008-12-16 21:12 | 只看该作者

夸一下LZ

格式还是蛮清爽的,值得表扬.

使用特权

评论回复
地板
xhtxzxw| | 2008-12-16 21:12 | 只看该作者

嘿嘿

不改,只提个建议:用C吧?

使用特权

评论回复
5
5880527| | 2008-12-16 21:46 | 只看该作者

还不错,有点象那么回事

个人感觉这些输入都应该进行消抖处理一下

使用特权

评论回复
6
piao520|  楼主 | 2008-12-22 12:00 | 只看该作者

首先谢谢大家的指导

    四楼兄弟建议小弟采纳,不过近期可能还是用汇编,因为小生刚开始学单片机,我想先把单片机各各功能了解了差不多后再转C语言编程,这样子可能会比较快一点.
     5楼的兄弟说要去抖,但门一到位时就等一直感应着,也就是说按键一值按着,这样子也要去抖吗???

使用特权

评论回复
7
piao520|  楼主 | 2008-12-22 12:02 | 只看该作者

2楼的 "耕在此行" 大师

   您好!
   您能不能具体的说一下我的程序主要存在着什么问题,我以后编程要主意那些?
   什么时候比较有时间帮小弟改完更是感激不尽!!!

使用特权

评论回复
8
piao520|  楼主 | 2008-12-25 13:54 | 只看该作者

自己来顶一下下下

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

20

主题

185

帖子

0

粉丝