原创 按摩棒程序(电机调速)

2008-3-4 16:09 1808 3 3 分类: MCU/ 嵌入式

按摩棒程序(电机调速)


                       EMC MCU的程序 U3、U4为74HC164


;====================================================
;  软件名称: 358PH-E
;  微控制器: EM78P156
;  晶体频率: 4.00MHz(4时钟周期)
;  软件版本: 
;  编制日期:   2006-09-19
;  修改日期:    2006-09-29
;====================================================


                                  ;// 定义



TCC_COUNT             ==          0X29               ;//TIMER 累计中断次数,用于等级制度
TCC_COUNT1MS          ==          0X2A               ;//TIMER 累计中断次数,电机触发脉冲时间
TEMP_DATA             ==          0X2B               ;//缓存..(U3_LED)......
dASave             ==       0X2C            ;// 中断,A寄存器值保存
dPSWSave              ==       0X2D            ;// 中断,标志寄存器保存


KEY                   ==          0X20               ;//


KEY_P50               ==          0                  ;//k1被按下的标志
KEY_P51               ==          1                  ;//k2被按下的标志
KEY_P52               ==          2                  ;//k3被按下的标志
KEY_P53               ==          3                  ;//k4被按下的标志
KEY_KEYEN             ==          4                  ;//键盘使能标志


FLAG_SYSTEM           ==          0X21               ;//系统标志
TCC_COUNT5MS          ==          0X22               ;//5MS计数器
 
FLAG_LEVEL            ==          0X23               ;//15等级 UP/DOWN
FLAG_MODE             ==          0X24               ;//AUTO:=1,2,3手动:=0


TEMP_FLAGLEVEL        ==          0X25               ;//缓存等级数


TEMP1                 ==          0X26               ;//中间标志 用于MODE2
TCC_COUNT50MS         ==          0X27               ;50MS计数器
TCC_COUNT250MS        ==          0X32               ;250MS计数器(500MS)
TCC_COUNT1S           ==          0X35               ;1S计数器


TEMP_TCCCOUNT         ==          0X34               ;//缓存等级时间


FLAG                  ==          0X33               ;BIT标志


FLAG_ON               ==          0                  ;系统ON/OFF
FLAG_1S               ==          1                  ;1S标志
FLAG_MOTOR0           ==          2                  ;电机过零标志  
FLAG_MOTORON          ==          3                  ;电机是否已经触发标志
FLAG_AUTO             ==          4                  ;AUTO MODE 标志
FLAG_5MS              ==          5                  ;5MS标志
FLAG_MODE2HL          ==          6                  ;MODE3脉冲0/1标志
FLAG_250MS            ==          7                  ;250MS标志


PC                 ==   0X02                ;// R2
PSW                ==   0X03                ;// R3
TCC                ==   0X01                ;// R1
P5                    ==   0X05                ;// Port5
P6                    ==   0X06                ;// Port6
IOWB                  ==      0X0B                   ;// P5内部下拉


SHOFF_DATA            ==          0X2E               ;//指示灯参数入口
SHOFF_COUNT           ==          0X2F               ;//BIT 计数
SHOFF_CLK             ==          6                  ;//U3时钟脚
SHOFF_A               ==          7                  ;//U3串行输入端


DISPLAY_DATA          ==          0X30               ;//DISPALY 级别参数入口
DISPLAY_COUNT         ==          0X31               ;//BIT 计数
BIT_Choice1           ==          3                  ;//位选2
BIT_Choice2           ==          2                  ;//位选1
DISPLAY_A             ==          4                  ;//U4串行输入端
DISPLAY_CLK           ==          5                  ;//U4时钟端


MOTOR_Control         ==          1                  ;//MOTOR 导通控制
 
; ===================================================
;|***************************************************
;|*
;|*                        主程序开始
;|*
;|***************************************************
; ===================================================


                            ORG 00H
                                JMP START
                            ORG 08H
                                JMP INTERRUPT
                           ;ORG 40H


START:
     JMP MAIN
;/////////////////////    数据表////////////////////////
        
TABL_TCC:                                              ;等级延时时间表
                 ADD  PC,A 
                 RETL @50                              ;0
                 RETL @37                              ;1
                 RETL @36                              ;2
                 RETL @34                              ;3       
                 RETL @32                              ;4
                 RETL @31                              ;5
                 RETL @30                              ;6
                 RETL @28                              ;7
                 RETL @26                              ;8
                 RETL @24                              ;9
                 RETL @22                              ;10
                 RETL @19                              ;11
                 RETL @17                              ;12
                 RETL @15                               ;13
                 RETL @12                               ;14
                 RETL @10                               ;15 
 
