#include "hotcom.h" Procedure (WDCON_Timeout_Setup) begin macro_disable_interrupt(),//关中断 asm_SETB_BIT(HotASM_WDCON_WDWR), asm_MOV_REG(HotASM_WDCON, HotASM_WDCON_Timeout_2000_0mS), macro_enable_interrupt(),//开中断 Procedure_return()//过程返回 end;
/*-------------------------------------- HotTask51汇编数组调用函数库 --------------------------------------*/ Procedure_Arg1 (__HotASM_STARTnew__, macro_U8_arg1)//(void) begin//DPTR保存的是汇编数组函数的首地址__HotASM_START__ #define lable__HotASM_START__Exit ( size_CLR_A() + size_MOV_REG_A() + size_JZ() + size_LJMP() + 2 * size_MOV_A_REG() + 2 * size_ADD_A() + 2 * size_PUSH_REG() ) asm_CLR_A(), asm_MOV_IE_A(),//关中断 asm_JZ(size_LJMP() - 1),//NOP() asm_LJMP(0x5500),// asm_MOV_A_DPL(), asm_ADD_A(lable__HotASM_START__Exit),//__HotASM_START__0 asm_PUSH_ACC(),//压入跳入地址__HotASM_START__0低8位 asm_MOV_A_DPH(),// asm_ADDC_A(0), asm_PUSH_ACC(),//压入跳入地址__HotASM_START__0高8位 //lable__HotASM_START__Exit: Interrupt_return()//(连续调用RETI二次) end;
/*--------------------------------------------- HotTask51系统启动函数 void __HotASM_START__(void) 入口: 无 Keil DPTR = &__HotASM_START__[0] R2R1 = DPTR 出口: 无 结果: 二次RETI后继续执行 特点: 本“函数”可以“动态加载” -----------------------------------------------*/ Procedure (__HotASM_START__)//(void) begin//DPTR保存的是汇编数组函数的首地址__HotASM_START__ #define lable__HotASM_START__Exit ( size_CLR_A() + size_MOV_REG_A() + size_JZ() + size_LJMP() + 2 * size_MOV_A_REG() + 2 * size_ADD_A() + 2 * size_PUSH_REG() ) asm_CLR_A(), asm_MOV_IE_A(),//关中断 asm_JZ(size_LJMP() - 1),//NOP() asm_LJMP(0x5500),// asm_MOV_A_DPL(), asm_ADD_A(lable__HotASM_START__Exit),//__HotASM_START__0 asm_PUSH_ACC(),//压入跳入地址__HotASM_START__0低8位 asm_MOV_A_DPH(),// asm_ADDC_A(0), asm_PUSH_ACC(),//压入跳入地址__HotASM_START__0高8位 //lable__HotASM_START__Exit: Interrupt_return()//(连续调用RETI二次) end;
/*--------------------------------------------- HotTask51软件复位函数 void __HotASM_RESET__(void) 入口: 无 Keil DPTR = &__HotASM_RESET__[0] R2R1 = DPTR 出口: 无 结果: 二次RETI后跳入0x0000 特点: 本“函数”可以“动态加载” -----------------------------------------------*/ Procedure (__HotASM_RESET__)//(void) begin//DPTR保存的是汇编数组函数的首地址__HotASM_RESET__ #define lable__HotASM_RESET__Exit ( size_CLR_A() + size_MOV_REG_A() + size_JZ() + size_LJMP() + 2 * size_MOV_A_REG() + 2 * size_ADD_A() + 2 * size_PUSH_REG() + size_RETI() ) asm_CLR_A(), asm_MOV_IE_A(),//关中断 asm_JZ(size_LJMP() - 1),//NOP() asm_LJMP(0xaa00),// asm_MOV_A_DPL(), asm_ADD_A(lable__HotASM_RESET__Exit),//lable__HotASM_RESET__0 asm_PUSH_ACC(),//压入跳入地址lable__HotASM_RESET__0低8位 asm_MOV_A_DPH(),// asm_ADDC_A(0), asm_PUSH_ACC(),//压入跳入地址lable__HotASM_RESET__0高8位 asm_RETI(),//顺序执行下句!!!(调用RETI) //lable__HotASM_RESET__Exit: asm_CLR_A(), asm_PUSH_ACC(),//压入复位地址低8位 asm_PUSH_ACC(),//压入复位地址高8位 Interrupt_return()//跳入复位地址处 end;
/*--------------------------------------------- HotTask51软中断函数 void __HotASM_ISR__(unsigned char isrNum) 入口: R7 D4D3 中断向量组号 D2D1D0 中断向量号 出口: R7 isrNum 结果: 跳入对应的中断地址 isrNum * 8 + 3 -----------------------------------------------*/ Procedure_Arg1 (__HotASM_ISR__, macro_U8_arg1) begin//DPTR保存的是汇编数组函数的首地址__HotASM_ISR__ #define lable__HotASM_ISR__Error (-(size_CPL_C() + size_MOV_A() + size_JNC())) asm_CJNE_R7(0x20, size_CPL_C() +size_MOV_A() - 1),//mov a,R7 //lable__HotASM_ISR__Error: asm_CPL_C(), asm_MOV_A(0xEF),//mov a,0xef// asm_JNC(lable__HotASM_ISR__Error),//非法软中断号>(0~0x1f) asm_RL_A(), asm_RL_A(), asm_RL_A(), asm_ORL_A(0x03), asm_CLR_ACC_2(), asm_PUSH_ACC(),//压入中断地址低8位 asm_CLR_A(), asm_PUSH_ACC(),//压入中断地址高8位 Procedure_return()//跳入对应的中断地址 isrNum * 8 + 3 end;
/*--------------------------------------------- HotTask51系统启动函数(直接操作SP) void __HotASM_STARTex__(void) 入口: 无 Keil DPTR = &__HotASM_STARTex__[0] R2R1 = DPTR 出口: 无 结果: 一次RETI后继续执行 特点: 本“函数”可以“动态加载” -----------------------------------------------*/ Procedure (__HotASM_STARTex__)//(void) begin//DPTR保存的是汇编数组函数的首地址__HotASM_START__ #define lable__HotASM_STARTex__Exit (22 + size_JMP_aDPTR() + size_DW()) asm_CLR_A(), asm_MOV_IE_A(),//关中断 /*------------------------------------------------------------------------ 注意下列方法和__HotASM_START__的最大不同之处和更为凶猛的方法~~~ --------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/ asm_INC_SP(), asm_MOV_R0_SP(),//准备搞破坏 asm_INC_SP(), asm_MOV_A_DPL(), asm_ADD_A(lable__HotASM_STARTex__Exit),//lable__HotASM_RESET__0 asm_MOV_iR0_A(),//装入lable__HotASM_STARTEx__Exit低8位 asm_INC_R0(), asm_MOV_A_DPH(), asm_ADDC_A(0), asm_MOV_iR0_A(),//20//装入lable__HotASM_STARTEx__Exit高8位 /*-----------------------------------------------------------------------*/ asm_MOV_A(lable__HotASM_STARTex__Exit), asm_JMP_aDPTR(), asm_DW(0x55aa), //lable__HotASM_STARTEx__Exit: Interrupt_return()//(调用RETI二次) end;
/*--------------------------------------------- HotTask51汇编数组函数测试 void __HotASM_TEST__(void) 入口: DPTR保存的是汇编数组函数的首地址__HotASM_TEST__ R2R1保存的是汇编数组函数的首地址__HotASM_TEST__ 出口: 结果: -----------------------------------------------*/ Procedure (__HotASM_TEST__) begin//DPTR保存的是汇编数组函数的首地址__HotASM_ISR__ //HotC51指令测试及HotC51宏扩展指令测试 //asm_LJMP(__HotASM_TEST__), asm_MOVC_A_aPC(),//movc a,@a+pc asm_MOVC_A_0PC(),//clr a;movc a,@a+PC asm_MOVC_A_nPC(0),//mov a, #0;movc a,@a+PC//比上条指令多1字节
asm_MOVC_A_aDPTR(),//movc a,@a+dptr asm_MOVC_A_0DPTR(0x1234),//mov dptr,#0x1234;clr a;movc a,@a+dptr asm_MOVC_A_nDPTR(0, 0x1234),//mov dptr,#0x1234;mov a, #0;movc a,@a+dptr //比上条指令多1字节
asm_MOVX_A_DPTR(), //movx a,@dptr asm_MOVX_A_iDPTR(0x1234), //mov dptr,#0x1234;movx a,@dptr
asm_MOVX_DPTR_A(), //movx @dptr,a asm_MOVX_0DPTR(0x1234), //mov dptr,#1234;clr a;movx @dptr,a asm_MOVX_nDPTR(0, 0x1234), //mov dptr,#1234;mov a,#0;movx @dptr,a//比上条指令多1字节
asm_MOVX_A_iRn(0), //movx a,@r0 asm_MOVX_A_iRn(1), //movx a,@r1
asm_MOVX_A_iR0(), //movx a,@r0 asm_MOVX_A_iR1(), //movx a,@r1
asm_MOVX_iRn_A(0), //movx @r0,a asm_MOVX_iRn_A(1), //movx @r1,a
asm_MOVX_iR0_A(), //movx @r1,a asm_MOVX_iR1_A(), //movx @r1,a
asm_MOV_A_Rn(0), //mov a,r0 asm_MOV_A_Rn(1), //mov a,r0 asm_MOV_A_Rn(2), //mov a,r0 asm_MOV_A_Rn(3), //mov a,r0 asm_MOV_A_Rn(4), //mov a,r0 asm_MOV_A_Rn(5), //mov a,r0 asm_MOV_A_Rn(6), //mov a,r0 asm_MOV_A_Rn(7), //mov a,r0
asm_MOV_A_R0(), //mov a,r0 asm_MOV_A_R1(), //mov a,r1 asm_MOV_A_R2(), //mov a,r2 asm_MOV_A_R3(), //mov a,r3 asm_MOV_A_R4(), //mov a,r4 asm_MOV_A_R5(), //mov a,r5 asm_MOV_A_R6(), //mov a,r6 asm_MOV_A_R7(), //mov a,r7
asm_MOV_Rn_A(0), //mov r0,a
asm_MOV_R0_A(), //mov r0,a asm_MOV_R1_A(), //mov r1,a asm_MOV_R2_A(), //mov r2,a asm_MOV_R3_A(), //mov r3,a asm_MOV_R4_A(), //mov r4,a asm_MOV_R5_A(), //mov r5,a asm_MOV_R6_A(), //mov r6,a asm_MOV_R7_A(), //mov r7,a
asm_MOV_Rn(0, 250), //mov r0,#250 asm_MOV_R0(250), //mov r0,#250
//HotC51宏扩展指令测试 asm_MOV_Timer0(0x0123),//mov th0,#0x12;mov tl0,#0x34 asm_MOV_Timer1(0x4567),//mov th1,#0x45;mov tl1,#0x67 asm_MOV_Timer2(0x89ab),//mov th2,#0x89;mov tl2,#0xab asm_MOV_RCAP2(0xcdef), //mov RCAP2H,#0xcd;mov RCAP2L,#0xef; asm_MOV_AB(0x1234), //mov a,#12;mov b,#0x34 asm_MOV_BA(0x1234), //mov b,#12;mov a,#0x34
/* #define lable_loop -(size_SJMP() + size_MOV_iRn()+size_ORL_A_iRn()) #define lable_exit size_ORL_A_REG()+size_JNC()+size_ORL_A_REG() //lable_loop: asm_MOV_iR1(250),//mov @r1,#250 asm_ORL_A_iR1(),//orl a,@r1 asm_SJMP(lable_loop), asm_SJMP(lable_exit), asm_ORL_A_B(),//orl a,b asm_JNC(size_ORL_A_REG()),//jnc exit asm_ORL_A_DPL(),//orl a,dpl //lable_exit: */
#define lable__HotASM_TEST__Exit ( size_JBC_P1_X() + size_CPL_P1_X() + size_CLR_P3_X() + size_SETB_P3_X() + size_NOP() ) asm_JB_P2_5(size_JBC_P1_X() + size_CPL_P1_X() + size_CLR_P3_X() + size_SETB_P3_X() + size_NOP() ), asm_NOP(), asm_JBC_P1_0(size_CPL_P1_X() + size_CLR_P3_X() + size_SETB_P3_X() ),//填入JBC_P1_0()到lable__HotASM_TEST__Exit之间的指令长度 asm_CPL_P1_0(), asm_CLR_WR(), asm_SETB_RD(), //lable__HotASM_TEST__Exit: Procedure_return() end;
code const ptrInterface(IHotAsmCom_Interface, comFunction)//装载COM接口函数指针 begin//开始按顺序装载函数 //装配函数 void STARTnew(); ptrProcedure(__HotASM_STARTnew__),// // (pMacro_Procedure_U8)__HotASM_STARTnew__,// // (void (*)(unsigned char arg1))__HotASM_STARTnew__,// //装配函数 void START(void); ptrProcedure(__HotASM_START__),// // (void (*)(void))__HotASM_START__,// //装配函数 void RESET(void); ptrProcedure(__HotASM_RESET__),// //装配函数 void ISR(unsigned char); ptrProcedure_Arg1(__HotASM_ISR__, unsigned char arg1),// //装配函数 void STARTex(); ptrProcedure(__HotASM_STARTex__),// //装配函数 void TEST(); ptrProcedure(__HotASM_TEST__),// end;//结束装载
相关链接:http://www.**/wangping/ti/blog_vote.php?blme_id=68 |