|
发表于 2004-11-24 21:22:06
|
显示全部楼层
[原创]请高手多多指点哦
我是一个单片机的初学者,这是我编写的一个程序,主要用来控制直流电动机的正转,反转以及加速,现在没发试验,不知道是否合理,望高手指点。
ORG 0000H
AJMP MAIN
ORG 30H
MAIN:
MOV P1, #0FFH
MOV SP,#5FH
LOOP:
ACALL BUTTON
JNB F0, LOOP;如果无键按下继续
ACALL DBUTTON ;否则调用按钮处理程序
AJMP LOOP
DELAY:
MOV R7, #100
D1: MOV R6,#100
DJNZ R6,$
DJNZ R7,D1
RET; 延时子程序
BDUTTON:
MOV A,B
JB ACC.2, BUTTON1;分析按下的按钮,某位被按下,则该位为1
JB ACC.3, BUTTON2
JB ACC.4, BUTTON3
JB ACC.5, BUTTON4
RET
BUTTON:
CLR F0
ORL P1,#00111100B
MOV A,P1
ORL A,#11000011B
CPL A
JZ K_RET
ACALL DELAY
ORL P1,#00111100B
MOV A,P1
ORL A,#11000011B
CPL A
JZ K_RET
MOV B,A
SETB F0
RET
K_RET:
ORL P1,#00111100B
MOV A,B
ORL A,#11000011B
CPL A
JZ K_RET1
AJMP K_RET
K_RET1:
RET
RET
BOTTON1:
MOV DPTR,#9000H;假设DAC0832的输入寄存器的地址为9000H
MOV A,#80H
MOVX @DPTR,A
ACALL DELAY1
MOV A,#0FFH
MOVX @DPTR,A
ACALL DELAY2
AJMP BUTTON1
RET
BOTTON2:
MOV DPTR,#9000H;假设DAC0832的输入寄存器的地址为9000H
MOV A,#80H
MOVX @DPTR,A
ACALL DELAY3
MOV A,#0FFH
MOVX @DPTR,A
ACALL DELAY4
AJMP BUTTON2
RET
BOTTON3:
MOV DPTR,#9000H;假设DAC0832的输入寄存器的地址为9000H
MOV A,#80H
MOVX @DPTR,A
ACALL DELAY3
MOV A,#00H;电动机反转
MOVX @DPTR,A
ACALL DELAY4
AJMP BUTTON3
RET
DUTTON4:
RET
RET
DELAY1:
MOV R7,#10
D1: MOV R6,#250
D2: DJNZ R6,D2
DJNZ R7,D1
RET
DELAY2:
MOV R7,#20
D1: MOV R6,#250
D2: DJNZ R6,D2
DJNZ R7,D1
RET
DELAY3:
MOV R7,#30
D1: MOV R6,#250
D2: DJNZ R6,D2
DJNZ R7,D1
RET
DELAY4:
MOV R7,#40
D1: MOV R6,#250
D2: DJNZ R6,D2
DJNZ R7,D1
RET
END
|
|