TAB_MODE:
                 ADD  PC,A                              ;//
                 RETL @00000000B                       ;//手动
                 RETL @10000000B                       ;//MODE1
                 RETL @01000000B                       ;//MODE2
                 RETL @00100000B                       ;//MODE3


TAB_DIODE:
                 ADD  PC,A                             ;//指示灯扫描
                 RETL @00000000B                       ;0
                 RETL @00000001B                       ;1 LED1
                 RETL @00000001B                       ;2 LED1
                 RETL @00000001B                       ;3 LED1
                 RETL @00000011B                       ;4 LED1,2
                 RETL @00000011B                       ;5 LED1,2
                 RETL @00000011B                       ;6 LED1,2
                 RETL @00000011B                       ;7 LED1,2
                 RETL @00000011B                       ;8 LED1,2
                 RETL @00000111B                       ;9 LED1,2,3
                 RETL @00000111B                       ;10 LED1,2,3
                 RETL @00000111B                       ;11 LED1,2,3
                 RETL @00001111B                       ;12 LED1,2,3,4
                 RETL @00001111B                       ;13 LED1,2,3,4
                 RETL @00001111B                       ;14 LED1,2,3,4
                 RETL @00011111B                       ;15 LED1,2,3,4,5
                


TAB_CODE:                                              ;//七段译码
                 ADD PC,A
                 RETL @00000001B                       ;0  1
                 RETL @00111111B                       ;1  63
                 RETL @01001000B                       ;2  64
                 RETL @00101000B                       ;3  40    
                 RETL @00110110B                       ;4  54
                 RETL @10100000B                       ;5  160
                 RETL @10000000B                       ;6  128
                 RETL @00111011B                       ;7  59
                 RETL @00000000B                       ;8  0
                 RETL @00100000B                       ;9   32


   


;///////////////////////////////////////////////////////
;******************************MAIN*********************
;///////////////////////////////////////////////////////


MAIN:
                 NOP
                 MOV   A  , @1                          ;//设置P60为IN,其它的为OUT
                 IOW   P6   
                 MOV   A  , @0FFH                       ;//设置P5为IN
                 IOW   P5
               
                 MOV   A  , @0FFH
                 IOW   IOWB                             ;//关P5内部下拉
                                                        ;//IOCE        0X0E
                 MOV   A  , @11000000B                  ;//开WDT//P60为/INT功能//关闭P5的R_OPTION
                 IOW   0X0E
                                                        ;//CONT       


                 MOV   A  , @14                         ;//分频器给WDT用//TCC为内部Clock触发,WDT的分频为1:128;
                 CONTW                                  ;//WDT溢出时间:128*18MS/1000=2.3S                   
                                                        ;//IOCF       0X0F 
                 MOV   A  , @00000101B                  ;//TCC Enable  //电平中断Disable //INT Enable
                 IOW   0X0F       
              
                 WDTC
  
                 MOV   A  , @0                          ;//初始化为0
                
                 MOV   FLAG_SYSTEM,A
                 MOV   FLAG_LEVEL,A
                 MOV   FLAG_MODE,A
                
                 MOV   A , @5                            ;//1MS
                 MOV   TCC_COUNT1MS,A
                 MOV   A , @25                           ;//5MS
                 MOV   TCC_COUNT5MS,A
                
                 BS    P6 , BIT_CHOICE1                 ;//上电不显示
                 BS    P6 , BIT_CHOICE2
                 BS    P6 , MOTOR_Control               ;//上电不触发电机
                 BC    FLAG,FLAG_MOTOR0                 ;//上电CLR电机过零标志
                
               
                 BC    FLAG,FLAG_AUTO                   ;//初始化为0
                
                 BC    0X0F,0                           ;//清中断TCC FLAG  
                 BC    0X0F,1                           ;//清中断FLAG  
                 BC    0X0F,2                           ;//清中断INT FLAG  
                
                 MOV   A  , @56
                 MOV   TCC,A                            ;//TIMER 的初值:256-56==200US
                 ENI                                    ;//开全局中断
               
LOOP:           
                 WDTC
    
                ; CALL KEY_SCAN
;*********************************************************
;/////////////////////////////////////扫描按键////////////
;*********************************************************


