呵呵,用汇编的滑很复杂的。我有程序,不过和这个不是很对是我做的一个项目,你可利用参考下,AD EQU 30HRTR EQU 31HLTR EQU 32HSTR EQU 33HBW EQU 34HBWS EQU 35HSHW EQU 36HSHWS EQU 37HGW EQU 38HGWS EQU 39HWSHR EQU 3AH;WSHR=BWS*100+SHWS*10+GWSsz EQU 3BH;数字与代码对应程序的数字变量xsm EQU 3CH;数字与代码对应程序的代码变量TODH EQU 3DH;计算的10进位数的高位*电机的要求转速高位TODL EQU 3EH;计算的10进位数的低位*电机的要求转速低位TODHT EQU 3FH;测试后电机的实际转速高位TODLT EQU 40H;测试后电机的实际转速低位PCK EQU 41H;pc口当前的状态植TOH EQU 42H;定时器高位数T0L EQU 43H;定时器低位数pink1 EQU 44H;电机转动1/4圈定时器1的奇数次数pink2 EQU 45HVTIMES EQU 46H;速度显示次数T1H EQU 47HT1L EQU 48HTESTK DATA 49H ;高电平脉冲的个数 TTH0 EQU 1AHTTL0 EQU 4BHSUBNOW EQU 4CHORG 0000HLJMP MAINORG 03HAJMP INTR0;中段0,用来计算电机转速ORG 0BHMOV A,PCKANL A,#00000111BMOV PCK,AMOV A,#00000110BCJNE A,PCK,INTT0LFLJMP INTT0L;ORG 1BH;pwm停转子程序AJMP INTT0HORG 0040H;**************************定时器中断子程序****************************;****电机停止程序INTT0H:mov th0,TOHmov tl0,T0LSETB TR0;定时器0开始计数CLR TR1;定时器1禁止计数INC pink1MOV DPTR,#7F02H; b地址MOV A, #00000000B;电机停止运动MOVX @DPTR,Areti;****电动机正转子程序INTT0L:mov th1,T1H mov tl1,T1LSETB TR1;定时器1开始计数CLR TR0;定时器0禁止计数MOV DPTR,#7F02H; b地址MOV A, #11001100B;C口输出片选号灯MOVX @DPTR,Areti;****电动机反转INTT0LF:mov th1,T1H mov tl1,T1LSETB TR1;定时器1开始计数CLR TR0;定时器0禁止计数MOV DPTR,#7F02H; b地址MOV A, #10101100B;C口输出片选号灯MOVX @DPTR,Areti;*************************计算电机转速************************;R2R3R4R5/ R6R7=R4R5余R2R3////(R2R3R4/R7)=(R2)R3R4 余数R7INTR0:MOV R2,#00HMOV R3,#0EHMOV R4,#0A6HMOV R7,pink1MOV pink1,#0MOV A,#10CLR CYSUBB A,R7JNB CY,OUTINT0LCALL NDIV31 MOV TODHT, R3MOV TODLT,R4MOV R6,TODHMOV R7,TODL CLR CYMOV A,R4SUBB A,R7MOV SUBNOW,AJB CY,ADVLCALL SUBVJMP OUTINT0ADV:LCALL ADDVOUTINT0:LCALL JSW;计算各位的数值毫时大大约600个始周期 ;MOV TODLT,TOH ;LCALL JSW;计算各位的数值毫时大大约600个始周期RETI;***********************************************************************************************;***************************************************************************************************;***************************************************************************************************COMP_M:MOV A,#0FDHSUBB A,TOHJNB CY,OUT_PMMMOV TOH,#0FDHMOV T1H,#85OUT_PMM:RET;***************加速子程序**********************ADDV: CLR EA CLR TR1 CLR TR0 MOV R1,SUBNOW MOV R0,#10000000BFRT: MOV A,R0 RL A MOV R0,A MOV A,R1 ANL A,R0 JZ FRT MOV A,TOH ADD A,R0 JC VMAX MOV TOH,A MOV A,T1H SUBB A,R0 MOV T1H,A JMP TXTVMAX: MOV TOH,#0FDH MOV T1H,#85TXT: SETB TR0 SETB TR1 SETB EARET;************减加速子程序*************************SUBV: CLR EA CLR TR1 CLR TR0 MOV R1,SUBNOW MOV R0,#10000000BFRT1: MOV A,R0 RL A MOV R0,A MOV A,R1 ANL A,R0 JZ FRT1 MOV A,TOH SUBB A,R0 JC VMAX1 MOV TOH,A MOV A,T1H ADD A,R0 MOV T1H,A JMP TXT1VMAX1: MOV TOH,#85 MOV T1H,#0FDHTXT1: SETB TR0 SETB TR1 SETB EARET ;*****************************主程序**************************************MAIN:MOV BW,#7DHMOV SHW,#7DHMOV GW,#7DHMOV BWS,#0MOV SHWS,#0MOV GWS,#0MOV SP,#0A0HMOV TOH,#0A1h;******************************************************************MOV T0L,#0h;******************************************************************MOV T1H,#0E1h;*******************************************************************MOV T1L,#37h;*******************************************************************MOV TMOD,#00H;定时器0在模式1下工作 MOV RTR,#00110110BMOV LTR,#00101101BMOV PCK,#00HMOV TODHT,#2MOV TODLT,#25HMOV TODH,#0MOV TODL,#0;LCALL JSTIM;计算总值TODH;TODLMOV pink2,#0MOV pink1,#0SETB EX0SETB IT0START:MOV DPTR,#7F00H; 状态字地址MOV A, #00111111B;设A,B,C口均为输出MOVX @DPTR,ALCALL DISPLAY;显示LCALL KEYSC;扫描键盘;MOV TESTK,#44H;************************************************TEST*************************************************ACALL DISPKEYV ;确定键盘;LCALL JSTIM;计算总值TODH;TODL;LCALL JSW;计算各位的数值毫时大大约600个始周期LCALL JSEHW;计算各个代码******************************JMP START;*************************键盘扫描程序**************************KEYSC:MOV TESTK,#0mov p1,#0FH ;p10-3输出1,作为输入位 mov a ,p1 ANL A,#0FH CJNE A,#0FH,DELAYRETDELAY: ACALL DELAY1 ; 延时去键抖 mov a ,p1 ANL A,#0FH CJNE A,#0FH,HAVERETHAVE: MOV A,#0EFH ;行扫描码NEXT: MOV B,A MOV P1,A MOV A,p1 ANL A,#0FH ;检测列 CJNE A,#0FH,YES MOV A,B RL A CJNE A,#0FEH,NEXT YES: orl a,#0f0h ;高四位置1 CPL A mov r2,#00h MOV R2,A ;存列码 MOV A,B ;取行码, CPL A ORL A,R2 ;列码+行码=键植MOV AD,#00HMOV TESTK,ARET;****************************确定键盘程序******************************DISPKEYV:MOV A,TESTK KEY0:CJNE A,#11H,KEY1 acall WORD0KEY1:CJNE A,#12H,KEY2 acall WORD1KEY2:CJNE A,#14H,KEY3 acall WORD2KEY3:CJNE A,#18H,KEY4 acall WORD3KEY4:CJNE A,#21H,KEY5 acall WORD4KEY5:CJNE A,#22H,KEY6 acall WORD5KEY6:CJNE A,#24H,KEY7 acall WORD6KEY7:CJNE A,#28H,KEY8 acall WORD7KEY8:CJNE A,#41H,KEY9 acall WORD8KEY9:CJNE A,#42H,KEY10 acall WORD9KEY10:CJNE A,#44H,KEY11 acall WORD10KEY11:CJNE A,#48H,KEY12 acall WORD11KEY12:CJNE A,#81H,KEY13 acall WORD12KEY13:CJNE A,#82H,KEY14 acall WORD13KEY14:CJNE A,#84H,KEY15 acall WORD14KEY15:CJNE A,#88H,PASS AJMP WORD15 PASS:RET WORD0:lCALL MOVEMOV A,#0MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV R0,TESTKTSTK0:LCALL KEYSCMOV A,R0CJNE A,TESTK,OUT0JMP TSTK0OUT0:MOV R0,#0RETWORD1:lCALL MOVEMOV A,#1MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV R0,TESTKTSTK1:LCALL KEYSCMOV A,R0CJNE A,TESTK,OUT1JMP TSTK1OUT1:MOV R0,#0RETWORD2:lCALL MOVEMOV A,#2MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV R0,TESTKTSTK2:LCALL KEYSCMOV A,R0CJNE A,TESTK,OUT2JMP TSTK2OUT2:MOV R0,#0ACALL JSEHW;计算各个位的显示代码RETWORD3:lCALL MOVEMOV A,#3MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV R0,TESTKTSTK3:LCALL KEYSCMOV A,R0CJNE A,TESTK,OUT3JMP TSTK3OUT3:MOV R0,#0ACALL JSEHW;计算各个位的显示代码RETWORD4:lCALL MOVEMOV A,#4MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV A,TESTKTSTK4:LCALL KEYSCCJNE A,TESTK,OUT4JMP TSTK4OUT4:ACALL JSEHW;计算各个位的显示代码RETWORD5:lCALL MOVEMOV A,#5MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV A,TESTKTSTK5:LCALL KEYSCCJNE A,TESTK,OUT5JMP TSTK5OUT5:ACALL JSEHW;计算各个位的显示代码RETWORD6:lCALL MOVEMOV A,#6MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV A,TESTKTSTK6:LCALL KEYSCCJNE A,TESTK,OUT6JMP TSTK6OUT6:ACALL JSEHW;计算各个位的显示代码RETWORD7:lCALL MOVEMOV A,#7MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV A,TESTKTSTK7:LCALL KEYSCCJNE A,TESTK,OUT7JMP TSTK7OUT7:ACALL JSEHW;计算各个位的显示代码RETWORD8:lCALL MOVEMOV A,#8MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV A,TESTKTSTK8:LCALL KEYSCCJNE A,TESTK,OUT8JMP TSTK8OUT8:ACALL JSEHW;计算各个位的显示代码RETWORD9:lCALL MOVEMOV A,#9MOV GWS,ALCALL JSTIM;计算总值TODH;TODLMOV A,TESTKTSTK9:LCALL KEYSCCJNE A,TESTK,OUT9JMP TSTK9OUT9:ACALL JSEHW;计算各个位的显示代码RETWORD10:CLR EACLR ET0CLR TR0mov th0,TOHmov tl0,T0LMOV PCK,#00000110BSETB EA;打开所有中断SETB ET0;定时器允许中断SETB TR0;定时器0开始计数CLR TR1;定时器1禁止计数SETB ET1;定时器1允许中断RETWORD11:CLR EACLR ET0CLR TR0mov th0,TOHmov tl0,T0LMOV PCK,#00000101BSETB EA;打开所有中断SETB ET0;定时器允许中断SETB TR0;定时器0开始计数CLR TR1;定时器1禁止计数SETB ET1;定时器1允许中断RETWORD12: LCALL ADDV MOV TODLT,TOH LCALL JSW;计算各位的数值毫时大大约600个始周期 MOV A,TESTK TSTK12: LCALL KEYSC CJNE A,TESTK,OUT12 JMP TSTK12 OUT12:RETWORD13: LCALL SUBV MOV TODLT,TOH LCALL JSW;计算各位的数值毫时大大约600个始周期 MOV A,TESTK TSTK11: LCALL KEYSC CJNE A,TESTK,OUT11 JMP TSTK11 OUT11:RETWORD14: CLR ET0;使能定时器0中断 CLR ET1;使能定时器1中断 CLR EA;使能总中断 CLR TR1;关闭T1计时 CLR TR0;关闭T0计时 MOV PCK,#00H MOV BW,#7DH MOV SHW,#7DH MOV GW,#77H RETWORD15:JB EA,MID15 MOV BWS,#0 MOV SHWS,#0 MOV GWS,#0 JMP OUT15 MID15: CLR EA MOV A,TESTK TSTK15: LCALL KEYSC CJNE A,TESTK,OUT15 JMP TSTK15 MOV TODLT,TOH LCALL JSW;计算各位的数值毫时大大约600个始周期 OUT15: SETB EARET;***********************计算各个代码******************************JSEHW:MOV SZ,BWSACALL jsMOV BW,xsmMOV SZ,SHWSACALL jsMOV SHW,xsmMOV SZ,GWSACALL jsMOV GW,xsmRETjs:mov a,szjs0:cjne a,#0,js1mov xsm,#7dhjs1:cjne a,#1,js2mov xsm,#14hjs2:cjne a,#2,js3mov xsm,#6ehjs3:cjne a,#3,js4mov xsm,#3ehjs4:cjne a,#4,js5mov xsm,#17hjs5:cjne a,#5,js6mov xsm,#3bhjs6:cjne a,#6,js7mov xsm,#7bhjs7:cjne a,#7,js8mov xsm,#00011100Bjs8:cjne a,#8,js9mov xsm,#7fhjs9:cjne a,#9,js10mov xsm,#3fhjs10:ret;***************************计算各位的数值毫时大大约600个始周期**************************************JSW:;(R2R3R4/R7)=(R2)R3R4 余数R7MOV R2,#0MOV R3,TODHTMOV R4, TODLTMOV R7,#100LCALL NDIV31MOV BWS,R4MOV A,R7;MOV R4,AMOV R3,#0MOV R2,#0MOV R7,#10LCALL NDIV31MOV SHWS,R4MOV GWS,R7RET;***************************计算十进制结果****************************JSTIM:MOV TODL,#0MOV TODH,#0MOV A,GWSMOV B,#1ACALL JSHLMOV A,SHWSMOV B,#10ACALL JSHLMOV A,BWSMOV B,#100ACALL JSHLRETJSHW:JB OV,JSGWCLR OVRETJSGW:INC TODH;TEST DATERETJSHL:MUL ABMOV R1,BADD A,TODLMOV TODL,AMOV A,BADDC A,TODHMOV TODH,AACALL JSHWRET;*****************************单字节的除法*********************;****************************(R2R3R4/R7)=(R2)R3R4 余数R7NDIV31 :MOV A,R2 MOV B,R7 DIV AB MOV R2,B MOV B,#10HNDV311 :CLR C MOV A,R4 RLC A MOV R4,A MOV A,R3 RLC A MOV R3,A MOV A,R2 RLC A MOV R2,A MOV F0,C CLR C SUBB A,R7 JB F0,NDV312 JC NDV313NDV312 :MOV R2,A INC R4NDV313 :DJNZ B,NDV311 CLR OV JZ NDV314 SETB OVNDV314 :XCH A,R2 MOV R7,A RET;*******************双字节减法***(R3R4-R6R7)=(R3R4)*******NSUB :MOV A,R4 CLR C SUBB A,R7 MOV R4,A MOV A,R3 SUBB A,R6 MOV R3,A RETDELAY1: MOV R5,#10D1: MOV R6,#250 DJNZ R6, $ DJNZ R5,D1 RETDELAY_BS: MOV R5,#5D2: MOV R6,#99D3: MOV R7,#99 DJNZ R7, $ DJNZ R6,D3 DJNZ R5,D2 RET;*****************************显示器显示子程序***********************************DISPLAY: MOV DPTR,#7F01H; MOV A, BW; MOVX @DPTR,A MOV DPTR,#7F03H; c地址 MOV A, #00011000B;C口输出片选号灯 MOV R0,PCK;pck=******** ORL A,R0;a=***11*** MOV R0,#00011111B;a=00011*** ANL A,R0 MOVX @DPTR,A ACALL D_40ms MOV DPTR,#7F01H; MOV A, SHW; MOVX @DPTR,A MOV DPTR,#7F03H; c地址 MOV A,#00101000B ORL A,R0 MOV R0,#00101111B ANL A,R0 MOVX @DPTR,A ACALL D_40ms MOV DPTR,#7F01H; MOV A, GW; MOVX @DPTR,A MOV DPTR,#7F03
2023-07-20 00:27:522