5 1 single chip microcomputer, how to realize the cyclic positive and negative rotation of stepping motor
Readers can make some modifications, such as I use jump instructions, and readers can change them to call instructions when entering the acceleration and deceleration loop. The motor speed can also be modified to have no lower limit.
Moreover, judging the process of pressing the key can also have its own method, and my judgment of pressing and releasing may be more troublesome.
What I set in the data table is that each pulse turns to 9. You can also modify your data table according to your actual needs.
For this program, I refer to P25 of Classic Examples of Design and Simulation of Single Chip Microcomputer Practical System (Editor: Zhou Jingrun Liu Xiaoxia). Interested readers can borrow this book from the library.
ORG 0000H
LJMP manager
ORG 0030H
Main business: MOV 30H, # 05H acceleration and deceleration speed control, control the number of delay cycles (initial value).
MOV DPTR,# tab 1; Table lookup method for assigning values to P2
MOV R0, # 03HP2 initial value
MOV R4, # 00H lookup table pointer value
MOV·P2,R0; assess
Wait: MOV P0, # 0FFHP0 needs to output a 1 before it can be input.
JNB P0.0, Song 3; Check whether the key is pressed, and Song indicates whether the key is released, otherwise the program will be confused.
JNB P0. 1, Song 4; Song in the program means the above.
SJMP waits; If you don't press this button, it won't start.
Song 3:JB p 0.0, Zheng; Input forward rotation
SJMP song 3;
Song 4:JB p 0. 1, Fan; Input inversion
SJMP song 4;
Zheng: 01h; Start looking up the table
Loop 1:JB p 0. 1, polysaccharide1; Check whether it is reversed. If the reverse key is not pressed, it works normally.
Song 1:JNB p 0. 1, Fan; Press reverse gear to release and enter reverse gear.
SJMP song1;
Yunxing 1:MOV A, R4; table look-at
MOVC A,@ A+DPTR;
MOV·P2;
Call delay; Enter the delay program to control the motor speed.
JB P0.3,cool 1; Detect whether the deceleration button is pressed, and if not, detect whether the acceleration button is pressed.
Song 5:JNB p 0.3, down1; Press to enter the delay program to modify the number of cycles.
SJMP song 5;
cool 1:JB p 0.2,normal 1; Detect whether the acceleration button is pressed, otherwise it will run normally.
Song 6:JNB p 0.2, up1; Press the acceleration key to enter the delay program and modify the number of cycles.
SJMP song 6;
nomal 1:INC R4; Check the next data
CJNE R4,#09H,loop 1; After checking the data in the table, reset the value of R4. If it is not selected, do not reset R4.
Zheng; Cyclic forward rotation
Vermicelli: R4, # 07H Reverse R4 initial value
Loop 2:JB p 0.0, Yunxing 2; Detect whether the forward key is pressed, and if not, run the reverse program normally.
Song 2:p 0.0, Zheng; Press and release the forward rotation button to enter the forward rotation program.
SJMP song 2;
Yunxing 2:MOV A, R4; Start looking up the table
MOVC A,@ A+DPTR;
MOV·P2;
Call delay; Enter the delay program to control the motor speed.
JB P0.3, COOL2 detects whether the deceleration button is pressed, and if not, detects whether the acceleration button is pressed.
Song 7:JNB p 0.3, down 2; Press to enter the delay program to modify the number of cycles.
SJMP song 7;
Cool 2:JB p 0.2, normal 2; Detect whether the acceleration button is pressed, otherwise it will run normally.
Song 8:JNB p 0.2, UP2 press to enter the delay program and modify the number of cycles.
SJMP song 8;
Normal school 2: R4 dec; Circular lookup table
CJNE R4, #00H, LOOP2 After checking again, reset and recheck the data.
SJMP fan; Reverse cycle
Delay: MOV R6, # 05H
DD 1: MOV R5,# 080H
DD2:MOV R7,# 05H
DD3:DJNZ R7,DD3;
DJNZ R5
DJNZ R6,DD 1; Fixed delay
DJNZ R 1, delay; The motor speed is controlled by changing the cycle time of the delay program.
Speed: mov r1.30h; Enter the speed value of each cycle into R 1.
SJMP is back;
down 1:INC 30H; The speed is reduced because the cycle number is+1.
CJNE R 1,# 10H,normal 1; The lower limit of speed limit is 10. If it is less than 10, you can continue to slow down.
MOV 30H,# 10H; You can't slow down when you reach the lower limit. It's always 10.
SJMP normal school1; Return to the forward rotation cycle
Up1:1February 30th; Speed plus, because the cycle number is-1
CJNE R 1,#0 1H,normal 1; The upper speed limit is 1. If it is less than 1, you can continue to accelerate.
MOV 30H,# 0 1H; If the speed reaches the upper limit, it cannot be accelerated, and it will always be 1.
SJMP normal school1; Return to the forward rotation cycle
down 2:INC 30H; The speed is reduced because the cycle number is+1.
CJNE R 1, # 10H, normal 2; The lower limit of speed limit is 10. If it is less than 10, you can continue to slow down.
MOV 30H,# 10H; You can't slow down when you reach the lower limit. It's always 10.
SJMP· Norma 2; Go back to the opposite cycle
Up2:1February 30th h; Speed plus, because the cycle number is-1
CJNE R 1, #0 1H, normal 2; The upper speed limit is 1. If it is less than 1, you can continue to accelerate.
MOV 30H,# 0 1H; If the speed reaches the upper limit, it cannot be accelerated, and it will always be 1.
SJMP· Norma 2; Go back to the opposite cycle
Back: RET delays subroutine return.
tab 1:DB 00H,02H,06H,04H
DB 0CH, 08H, 09H, 0 1H, 03H control the numerical table of each power-on sequence.
End; end