KEY_SCAN:      
               
                JBC    KEY,KEY_KEYEN                      ;//键盘使能开?
                JMP    NEXT_SCAN                          ;//开,扫描P5
                JMP   waiting                             ;//没有开.不扫P5,测使能?
               
              
;*********************************************************
;***********************************扫P5******************
;*********************************************************
NEXT_SCAN:      
                MOV    A,  P5
                CALL   DELAY5MS
                MOV    A,  P5  
                AND    A,  @0X0F                          ;//存低四位
                XOR    A,  @0X0F                          ;//P5是否与0X0F相同,不同,Z=0,即有键摁下
                JBC    PSW,2                              ;//Z=0有键摁下,为1无
                JMP    KEY_END                            ;//重新扫描
                JMP    PRESS_KEY                          ;//
               
;///////////////////// KEY_FOUNTION //////////////////////


PRESS_KEY:                     
                                                          ;///////////////具体键位检测/////////////////          
                JBS    P5,0                               ;//为1,测下一位;为0转向置FOUNTION_ON标志
          
                JMP    NEXT_PRESSP50
                JMP    NEXT_P51       
               
NEXT_PRESSP50:               
               
                BS     KEY , KEY_P50                      ;//置K1被按下标志
                BC     KEY , KEY_KEYEN                    ;//关键盘使能            
                JMP    NEXT_JBCKEY                        ;//
NEXT_P51:          
                JBS    P5, 1                               ;//..........................
                JMP    NEXT_PRESSP51          
                JMP    NEXT_P52
               
NEXT_PRESSP51:               
              
                BS     KEY , KEY_P51                      ;//置K2被按下标志
                BC     KEY , KEY_KEYEN                    ;//关键盘使能  
                JMP    NEXT_JBCKEY
NEXT_P52:         
                JBS    P5,2                                ;//........................
                JMP    NEXT_PRESSP52
              
                JMP    NEXT_P53
                                        
                
NEXT_PRESSP52:               
              
                BS     KEY , KEY_P52                      ;//置K3被按下标志   
                BC     KEY , KEY_KEYEN                    ;//关键盘使能  
                JMP    NEXT_JBCKEY       
               
NEXT_P53:
                JBS    P5,3                                ;//..........................
                JMP    NEXT_PRESSP53
                JMP    KEY_END
     
NEXT_PRESSP53:               
              
                BS     KEY ,KEY_P53                       ;//置K4被按下标志     
                BC     KEY , KEY_KEYEN                    ;//关键盘使能                                                      


    ;//释放了,执行相应功能
NEXT_JBCKEY:
                JBC    KEY ,KEY_P50
                JMP    P50_FOUNTION                       ;//K1开机键,被按下跳
                JBC    KEY ,KEY_P51
                JMP    P51_FOUNTION                       ;//K2模式键,被按下
                JBC    KEY ,KEY_P52
                JMP    P52_FOUNTION                       ;//K3 UP键,被按下
                JBC    KEY ,KEY_P53
                JMP    P53_FOUNTION                       ;//K4 DOWN键,被按下
                JMP    KEY_END
;//////////////////////////////////////////////////////////
;********************************P5功能********************
;//////////////////////////////////////////////////////////
P50_FOUNTION:
                COM    FLAG_SYSTEM                         ;//取反系统标志,FLAG_SYSTEM=FF开机
                BC     KEY ,KEY_P50                        ;//CLR P50被按下标志
                MOV    A,  FLAG_SYSTEM
                XOR    A,  @0FFH
                JBC    PSW,2
                JMP    FOUNTION_ON                         ;//开机,手动一级
               
                JMP    KEY_END


P51_FOUNTION:  
                  BC     KEY ,KEY_P51                        ;//CLR P51,K2被按下标志
                  INC    FLAG_MODE                           ;//模式加1
                  JMP    FOUNTION_MODE                       ;//跳到模式判断
                               
P52_FOUNTION:
                  BC     KEY ,KEY_P52                       ;//CLR P52,K4被按下标志
                  CLR    FLAG_MODE                          ;//功能是在AUTO_MODE下DOWN被按下,返回手动
                  JMP    FOUNTION_DOWN
                 
P53_FOUNTION:
                  BC     KEY ,KEY_P53                       ;//CLR P53,K3被按下标志
                  CLR    FLAG_MODE                          ;//功能是AUTO_MODE下UP被按下,返回手动
                  JMP    FOUNTION_UP
                 


