FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    19 lesson: single-chip timer, interrupted test

     

    When we are learning a single-chip machine, our first routine is the flashing of the lamp. It is done with the delay program. Now I think so, don't be very appropriate, why? Our main program has a flashing of the lamp, you can't do anything else, can the single-chip microcontroller can only work? Of course, we can use the timer to implement the flashing function of the lamp. Example 1: Query method ORG 0000H AJMP START ORG 30H Start: MOV P1, # 0ffh; MOV TMOD, # 00000001B; Timed / Counter 0 works in mode 1 Mov TH0, # 15h MOV TL0, # 0a0h; ie 5536 Setb TR0; Timed / Counter 0 starts running LOOP: JBC TF0, Next; If TF0 is equal to 1, then clear TF0 and turn NEXT Ajmp loop; otherwise running to LOOP Next: CPL P1.0 Mov TH0, # 15h MOV TL0, # 9FH; Reset Timer / Counter Ajmp loop End ajmp loop End Type the program, what did you see? The lamp is flashing, which is done with timer, no longer the loop of the main program. Simply analyze the program, why use JBC? TF0 is the overflow marker of timing / counter 0, and when the timer generates overflow, the bit is changed by 0, so queries whether the bit can be known when it is. After this bit is 1, you need to use the software to clear the marking bit, so that the next timing is between 0 changing 1, so it uses JBC instructions, which is the judgment 1 transfer, and will Clear 0. The above program is able to achieve the flashing, but the main program can't make anything else, or do it! No, no, we can insert some instructions between loops: ... and the AJMP LOOP instructions, as long as the time to perform these instructions is less than the timing. Then we can use some instructions to replace DJNZ when using software delay programs? Yes, but then ask you to accurately calculate the time of the instruction used, then subtract the corresponding number of corresponding DJNZ cycles, it is very inconvenient, and now only requires the instructions used less than the timing, obviously low. Of course, this method is still not good, so we often use the following methods to achieve. Program 2: Implementation with interrupt ORG 0000h, AJMP START ORG 000BH; Interrupt vector address of Timer 0 AJMP Time0; Jump to the real timer program ORG 30H Start: MOV P1, # 0ffh; MOV TMOD, # 00000001B; Timed / Counter 0 works in mode 1 Mov TH0, # 15h MOV TL0, # 0a0h; ie 5536 Setb EA; open total interrupt allowed Setb ET0; Opening Time / Counter 0 Allow Setb TR0; Timed / Counter 0 starts running LOOP: AJMP loop; Really, you can write any program here Time0:; Interrupt handler for timer 0 PUSH ACC Push PSW; push PSW and ACC into stack protection CPL P1.0 Mov TH0, # 15h MOV TL0, # 0a0h; reset timing constant POP PSW POP ACC Reti End In the above routine, the timing time is between, the TF0 is changed from 0, which will cause the interrupt, the CPU will automatically turn to 000B to find the program and execute, because there is only 8 bytes of space to the timer interrupt, obviously insufficient To write all the interrupt handles, a jump instruction is arranged at 000B, and go to the actual processing interrupt, so that the interrupt program can be written in any place, and can write any length. After entering the timed interrupt, first save the current state, only the programs are demonstrated to save ACC and PSW, and the values ​​that may be changed can be pushed into the stack as needed in the actual operation (this is not actually You need to save any value, here only make a presentation). After the two microcontroller programs above, we found that the lights flicker were very fast, and they couldn't find out, but they only visually felt a little shake, why? We can calculate the number of preset in the timer is 5536, so 60,000 pulses per meter is time time, how much is this 60,000 pulse? Our crystal oscillator is 12m, so it is 60000 microseconds, that is, 60 milliseconds, so the speed is very fast. What should I do if I want to implement a 1S timing? At the end of this crystal oscillator, the longest timing is 65.536 milliseconds! A routine is given above. ORG 0000H AJMP START ORG 000BH; Interrupt vector address of Timer 0 AJMP Time0; Jump to the real timer program ORG 30H Start: MOV P1, # 0ffh; MOV 30H, # 00H; Software Counter Pred Eqing 0 MOV TMOD, # 00000001B; Timed / Counter 0 works in mode 1 Mov TH0, # 3ch MOV TL0, # 0b0h; ie 15536 Setb EA; open total interrupt allowed Setb ET0; Opening Time / Counter 0 Allow Setb TR0; Timed / Counter 0 starts running LOOP: AJMP loop; Really, you can write any program here Time0:; Interrupt handler for timer 0 PUSH ACC Push PSW; push PSW and ACC into stack protection INC 30H Mov a, 30h CJNE A, # 20, T_RET; Is the value of the 30H unit to 20? T_L1: CPL P1.0; arrived, reflect P10 MOV 30H, # 0; Qing Software Counter T_ret: Mov TH0, # 15h MOV TL0, # 9fh; reset timing constant POP PSW POP ACC Reti End First analyze your own, see how it is achieved? Here, the concept of the software counter is used. The idea is such that the timer / counter 0 is used to do a 50 millisecond timer, and the timing is not immediately reflecting the P10 immediately, but adds the value in the software counter 1, If the software counter is 20, take the reverse P10 and clear the value in the software counter, otherwise it will be returned directly, so that it has become 20 timing interrupts to take anti-one P10, so the timing is extended to 20 * 50 is 1000 milliseconds. Read more

     

     

     

     

    List all Question

    Nickname

    Email

    Questions

    Our other product:

    Professional FM Radio Station Equipment Package

     



     

    Hotel IPTV Solution

     


      Enter email  to get a surprise

      fmuser.org

      es.fmuser.org
      it.fmuser.org
      fr.fmuser.org
      de.fmuser.org
      af.fmuser.org ->Afrikaans
      sq.fmuser.org ->Albanian
      ar.fmuser.org ->Arabic
      hy.fmuser.org ->Armenian
      az.fmuser.org ->Azerbaijani
      eu.fmuser.org ->Basque
      be.fmuser.org ->Belarusian
      bg.fmuser.org ->Bulgarian
      ca.fmuser.org ->Catalan
      zh-CN.fmuser.org ->Chinese (Simplified)
      zh-TW.fmuser.org ->Chinese (Traditional)
      hr.fmuser.org ->Croatian
      cs.fmuser.org ->Czech
      da.fmuser.org ->Danish
      nl.fmuser.org ->Dutch
      et.fmuser.org ->Estonian
      tl.fmuser.org ->Filipino
      fi.fmuser.org ->Finnish
      fr.fmuser.org ->French
      gl.fmuser.org ->Galician
      ka.fmuser.org ->Georgian
      de.fmuser.org ->German
      el.fmuser.org ->Greek
      ht.fmuser.org ->Haitian Creole
      iw.fmuser.org ->Hebrew
      hi.fmuser.org ->Hindi
      hu.fmuser.org ->Hungarian
      is.fmuser.org ->Icelandic
      id.fmuser.org ->Indonesian
      ga.fmuser.org ->Irish
      it.fmuser.org ->Italian
      ja.fmuser.org ->Japanese
      ko.fmuser.org ->Korean
      lv.fmuser.org ->Latvian
      lt.fmuser.org ->Lithuanian
      mk.fmuser.org ->Macedonian
      ms.fmuser.org ->Malay
      mt.fmuser.org ->Maltese
      no.fmuser.org ->Norwegian
      fa.fmuser.org ->Persian
      pl.fmuser.org ->Polish
      pt.fmuser.org ->Portuguese
      ro.fmuser.org ->Romanian
      ru.fmuser.org ->Russian
      sr.fmuser.org ->Serbian
      sk.fmuser.org ->Slovak
      sl.fmuser.org ->Slovenian
      es.fmuser.org ->Spanish
      sw.fmuser.org ->Swahili
      sv.fmuser.org ->Swedish
      th.fmuser.org ->Thai
      tr.fmuser.org ->Turkish
      uk.fmuser.org ->Ukrainian
      ur.fmuser.org ->Urdu
      vi.fmuser.org ->Vietnamese
      cy.fmuser.org ->Welsh
      yi.fmuser.org ->Yiddish

       
  •  

    FMUSER Wirless Transmit Video And Audio More Easier !

  • Contact

    Address:
    No.305 Room HuiLan Building No.273 Huanpu Road Guangzhou China 510620

    E-mail:
    [email protected]

    Tel / WhatApps:
    +8618078869184

  • Categories

  • Newsletter

    FIRST OR FULL NAME

    E-mail

  • paypal solution  Western UnionBank OF China
    E-mail:[email protected]   WhatsApp:+8618078869184   Skype:sky198710021 Chat with me
    Copyright 2006-2020 Powered By www.fmuser.org

    Contact Us