宏部分,宏为以后的修改非常方便,望学习汇编的好好学习这一方法
;*******************************Macro Assembler Start******************************************
REG_CLR MACRO DATA_START,DATA_END
CLR A
MOV R0,#DATA_END
MOV R1,#(DATA_END-DATA_START)
REPEAT_CLR:
MOV @R0,A
DEC R0
DJNZ R1,REPEAT_CLR
ENDM
TIME_INITIAL MACRO SYSTEM_TIME
MOV TL0,#((65536-SYSTEM_TIME) MOD 256)
MOV TH0,#((65536-SYSTEM_TIME)/ 256)
ENDM
TIME_MODEL_SET MACRO
MOV TMOD,#01H;
SETB EA
SETB ET0
SETB TR0
ENDM
TIME_CORRECT MACRO SYS_TIME ;the task time correct automaticlly ;
MOV A,#((65536-SYS_TIME+7) MOD 256) ;default worth is 5ms
CLR TR0
ADD A,TL0
MOV TL0,A
MOV A,TH0
ADDC A,#((65536-SYS_TIME+7 )/256)
MOV TH0,A
SETB TR0
ENDM
TASK_REG_INITIAL MACRO
DEC A
MOV SP,A ;sp points to the stack of the idle task
MOV TASK_RD_INDEX,#03FH ;all tasks are inserted to the task_ready_squeue
MOV TASK_CURRENT_ID,#05H;start with the task idle who have the lowest priority
MOV TASK_POSITION,#~TASK_POSITION_ID
MOV TASK_TIMEOUT,#TASK_TIMEOUT_SET ;
SETB REAL_TASK ;indicate that there is a task running
ENDM
TASK_STACK_INITIAL MACRO
MOV STACK_BACK_L,#LOW(TASK_SWITCH_FUC)
MOV STACK_BACK_H,#HIGH(TASK_SWITCH_FUC)
MOV R0,#TASK_STACK_START
MOV A,R0
ADD A,#06H
MOV TASK0_SP,A
MOV A,R0
MOV @R0,#LOW(TASK0)
INC R0
MOV @R0,#HIGH(TASK0)
ADD A,#TASK0_FREE_SPACE
ENDM
TASK_CREATE MACRO TASK_FREE_SPACE,ADDRESS,LOCALSP,REG_INI,REG0,REG1,REG2
MOV R0,A
ADD A,#06H
MOV LOCALSP,A
MOV A,R0
MOV @R0,#LOW(ADDRESS)
INC R0
MOV @R0,#HIGH(ADDRESS)
ADD A,#TASK_FREE_SPACE
IF REG_INI <>0
INC R0 ;ignore ACC
INC R0
MOV @R0,REG0
INC R0
MOV @R0,REG1
INC R0
MOV @R0,REG2
ENDIF
ENDM
SEND_SIGNAL MACRO ID,FLAG,CONTROL
IF CONTROL <> 0
SETB FLAG
MOV A,ID&_DELAY
JNZ END_&ID
SETB ID&_READY
END_&ID:
NOP
ELSE
SETB FLAG
SETB ID&_READY
ENDIF
ENDM
GET_SIGNAL MACRO ID,FLAG,SUSPEND_SIGNAL
JBC FLAG,DP&ID
IF SUSPEND_SIGNAL ==0
SETB C
ENDIF
IF SUSPEND_SIGNAL <> 0
CLR EA
CLR REAL_TASK
SETB TASK_SUSPEND
ACALL TASK_SWITCH_FUC
ENDIF
DP&ID:
NOP
ENDM
TASK_GIVEUP MACRO
CLR EA
CLR REAL_TASK
ACALL TASK_SWITCH_FUC
ENDM
TASK_SUSPENDSET MACRO
CLR EA
CLR REAL_TASK
SETB TASK_SUSPEND
ACALL TASK_SWITCH_FUC
ENDM
TASK_DELAYSET MACRO ID,TIME
MOV ID&_DELAY,TIME
SETB TASK_SUSPEND
ENDM |