;***********************************************************
;////////////////////////////功能///////////////////////////
;***********************************************************


FOUNTION_ON: ;******************开机************************//进入手动1级
                CLR    FLAG_MODE                           ;//FLAG_MODE=0 手动
              
                MOV    A,@1
                MOV    FLAG_LEVEL,A 
                CALL   DELAY_LEVEL                           ;///查询等级延时时间TCC_COUNT=A
                BC     FLAG,FLAG_AUTO                      ;//自动标志为0,
              
                JMP    KEY_END
                
FOUNTION_MODE:                                             ;//AUTO OR Manual  按一次为AUTO,MODE1,二次为MODE2,三次为MODE3,
                                                           ;//0 OR 4次为Manual
                MOV    A,FLAG_MODE
                XOR    A,@0                                ;//手动  0,4                         
                JBS    PSW,2
                JMP    NEXT_FAUTO                          ;//转  置AUTO标志                   
                JMP    NEXT_FMANUAL                        ;//转  置MANUAL标志     


NEXT_FAUTO:                                                ;//置AUTO标志,查模式1,2,3
                BS     FLAG,FLAG_AUTO               
                JMP    KEY_END


NEXT_FMANUAL:                                              ;//置MANUAL标志,手动UP/DOWN         
                BC     FLAG,FLAG_AUTO 
                JMP    KEY_END


;***********************************************************
;......................................AUTO.................
;***********************************************************         
AUTO:          
                WDTC                                        ;//
                MOV   A,FLAG_MODE                           ;//
                XOR   A,@1                                  ;//FLAG_MODE=1,A=0,Z=1
                JBC   PSW,2                                 ;//
                JMP   MODE1                                 ;//FLAG_MODE=1,转 模式1


                MOV   A,FLAG_MODE                           ;//
                XOR   A,@2
                JBC   PSW,2                     
                JMP   MODE2                                 ;//FLAG_MODE=2,转 模式2
       
                MOV   A,   FLAG_MODE                        ;//
                XOR   A,   @3
                JBC   PSW, 2
                JMP   MODE3                                 ;//FLAG_MODE=3,转 模式3
       
                MOV   A,   FLAG_MODE
                XOR   A,   @4
                JBC   PSW, 2
                CLR   FLAG_MODE                              ;//FLAG_MODE=4,回到手动级      
       
                JMP   AUTO_RET


;************************************************************
;........................................AUTO_MODE1..........
;************************************************************
MODE1 :     
                JBC    FLAG,FLAG_250MS
                JMP    NEXT_INCLEVEL
                JMP    NEXT_JMPINC
NEXT_INCLEVEL:               
                INC    FLAG_LEVEL                            ;//;//1->>>-15,250MS +1
                CALL   DELAY_LEVEL                           ;///查询等级延时时间TCC_COUNT=A
               
NEXT_JMPINC:                
             
                WDTC                                         ;//喂DOG
                BC     FLAG,FLAG_250MS
                MOV    A,FLAG_LEVEL                   
                XOR    A,  @16
                MOV    A,  @1                                ;//16级了?不是继续累加
                JBC    PSW,2
                JMP    NEXT_MOVLEVEL1
                JMP    AUTO_RET
NEXT_MOVLEVEL1:               
                MOV    FLAG_LEVEL,A                          ;//FLAG_LEVEL=1
                CALL   DELAY_LEVEL                           ;///查询等级延时时间TCC_COUNT=A
                JMP    AUTO_RET
;************************************************************
;........................................AUTO_MODE2..........
;************************************************************            
MODE2:                                                       ;//1--->>15>>---1
                WDTC                                         ;//喂DOG 
                MOV    A, TEMP1                              ;//TEMP1为0 增    ,1减         
                XOR    A,@0
                JBC    PSW,2
                JMP    M_INC                                 ;//转,上升
                JMP    M_DEC                                 ;//转,下降
M_INC:      
                JBC    FLAG,FLAG_250MS
                JMP    NEXT_INC2LEVEL 
                JMP    NEXT_JMP2LEVEL
            
NEXT_INC2LEVEL:
                INC    FLAG_LEVEL                            ;//1->>>>-15,上升
                CALL   DELAY_LEVEL                           ;///查询等级延时时间TCC_COUNT=A
           
