In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
After dealing with the accuracy results, let's go back to our motor mastery program again. Neither of the two routines given below are applicable procedures. Why? Because there is a large delay in the program, and nothing else can be done during the delay, think of the second program, which can do nothing else for a full 200 seconds, which is relatively impermissible in practice. So how to reform it? Of course, it is still done with the just-in-time suffix, since each rhythm continues to be 2ms, then we just use the timer just-in-time 2ms to refresh the rhythm. The procedures after the reform are as follows:
# include unsigned long beats = 0; / / Total Motor transfer Rhythm void StartMotor (unsigned long angle); void main () {EA = 1; / enable Total TMOD = 0x01; / / set T0 to form 1 TH0 = 0xF8; / / assign initial value 0xF8CD to T0, just-in-time 2ms TL0 = 0xCD; ET0 = 1; / enable T0 infix TR0 = 1; / start T0 StartMotor (360 cycles 2 cycles 180); / / master motor migration transition 2 and a half while (1) } / * the starting function of the stepper motor, the angle that the angle- needs to turn * / void StartMotor (unsigned long angle) {/ / close the infix before the calculation, and then open it after completion, in order to prevent the infix from interrupting the calculation process and form a fault EA = 0; beats = (angle * 4076) / 360; / / the measured value is 4076 beats, migration and transformation circle EA = 1 } / * T0 suffix service function to drive stepper motor torsion * / void InterruptTimer0 () interrupt 1 {unsigned char tmp; / / temporary variable static unsigned char index = 0; / / rhythm input index unsigned char code BeatCode [8] = {/ / IO mastery code corresponding to stepper motor rhythm 0xE, 0xC, 0xD, 0x9, 0xB, 0x3, 0x7, 0x6}; TH0 = 0xF8; / / reload initial value TL0 = 0xCD / / if the number of rhythms is not 0, a driving rhythm if (beats! = 0) {tmp = P1; / / use tmp to temporarily store the values after P1 mouth tmp = tmp & 0xF0; / / use & operation to clear low 4 bits / / use | operation to write rhythm code to the lower 4 bits tmp = tmp | BeatCode [index]; / / return the lower 4 bit rhythm code and the high 4 bit original value back to P1 = tmp; index++; / rhythm input index increment index = index & 0x07 / / with & the operation is completed to 8 return to zero beats--; / / Total rhythms-1} else {/ / if the number of rhythms is 0, the motor is closed with P1 = P1 | 0x0F;}}
The program is still relatively complex. The starting function StartMotor of motor migration transformation only calculates the total rhythm number beats of a demand, then detects this variable in the infix function, performs the rhythm operation when it is not 0, and subtracts it by 1 until it is reduced to 0.
Here, we want to specifically clarify the two operations on EA in the StartMotor function. We can see that the assignment calculation statement to beats is sandwiched between the two lines of EA=0;EA=1;, that is, the assignment calculation statement closes the infix before it is executed, and then reopens the infix after it is completed. In its performance process, the single-chip microcomputer will not echo the infix, that is, the infix function InterruptTimer0 will not be performed, even if the sub-timer overflowed and the infix broke out, it can only wait for EA to be re-set 1 before the ability to echo, the infix function InterruptTimer0 will be fulfilled.
So why are you doing this? Let's think about it: at the beginning of this book, we mentioned that the STC89C52 single-chip microcomputer we use is an 8-bit single-chip microcomputer, this 8-bit concept means that when the single-chip microcomputer operates data, it is mostly stopped by 8 bits, that is, by 1 byte, then the operation of multiple bytes (whether reading or writing) must be stopped repeatedly. And the variable beats in our program is unsigned long, which takes up 4 bytes, so the assignment to it has to be completed at least four times. Let's imagine that after completing the assignment of the first byte, the infix occurs, and the InterruptTimer0 function loses its performance, and this function can stop the operation of subtracting 1 from beats, and the subtraction will be able to borrow, and the borrower will change other bytes, but because other bytes have not yet been assigned to a new value, the problem will occur, and the consequence of minus 1 is not the expected value! Therefore, in order to prevent the occurrence of this problem, we have to temporarily close the infix, and then open the infix after the assignment is completed. If we use char or bit variables, because they are mostly done in a single operation of CPU, even if the suffix is not turned off, it will not go wrong. The analysis of the results is clear, if you abandon it, you have to think about it according to the actual situation, and think about it when you catch up with this kind of achievement.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.