电子文章 | 电子资料下载 | 家电维修 | 维修资料下载 | 加入收藏 | 全站地图
您现在所在位置:电子爱好者电子文章电子电路图单片机电路图xTimer V1.0

xTimer V1.0

03-13 01:54:52 | http://www.5idzw.com | 单片机电路图 | 人气:450
标签:电路图讲解,电路图练习,http://www.5idzw.com xTimer V1.0,http://www.5idzw.com
My wife asked me to find another timer for using in the kitchen. She got one already with analog setting, but it needs one AA size battery. Digital setting may not easy for human interface. However I will make it for easy time setting. When I am free I will modify it to be analog setting. May be I can use 555 monostable for POT reading. So I got my lab at home finding old boards and parts on the shelf. I found MAX7219, 8-digit LED display module and two buzzers. The MAX7219 needs serial interface, like SPI. This enables me to use a 20-pin 89C4051 MCU, since the pin counts for i/o port is quite limited. The 8-digit LED lets me have four timers, each will have two digit. I can set say, 00-99mins or 0-99Hrs. The output would  be open collector with my favorite 7407!

Figure 1: The prototype of xTiemr V1.0.

The LED module with MAX7219 is a ready made having 10-pin header for easy plugin to the 4051 board. As shown in Fig. 1, four keys are used to set time for each timer. Each timer will have two digit LED. The right hand side, timer 1 and timer 2 are for minute counting, the left hand, timer 3 and timer 4 are for hour counting.

For easy setting with key switch, it has a preset time value that was commonly used, e.g. -1, 0, 3, 5, 10, 15, 20, 25.

When time-out, display will show 0, and the output bit is activated. The optional two buzzers are for timer1 and timer2 alarm. I made this output alarm for kitchen use.

Hardware Schematic

Complete schematic is shown in Fig 2. The MCU is AT89C4051 with 11.0592MHz xtal. The MAX7219 needs only three signals, CLK, DIN and LOAD. These signals are software generated assembly code. You may learn how assembly code interface with c from the firmware. Since when power up, all port bits are logic high, so I chose the 7407, open collector to provide NPN O/C output. These output bits are suitable for opto-isolator driving. The sample output module is opto-triac, the MC3040. The input circuit is simple with current mode driving, say 15mA is enough for MC3040. The output triac having ZCS drives a 220V coil electromechanical relay. Since the relay contact provide NO and NC, so we can provide two function AC plugs, i.e., delay on for NO and delay off for NC contacts.


Figure 2: Hardware schematic of xTimer V1.0.


xtimer1.pdf

You can notice that we have reset button to wake up MCU! This version has no main switch to power on and off the board. Instead it uses MCU and MAX7219 power down mode. We will see later sample code that put MCU and MAX7219 to power down mode. When All LEDs are light, the dc current drawn about 90mA @+5V, and when power down mode, it will be approx. 10mA. The circuit of MAX7219 is recommenced by MAXIM application note, it is simple hardware and most of settings are done by software control.

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]  下一页

,xTimer V1.0
关于《xTimer V1.0》的更多文章