NEXT_JMP2LEVEL: 
                BC     FLAG,FLAG_250MS                       ;//清250MS标志
                          
                MOV    A,FLAG_LEVEL                  
                XOR    A,@15
                MOV    A,@1
                JBS    PSW,2                                 ;当FLAG_LEVEL=15,Z=1, DOWN FLAG_LEVEL
                JMP    MODE2_END           
                MOV    TEMP1,A                               ;TEMP1为1减  15 DEC >>>1
                JMP    MODE2_END 
M_DEC:      
                JBC    FLAG,FLAG_250MS                       ;//250MS -1
                JMP    NEXT_DECLEVEL
                JMP    NEXT_JMPDEC
NEXT_DECLEVEL:
            
                DEC    FLAG_LEVEL                             ;//15--1,下降
                CALL   DELAY_LEVEL                            ;///查询等级延时时间TCC_COUNT=A
 NEXT_JMPDEC:            
           
                BC     FLAG,FLAG_250MS                         ;//清250MS标志
             
                MOV    A,FLAG_LEVEL                  
                XOR    A,@1
                MOV    A,@1
                JBS    PSW,2                                   ;当FLAG_LEVEL=1时,Z=1,UP FLAG_LEVEL
                JMP    MODE2_END   
                CLR    TEMP1                                   ;//TEMP1=0 ,1 INC 15
MODE2_END:             
                JMP    AUTO_RET
;***************************************************************
;........................................AUTO_MODE3.............
;***************************************************************          
MODE3 :                                                        ;// 0/1脉冲
                WDTC
                JBS    FLAG,FLAG_MODE2HL       
                JMP    NEXT_L                                      ;//0,低速
                JMP    NEXT_H                                      ;//1,高速
                     
NEXT_L:      
               JBC     FLAG,FLAG_1S
               JMP     NEXT_LL                                     ;//1S时间到.脉冲0
               JMP     AUTO_RET                                    ;//1S没有到,结束
NEXT_LL:
               MOV     A,@1
               MOV     FLAG_LEVEL,A                                ;//  0/1脉冲 的0
               CALL    DELAY_LEVEL                                 ;///查询等级延时时间TCC_COUNT=A
               BS      FLAG, FLAG_MODE2HL
               BC      FLAG,FLAG_1S
               JMP     AUTO_RET
NEXT_H:           
               JBC     FLAG,FLAG_1S
               JMP     NEXT_HH                                     ;//1S时间到.脉冲1
               JMP     AUTO_RET                                    ;//1S没有到,结束
           
NEXT_HH:          
               MOV     A,@15
               MOV     FLAG_LEVEL,A                                 ;0/1脉冲的1,FLAG_LEVEL=15
               CALL    DELAY_LEVEL                                  ;///查询等级延时时间TCC_COUNT=A
               BC      FLAG,FLAG_1S
               BC      FLAG, FLAG_MODE2HL
AUTO_RET:
               RET


;***********************************************************
;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FOUNTION_UP,,,,,,,,,,,,,,,
;***********************************************************


FOUNTION_UP:                                               ;//延时短,MOTOR导通时间长,力度增,
              WDTC                                         ;//喂DOG
              INC     FLAG_LEVEL
              CALL    DELAY_LEVEL                          ;///查询等级延时时间TCC_COUNT=A
              MOV     A,FLAG_LEVEL
              XOR     A,@16
              MOV     A,@1
              JBC     PSW,2                                 ;//FLAG_LEVEL=16时z=1,重新累加
              MOV     FLAG_LEVEL,A                          ;//FLAG_LEVEL=1 
              CALL    DELAY_LEVEL                           ;///查询等级延时时间TCC_COUNT=A        
              JMP     KEY_END
;************************************************************
;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,FOUNTION_DOWN,,,,,,,,,,,,,,
;************************************************************
FOUNTION_DOWN:                                            ;//SPEED,力度减
            ; WDTC                                        ;//喂DOG
              MOV    A,FLAG_LEVEL                  
              XOR    A,@1
              MOV    A,@15
              JBS    PSW,2
              JMP    NEXT_JMPKEYEND
              MOV    FLAG_LEVEL,A                          ;//FLAG_LEVEL=15
              CALL   DELAY_LEVEL                           ;///查询等级延时时间TCC_COUNT=A
              JMP    KEY_END
NEXT_JMPKEYEND:
              DEC    FLAG_LEVEL
              CALL   DELAY_LEVEL                           ;///查询等级延时时间TCC_COUNT=A                           
              JMP    KEY_END
