Help write a single chip microcomputer counting program, how to use the 51 single chip microcomputer

Updated on technology 2024-05-09
15 answers
  1. Anonymous users2024-02-10

    Pick up the first sensing; Take the second sensor. As for the LED display program, it is very simple, just write a subprogram. That's it for the basic program, but there are other possibilities to add it yourself according to the actual situation, and the program must pass through two points in turn, otherwise the program will be in an endless loop.

    You can write a timer yourself to jump out.

    main()

    int i=0;

    int cnt;

    while(1)

    p0=0xff;

    i=p0;i=i&0x03;

    if(i==1)

    while(1)

    i=p0&0x02;

    if(i==2)

    cnt++;

    leddisp(cnt);

    break;

    if(i==2)

    while(1)

    i=p0&0x01;

    if(i==1)

    cnt--;

    leddisp(cnt);

    break;

  2. Anonymous users2024-02-09

    What do you mean 1 means come in plus one 2 means leave minus one r1 stands for 1 sensor, when r1 comes to h, it means that r2 stands for 2 sensor, r2 comes when it comes to h, it means that it leaves the first definition of the digital tube character led=

    main()

    int i=0;

    while(1)

    if(r1) r1 first.

    if(r2)

    i++if(r2) r2 first.

    if(r1)

    i++p0=led[i];

  3. Anonymous users2024-02-08

    Upstairs is wrong, lz means that when people enter and exit, two sensors will send signals, that is, 1 is outside the door and 2 is inside the door.

    In: Shilling 1 sends a signal, then No. 2 sends a signal, and the person enters.

    Out: Shilling 2 sends a signal, then 1 sends a signal, and the person is out.

  4. Anonymous users2024-02-07

    This is what we have done before, that is, the procedure of counting the floor of the elevator, which is relatively simple.

  5. Anonymous users2024-02-06

    51 single-chip microcomputer is a basic entry single-chip microcomputer, or the most widely used.

    51 Timing of MCU The concept of counters.

    In the single-chip microcomputer, the relationship between pulse counting and time is very close, every time a pulse is entered, the value of the counter will automatically accumulate 1, as long as the time interval between the adjacent two counting pulses is equal, the counting value represents the passage of time, therefore, the timer and the counter in the single-chip microcomputer are actually the same physical electronic components, but the counter records what happens outside the single-chip microcomputer (receiving the external pulse), and the timer is a very stable counter provided by the single-chip microcomputer itself, This stable counter is the crystal oscillator component connected to the microcontroller; The crystal oscillator of MCS-51 microcontroller is provided to the microcomputer after 12 frequency divisions. The frequency of the crystal oscillator is very accurate, so the time interval between the counting pulses of the microcontroller is also very accurate.

    51. The timing of the single-chip microcomputer The working principle of the counter.

    There are two counting pulses in the plus 1 counter input, one is sent by the clock oscillator output pulse of the system through 12 divisions; One is an external pulse source with a T0 or T1 pin input.

    When used as a timer, the timer counts the number of pulses after 12 divisions are output by the on-chip oscillator of the 8051 single-chip microcontroller, that is, the register value of timer t0 t1 is automatically accumulated by 1 for each machine cycle until it overflows, and the cycle counting from 0 continues after overflow; So, the resolution of the timer is 1 12 of the oscillation frequency of the clock;

    When used as a counter, the external pulse signal is counted via pin t0 ( or t1 (, and the counter value is automatically increased by 1 when the input external pulse signal undergoes a negative jump from 1 to 0, and since it takes 2 machine cycles to detect a falling edge from 1 to 0, the level to be sampled is required to be maintained for at least one machine cycle. When the crystal oscillator frequency is 12MHz, the maximum counting frequency does not exceed 1 2MHz, that is, the period of the counting pulse should be greater than 2 microseconds. The highest frequency of the counter is generally 1 24 of the clock oscillation frequency;

    It can be seen that regardless of whether the timer or the counter works, the timers T0 and T1 do not occupy the time of the CPU, unless the timer counters T0 and T1 overflow, which may cause the CPU to interrupt and execute the interrupt handler instead. Therefore, the timer counter is a high-efficiency and flexible component in the microcontroller.

  6. Anonymous users2024-02-05

    The counters t0 and t1 of the 51 single-chip microcomputer can be used, for example, the external counting pulse input of the counter 0 t0 is used to count, and when the number of 100 pulses is counted, the interrupt is triggered. Enter the Count Service Interruption program.

  7. Anonymous users2024-02-04

    He's just a unit, but it's just an address.

    To give you a popular example, let's say you are the only network manager of an Internet café, and your task is to be responsible for the inspection of the 600 computer in the Internet café.

    When you go to work, you check from the No. 1 computer, repair if there is a problem, check No. 2 if there is no problem, and then No. 3...

    When checking the No. 8 machine, the No. 8 owner tells you that there is a problem with the No. 19 machine, at this time, after you leave the No. 8 machine, instead of going to the No. 9, but to the 19th, after the No. 19 machine is processed, the No. 19 owner tells you that there is a problem with the No. 113 machine, at this time, you go to the No. 113 machine, after dealing with the No. 113 machine, the No. 113 owner did not give you the information of other owners, then, you return to the No. 9 machine to deal with it, then the No. 10 machine, then the 11th...

    Although this example is not 100% in line with the working process of the microcontroller, it is almost the same.

    The "you" in this example is equivalent to a PC program counter, you are a person, and then you have to deal with the problem of 600 machines, so all you need is the number of 600 machines, jump according to the number, and it doesn't mean that you have to grow as big as 600 machines.

    In the same way, the PC register is a 16-bit unit, because it is 16 bits, so the number that can be held is 0---65535, a total of 65536 digits. So, I made the program space into 65536 units, and each unit was numbered, and I just needed to number the PC, and I didn't need the PC to grow that big.

  8. Anonymous users2024-02-03

    When a jump occurs, the internal logic circuit forces the jump address to be written to the PC

    There are a lot of program instructions that affect PC jumping.

    But the structure is similar.

  9. Anonymous users2024-02-02

    The method on the first floor is not feasible for general counters, because the counters have overflowed by the time of interruption.

    There are two ways to achieve this outcome that the landlord wants:

    1. Gate vacancy, that is, Gate in tmod, if this bit is 1, that is, the timer is controlled by the external interrupt in addition to its own TRX, if the external interrupt is low, the timer can not run.

    2. Use a timer with a capture function. A microcontroller with a T2 timer such as the AT89S52 can do this, that is, when an external signal causes an interrupt, T2 can stop the timer and read out the counting value.

    Comparing the two methods, the first one can run on a general microcontroller, but it wastes an external interrupt resource. The second one is more convenient and resource-saving, that is, the single-chip microcomputer should be slightly better.

    PS: There are many microcontrollers with capture function.

  10. Anonymous users2024-02-01

    Microcontroller counting simply generates an interrupt for each incoming signal.

    In fact, we still need to manually accumulate registers in this interrupt program.

    So the registers are specified by ourselves.

  11. Anonymous users2024-01-31

    With 51 single-chip microcomputer 16-bit timing.

    Counter 1 (t1) is commonly explained:

    The count is T1 is a basin that can hold 65536 (at the sixteenth digit) dripping water, and the water is dripped into the basin drop by drop under the faucet. If the basin is empty, the water overflows when the 65536 drops are finished, and the basin is full when one more drop is made. That's when the outage happens.

    If the basin is already filled with 65,500 drops of water (i.e. the initial value), then only 36 drops of water are needed before it overflows.

    Each drop of water is a pulse. The velocity of the water droplet at the timing time is the machine cycle, which is equal to 12 oscillation periods (the oscillation frequency of the crystal oscillator divided by 12), which directly affects the overflow time.

  12. Anonymous users2024-01-30

    How to master the microcontroller timer counter program, I will not write.

    It's normal, it's hard to get started.

    For the sake of understanding, I will illustrate it in the form of an analogy.

    1. Why is it called a timer counter? This is because it is possible to count both the internal clock (timer) and the external pulse (counter).

    2. For example, if you have a bucket (equivalent to a timer counter), this bucket has a certain capacity (the timer counter uses two bytes to time count), now take a bowl from the pool and fill the bucket with water (a bowl of water is equivalent to a timer counting pulse), what will happen if the water is full? Spillover (equivalent to timer counter overflow). Usually we take advantage of this overflow feature (there are exceptions) because it will notify you (with overflow flags).

    The microcontroller timer counter is a plus count, the maximum number of two-byte count registers is 65535, and one more counting unit will return to zero, and at the same time set the overflow flag (turning on the interrupt will also cause an interrupt).

    4. Because it is a plus count, the count value you expect does not necessarily start from zero, so it must be "at the bottom" (assign the initial value).

    Straighten it out and digest it to see if you understand.

    Writing a microcontroller timer counter program is to set registers related to the microcontroller timer counter, and it is easy to understand the above.

  13. Anonymous users2024-01-29

    When the counter counts, it counts from the low to the high.

    That is, the trembling tomb is to count the full tl0 first, enough for 256, and then carry 1 to th0.

    The 1 in th0 represents 256, so the total number of counters is th0tl0.

    The value of the counter cannot be read out at one time, but can only be read as th0 and tl0 respectively.

    When one of them is read out, the other may be catching up with the carry, so the two values read out are wrong.

    Only when you read two times, and the two times are equal, what is read is the correct current count.

    while(1)

    Endless loop. th1

    th0;Read it out for the first time.

    tltl0;

    Read out the other.

    th2th0;

    Re-read the first one.

    if(th1

    th2)break;

    If it is equal twice, it jumps out of the loop.

  14. Anonymous users2024-01-28

    First of all, a digression: Lao Guo's book ideas are still okay, the program really doesn't dare to compliment, and it's a bit goosebumpy to see the two classic variables of dula and wela.

    1,0-255 is 256 numbers, the timer counts from 0 to 255, a total of 256 numbers, no 256,256 is 0, which is the point in time when the overflow interrupts (for the 8-bit timer or th);

    2, in fact, there is no if(th0==th0) in the above program, this is your own understanding, Lao Guo's hail is like the original program.

    while(1)

    th1=th0;

    th2=th0;

    tl=tl0;

    if(th1==th2)

    break;

    val=th1*256+tl;

    return

    val;Although th0 is assigned to th1 and th2 respectively, and then these two variables are judged (remember that this is a variable, relatively speaking, you don't change it, its value is dead; And th0 is the register of the timer, as long as the timer is running, it is always the source configuration is changing) is equal, but it is not equivalent to if(th0==th0) as you understand it, when th1=th0; th2=th0;In the middle of these two sentences, tl0 is a number (assuming that your monolithic seller does not divide the timer), that is, although th1 and th2 are also reading th0 and the same register, the values read may be different, although this chance is very small, that is, when tl0=255 jumps to 0. Your program is only partially posted, I don't understand what it's used for, but Lao Guo's program seems to be to exclude a good point in time. I don't understand the intent, but you know what the program is for, and you can think for yourself.

    3,The third problem is the conceptual problem,th0 is the high position of the timer,tl0 goes to 256 numbers before it goes into 1,th0 plus 1 means that the timer goes 256 numbers。 The whole expression val means that the calculation timer has gone a few since 0.,As for what this is used for.,I don't know.,What is its initialization?,There's no one in the program above.,Think for yourself.。

  15. Anonymous users2024-01-27

    timez[0]-timez[2], is the time difference between the three drops.

    That is, the time it takes to drop two drops. Units, presumably ms ?

    2400 (timez[0]-timez[2]), which is the time it takes to drop 4800 drops.

Related questions
5 answers2024-05-09

If you really want to learn, you don't need to buy a development board. Find a minimal system board, then learn something, buy components and build small circuits by yourself. Run the electronic market by yourself, build the circuit by yourself, in order to know the problem, in order to learn something, buy a development board, according to the circuit on the manual, and then put the program into it, and then the program basically understands, this is not called learning... >>>More

16 answers2024-05-09

Isn't this thing just a digital tube displaying 16 digits? Prompt you 16 times to get there, let go after you think to press the stop button. If so, the procedure is available for reference: >>>More

9 answers2024-05-09

16 and 7 are the number of bytes between the PC and the data ** at the time of the lookup command. >>>More

10 answers2024-05-09

It should be that the bias resistor selection is not suitable.

4 answers2024-05-09

You use a P1 port to control the dynamic scanning of 8 digital tubes, and the dynamic scanning display of digital tubes needs to be blanked. >>>More