You Are Here: Home » AVR ATmega Projects » xTimer V1.0 using AT89C4051 microcontroller

xTimer V1.0 using AT89C4051 microcontroller




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!

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.

xTimer V1.0

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.

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++].

 

For more detail: xTimer V1.0 using AT89C4051 microcontroller

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Haptic Technology
How Haptic Technology Works

Since the 1980s, computer scientists have been trying to answer these questions. Their field is a specialized subset of haptics...

Close
Scroll to top