KEY_END:
;*****************************键盘结束*************************  
;///////////////////////////按键是否释放///////////////////////               
              
waiting:                                                   ;//按键是否释放
               ; CALL   DELAY5MS
                JBS     FLAG,FLAG_5MS                      ;//5MS 是否到了??
                JMP     NEXT_WAITINGRET
                BC      FLAG,FLAG_5MS           
                MOV     A,P5
                XOR     A,@0FH
                JBS     PSW,2
                JMP     NEXT_WAITINGRET
                BS      KEY , KEY_KEYEN                     ;//开键盘使能
NEXT_WAITINGRET:               
                  
;***************************************************************
;***********************************  开机?  *******************
;***************************************************************                                    
                 MOV    A,FLAG_SYSTEM                      ;//SYSTEM FLAG ON/OFF?
                 XOR    A,@0FFH
                 JBS    PSW,2                              ;//FLAG_SYSTEM=0,Z=0,关电机 ,不显示
                 JMP    NEXT_OFFSYS
                 WDTC
                ; CALL FOUNTION_AM                         ;//AUTO OR MANUAL    
                 JBC    FLAG, FLAG_AUTO
                 JMP    NEXT_CALLAUTO
                 JMP    NEXT_CALLMANUAL                    ;//不进入自动.即是手动
NEXT_CALLAUTO:                                             
                 CALL   AUTO
               
NEXT_CALLMANUAL:                           
                 NOP           
                 WDTC
                
;**************************************************************
;*************************************** 显示 *****************
;**************************************************************            


                              
                               CALL DISPLAY              
          
                 JMP  LOOP
 
;//////////////////////////////////////////////////////////////
;********************************关机**************************
;//////////////////////////////////////////////////////////////
      
NEXT_OFFSYS:
                 BS    P6 , MOTOR_Control               ;//关机不显示,不触发电机
                 BS    P6 , BIT_CHOICE1                 ;//关显示
                 BS    P6 , BIT_CHOICE2
                 MOV   A  , @0
                 CALL  PASS_U3                          ;//关机灭灯
                 JMP   LOOP


;***************************************************************  
;////////////////////////////中断///////////////////////////////
;***************************************************************
INTERRUPT:
                  DISI                                    ;// 关全局中断
                  JBC    0X0F,0                           ;//为1是TCC中断,0转向检测INT
                  JMP    TCC_INT
                  JBC    0X0F,2                           ;//为1是INT中断
                  JMP    INT_INT
                  JMP    RE_FIME
                  RETI
                                            
TCC_INT:
                  MOV    dASave, A                  ;// 保护现场,A高低位交换保存到dASave中,
               SWAP   dAsave                  ;// 由于该单片机只有5级堆栈,故使用此方法保护现场
               SWAPA  PSW                     ;// 标志寄存器PSW高低位交换,保存到dPSWSave中
               MOV dPSWSave,A
             
                  BC     0X0F,0                           ;//清TCC中断标志
                  MOV    A, @66     
                  MOV    TCC,A                            ;//重新装入定时数据,加10个指令周期时间补偿
;........................................................             
;***************************电机触发*********************          
;........................................................
            
                 MOV    A,FLAG_SYSTEM                    ;//开启状态?                                               
                 XOR    A,@0FFH   
                 JBS    PSW,2           
                 JMP    NEXT_Continue1                   ;//未开机
                               
                 JBS    FLAG,FLAG_MOTORON                ;//电机已经触发??                
                 JMP    NEXT_JBSMOTOR0                   ;//未触发,查过零?
                 JMP    NEXT_DELAY1MS                    ;//已经触发,延时1MS
NEXT_JBSMOTOR0:                
                 JBS    FLAG,FLAG_MOTOR0                 ;//过零?
                 JMP    NEXT_Continue1                   ;//未过零
                                                         ;//
                 DJZ    TCC_COUNT                        ;//时间到?
                 JMP    NEXT_Continue1                   ;//时间未到
               
                 BC     P6,MOTOR_Control                 ;//等级延时时间到+开机+过零=触发电机
                 BS     FLAG,FLAG_MOTORON                ;//SBIT 电机已经触发标志
                 BC     FLAG,FLAG_MOTOR0                 ;//CLR电机过零标志
                ; CALL   DELAY_LEVEL                     
                 MOV    A,TEMP_TCCCOUNT                  ;//TCC_COUNT备份
                 MOV    TCC_COUNT,A                      ;//重装等级延时时间TCC_COUNT=A
                 JMP    NEXT_Continue1                
