xTimer V1.0

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

文章摘要:Software Main program is simple forever loop with 10ms tick cycle. All tasks will run every tick in round robin manner. The tick was prepared in startup file, as shown below, it was declared as cputick and the modifier extern indicates this variable was declared in external file. extern unsigned reg

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

Main program is simple forever loop with 10ms tick cycle. All tasks will run every tick in round robin manner. The tick was prepared in startup file, as shown below, it was declared as cputick and the modifier extern indicates this variable was declared in external file.

extern unsigned register char cputick;

Here is the main program, we will see detail for each task below.
 

 while(1)
  {
     while(!cputick)  // run following tasks every 10ms
     ;
     cputick = 0;
     set_timer();    // check key pressed 
     run_timer();    // run four timers
     key_release();    // check if key has been released
     updatedisplay();    // send data to MAX7219
     ring1();            // optional buzzer alarm1
     ring2();             // optional buzzer alarm2
  }

set_timer( ) function will check a given input bit. These input bit are P3.2, P3.3, P3.4 and P3.7. Checking is done by logical AND a specified bit with MASK byte, e.g. for P3.2 we will check bit 2 of P3 with MASK byte 0x04. The statement will be (P3&0x04), if the result is 0 then set flag1 bit 0 to one to indicates that key1 was pressed. Then check index1 greater or equal 9, if true, reset index1 to 0. Timer1 will reload with a preset_timer1[index1++].

The preset_timer1[] array is preset value for timer1. The sample is below.

char preset_timer1[] = {-1,0,3,5,10,15,20,25,30};
 
 

// reload preset time value from preset array for each key pressed

set_timer()
{
    if((flag1&1) == 0)    // enter only when keys have been released 
    {
    if((P3&0x04) == 0)
      {
        flag1 |= 1;
        if(index1>=9) index1 =0;
        timer1= preset_timer1[index1++];
      }
    if((P3&0x08) == 0)
      {
        flag1 |= 1;
        if(index2>=9) index2 =0;
        timer2= preset_timer2[index2++];
      }

    if((P3&0x10) == 0)
      {
        flag1 |= 1;
        if(index3>=13) index3 =0;
        timer3= preset_timer3[index3++];
      }
    if((P3&0x20) == 0)
      {
        flag1 |= 1;
        if(index4>=8) index4 =0;
        timer4= preset_timer4[index4++];
      }

     }

}

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


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

《xTimer V1.0》相关文章