xTimer V1.0

[05-23 02:47:29]   来源:http://www.88dzw.com  单片机电路图   阅读:8450

文章摘要:You may see every key checking, flag1 bit 0 will set. This flag will signal the set timer task that key has been pressed, so on entering it will check if this bit = 1, it will not repeat running. The task that reset this bit will check if all keys have been released is shown below. using logical AND

xTimer V1.0,标签:电路图讲解,电路图练习,http://www.88dzw.com

You may see every key checking, flag1 bit 0 will set. This flag will signal the set timer task that key has been pressed, so on entering it will check if this bit = 1, it will not repeat running.

The task that reset this bit will check if all keys have been released is shown below. using logical AND P3 with 0x3C. If all bits are '1', then clear bit 0 of flag1.
 

key_release()
{
    if((P3&0x3c) == 0x3c)
     flag1 &= ~1;
}

run_timer( ) can be one second resolution, so we put it running every second with the help of incrementing of one_second variable. All four timers will run every second then. The shutdown task also runs every second. We will see later for shutdown detail.
 

run_timer()
{
   if(++one_sec>=100)
   {
    one_sec = 0;
    run_timer1();
    run_timer2();
    run_timer3();
    run_timer4();
    shutdown();  // run shutdown checking every second
   }
}

Now look at the sample code that runs timer1.
 

run_timer1()
{
     if(timer1 != -1) // enter only preset value != -1
     {
       if(timer1 != 0) // enter only timer1 != 0
       {
        timer7 = 0; // reset shutdown timeout
        buzzer1 = off;
        flag1 |= 0x02;
        setbit(output1)

        if(++timer1_clk >= 60)   // timer1 is one min based!
           {
             timer1_clk = 0;
             timer1--;
           }
        }
        else  // timer1 == 0 then fire output
           {
              clrbit(output1) // fire output1
              buzzer1 = on;
              flag1 &= ~0x02;
              flag2 &= ~0x01;
           }
      }
       else
       {
       flag1 &= ~0x02; // no blink when timer1 == -1
       flag2 &= ~0x01;
       buzzer1 = off;
       }
}
 

上一页  [1] [2] [3] [4] [5]  下一页


Tag:单片机电路图电路图讲解,电路图练习电子电路图 - 单片机电路图

《xTimer V1.0》相关文章