NEXT_DELAY1MS:               
                 DJZ    TCC_COUNT1MS                     ;//1MS计数器.电机触发信号脉宽
                 JMP    NEXT_Continue1                   ;//1MS未到,跳过
                
                 BS     P6,MOTOR_Control                 ;//1MS到,关电机触发信号
                 BC     FLAG,FLAG_MOTORON                ;//CLR电机已经触发标志为0,电机未触发
                 BC     FLAG,FLAG_MOTOR0                 ;//CLR电机过零标志
                 MOV    A , @5                           ;//重装1MS数据
                 MOV    TCC_COUNT1MS,A
                
;........................................................
;********************************************************          
;........................................................
      
NEXT_Continue1: 
                 ; WDTC                                    ;//测试出程序只在中断执行
            
                  DJZ    TCC_COUNT5MS                      ;//25*200uS=5MS计数器
                  JMP    NEXT_INC50MS
                  
                  BS    FLAG,FLAG_5MS                     ;//5MS到.置5MS标志,
                  MOV   A,@30                             ;//重装
                  MOV   TCC_COUNT5MS,A



NEXT_INC50MS:                
                 INC    TCC_COUNT50MS                    ;//50MS计数器
                 MOV    A, TCC_COUNT50MS
                 XOR    A, @250                          ;250*200uS=50MS
                 JBC    PSW ,2
                 JMP    NEXT_INC250MS
                 JMP    RE_FIME
       
NEXT_INC250MS:
       
                INC    TCC_COUNT250MS                    ;//250MS计数器
                INC    TCC_COUNT1S                       ;//1S计数器
                CLR    TCC_COUNT50MS
       
                MOV    A,TCC_COUNT250MS                  ;//
                XOR    A,@10                             ;//5*50MS=250MS;10*50MS=500MS(用在AUTO_MODE)
                JBC    PSW,2
                JMP    NEXT_SBIT250MS
                JMP    RE_FIME
       
NEXT_SBIT250MS:


                BS     FLAG,FLAG_250MS                    ;//250MS时间到.置250MS标志位
                CLR    TCC_COUNT250MS                     ;//清250MS计数器
              
                MOV    A,TCC_COUNT1S                      ;//
                XOR    A,@20                              ;//50MS*20=1S(用在AUTO_MODE3)
                JBC    PSW,2
                JMP    NEXT_SBIT1S
                JMP    RE_FIME
NEXT_SBIT1S:
                BS     FLAG,FLAG_1S                      ;//1S时间到.置1S标志位                
                CLR    TCC_COUNT1S
               
               
RE_FIME:
                SWAPA dPSWSave                   ;// 恢复现场
             MOV   PSW, A
             SWAPA dASave
                ENI                                       ;//开中断
                                                          ;//中断返回   
                RETI 
                   
               
INT_INT:
                BC     0X0F,2                             ;//清外部中断FLAG      
                BS     FLAG,FLAG_MOTOR0                   ;//电机过零标志      
                ENI
               ; WDTC
               RETI                                       ;//测试出程序只在中断执行            


                                                          ;// ?


;/////////////////////////////////////////////////////////
;**********************延时时间查询***********************
;/////////////////////////////////////////////////////////


DELAY_LEVEL:
            MOV A ,FLAG_LEVEL
            CALL TABL_TCC
            MOV TCC_COUNT,A
            MOV TEMP_TCCCOUNT,A
    
            RET
           
          
;/////////////////////////////////////////////////////////
;**********************DISPLAY****************************
;/////////////////////////////////////////////////////////
DISPLAY:
       BC  PSW,0                        ;//CLR C
       MOV  A, FLAG_MODE                ;///////U3
       CALL TAB_MODE
       MOV  TEMP_DATA,A
       MOV  A,FLAG_LEVEL                ;//按等级闪光
       CALL TAB_DIODE
       OR   A,TEMP_DATA
             
       CALL  PASS_U3


       MOV A,@10                        ;///////U4
       SUB A,FLAG_LEVEL
       JBS PSW,0
       JMP DATA_0                       ;//C=0时,有借位,此时FLAG_LEVEL<10
       JMP DATA_1                       ;//C=1时,无借位,此时FLAG_LEVEL>=10
     
DATA_0:
        BC  PSW,0                        ;//CLR C     
        MOV A,@00000001B                 ;// 0
        CALL PASS_U4
       
        BC   P6,BIT_CHOICE2              ;//BIT
        BS   P6,BIT_CHOICE1
        CALL DELAY5MS
        /*
        JBS  FLAG,FLAG_5MS               ;//5MS 是否到了?到了往下发个位数
        JMP  NEXT_DATA0RET               ;//没有到,跳出
        BS   P6,BIT_CHOICE2              ;//灭十位              
       */
        MOV   A,FLAG_LEVEL
        CALL TAB_CODE
        CALL PASS_U4
        BS   P6,BIT_CHOICE2
        BC   P6,BIT_CHOICE1
       
      /* JBS  FLAG,FLAG_5MS               ;//5MS 是否到了?到了灭个位
        JMP  NEXT_DATA0RET               ;//没有到,跳出
       
        BS   P6,BIT_CHOICE1              ;//灭个位 
      */
        CALL DELAY5MS
        JMP  NEXT_DISPLAYRET
           
DATA_1:
        MOV   A,@00111111B                 ;//1
        CALL  PASS_U4
        BC   P6,BIT_Choice2               ;//BIT
        BS   P6,BIT_CHOICE1
        CALL DELAY5MS
      /*  JBS  FLAG,FLAG_5MS               ;//5MS 是否到了?到了往下发个位数
        JMP  NEXT_DATA1RET               ;//没有到,跳出
       
        BS   P6,BIT_CHOICE2              ;//灭十位      
      
       */
        MOV   A,@10
        SUB   A,FLAG_LEVEL
        CALL  TAB_CODE
        CALL  PASS_U4
        BS   P6,BIT_Choice2
        BC   P6,BIT_Choice1     
        CALL DELAY5MS
       /* JBS  FLAG,FLAG_5MS               ;//5MS 是否到了?到了灭个位
        JMP  NEXT_DATA1RET               ;//没有到,跳出
       
        BS   P6,BIT_CHOICE1              ;//灭个位    
         */
NEXT_DISPLAYRET:


                RET 
           
             
PASS_U3:
        MOV  SHOFF_DATA,A
        MOV  A,@8
        MOV  SHOFF_COUNT,A               ;//8 BIT
  
U3_LOOP:
        BC   P6, SHOFF_CLK
        JBS  SHOFF_DATA ,7               ;//为1则将P67置1;为0则将P67置0
        JMP NEXT1
        BS   P6, SHOFF_A
        JMP NEXT2
NEXT1:
        BC P6,SHOFF_A    
NEXT2: 
       
        NOP
        NOP
        BS   P6, SHOFF_CLK                ;//产生一个上升沿              
        BC   P6, SHOFF_CLK                ;//CLK为低,保持输出
        RLC   SHOFF_DATA                  ;//左移
        DJZ  SHOFF_COUNT                  ;//移完8BIT结束,否则继续
       
        JMP  U3_LOOP
       
            RET
           
;//////////////数码管控制///////////////


PASS_U4:
        MOV  DISPLAY_DATA,A
        MOV  A,@8
        MOV  DISPLAY_COUNT,A       
LOOP_U4:
        BC   P6, DISPLAY_CLK
        JBS  DISPLAY_DATA ,7               ;//为1则将P65置1;为0则将P65置0
        
        JMP NEXT3              
        BS   P6, DISPLAY_A                 
        JMP NEXT4
NEXT3:
        BC   P6, DISPLAY_A
NEXT4:        
        NOP
        NOP       
        BS   P6, DISPLAY_CLK               ;//产生一个上升沿
        NOP
      
        BC   P6, DISPLAY_CLK                ;//CLK为低,保持输出
                   
        RLC  DISPLAY_DATA                  ;//左移
        DJZ  DISPLAY_COUNT                 ;//0移完8BIT--DISPLAY,1继续
             
        JMP  LOOP_U4
        RET
       
       
       
         


;////////////////////////////////////////////////////
;**********************延时**************************
;////////////////////////////////////////////////////  


          
DELAY5MS:                    ;//5MS/// 8MS
         MOV A,@5            
         MOV 0X37,A
DELAYHL:
         MOV A,@250
         MOV 0X36,A
DELAYHH:
         NOP
         DJZ 0X36
         JMP DELAYHH
         DJZ 0X37
         JMP DELAYHL
            RET
ORG 0X3FF
JMP START
 
    END



 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条