最新无码a∨在线观看,一本av高清一区二区三区,亚洲熟妇色l20p,宅男噜噜69av,中出あ人妻熟女中文字幕

xTimer V1.0

2013-10-29 14:27:00
  • my wife asked me to find another timer f using in the kitchen. she got one already with analog setting, but it needs one aa s

my wife asked me to find another timer f using in the kitchen. she got one already with analog setting, but it needs one aa size battery. digital setting may not easy f human interface. however i will make it f easy time setting. when i am free i will modify it to be analog setting. may be i can use 555 monostable f pot reading. so i got my lab at home finding old boards parts on the shelf. i found max7219, 8-digit led display module two buzzers. the max7219 needs serial interface, like spi. this enables me to use a 20-pin 89c4051 mcu, since the pin counts f i/o pt is quite limited. the 8-digit led lets me have four timers, each will have two digit. i can set say, 00-99mins 0-99hrs. the output would be open collect with my favite 7407! figure 1: the prototype of xtiemr v1.0.the led module with max7219 is a ready made having 10-pin header f easy plugin to the 4051 board. as shown in fig. 1, four keys are used to set time f each timer. each timer will have two digit led. the right h side, timer 1 timer 2 are f minute counting, the left h, timer 3 timer 4 are f hour counting. f 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, the output bit is activated. the optional two buzzers are f timer1 timer2 alarm. i made this output alarm f 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 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 pt bits are logic high, so i chose the 7407, open collect to provide npn o/c output. these output bits are suitable f opto-isolat driving. the sample output module is opto-triac, the mc3040. the input circuit is simple with current mode driving, say 15ma is enough f mc3040. the output triac having zcs drives a 220v coil electromechanical relay. since the relay contact provide no nc, so we can provide two function ac plugs, i.e., delay on f no delay off f nc contacts. figure 2: hardware schematic of xtimer v1.0. xtimer1.pdfyou can notice that we have reset button to wake up mcu! this version has no main switch to power on off the board. instead it uses mcu max7219 power down mode. we will see later sample code that put mcu max7219 to power down mode. when all leds are light, the dc current drawn about 90ma @+5v, when power down mode, it will be approx. 10ma. the circuit of max7219 is recommenced by maxim application note, it is simple hardware most of settings are done by software control. software main program is simple fever 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 the modifier extern indicates this variable was declared in external file. extern unsigned register cputick; here is the main program, we will see detail f 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 p3.7. checking is done by logical a specified bit with mask byte, e.g. f 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 equal 9, if true, reset index1 to 0. timer1 will reload with a preset_timer1[index1++]. the preset_timer1[] array is preset value f timer1. the sample is below. preset_timer1[] = {-1,0,3,5,10,15,20,25,30}; // reload preset time value from preset array f 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++]; } } }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 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 f 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; } } we have three states that will be executed. below table shows the action f each state. note that timer7 is a timer that we used f shutdown timeout. flag1 bit 1 is f dot blinking signal flag. stateactiontimer1 = -1flag1 &= ~0x02; // no dot blink flag2 &= ~0x01; buzzer1 = off; // off buzzer1timer1 = 0clrbit(output1) // fire output1 buzzer1 = on; // on buzzer flag flag1 &= ~0x02; // no dot blink flag2 &= ~0x01;timer1 = 3, 5,....timer7 = 0; // reset shutdown timeout buzzer1 = off; flag1 |= 0x02; setbit(output1) if(++timer1_clk >= 60) {timer1_clk = 0; timer1--; }as shown above the shutdown task also resided in one second resolution the same as timer running. timer7 will reset every timer1 is not equal 0. however when user set all timers off, all value of timer1-timer4 will be -1, then the shutdown task will run. the timeout is 10 seconds, you may see that when timeout, the max7219 will be set to shutdown mode the pd bit in pcon will be set to one to enable power down! the on chip oscillat stops!, display will show blank. there will no response from any key pressing then. to wake up mcu turn it on, the reset button will help exit from power down mode! shutdown() { if((timer1&timer2&timer3&timer4)== -1) { timer7++; if(timer7 >= 10) // 10 seconds timeout { shift(0x0c00); // enable shutdown mode asm' clr ie.7'; asm' mov pcon,#2'; // enter power down mode } } }the update display will send serial data of buffer[] array to max7219. you may study the code of how to convert binary data to 7-segment display in movetimetobuffer( ) function. sdcc version firmware again the reason why i wrote a new version firmware, just f fun spend my free time learning new things. i got the problem with a big electromechanical relay, mostly the makers only produce the no contact. the sample schematic shown in fig 2. has the relay circuit that uses opto triac driving a no/nc relay! so i must change the firmware to let the output turn on when start timer turn off when time is over. to do such changing, it needs to modify the source code recompile it. i thought why don't try with sdcc. the people can modify the source code do-it-yourself. let get the sdcc f dos comm line, sdcc f 8051. unzip the package save to drive c. i made the folder app (application programs) f my source code. here is the new source code f sdcc, xtimer1.c timer4 is now modified to be delay off output. the counting is now based on minute the same as timer1 2. timer3 still be hour counting based. i have made the opto-relay f big load switching. figure 3: opto-relay f output4(active low).the opto-transist can be any type. usually some opto output can drive relay directly, but i think better to use a darlington transist, says uln2003, uln2803 to drive the relay. with this method, there is no galvanic contact between hv digital board. the emi produced from inductive load turning off will only propagate to the control board by induction radiation. this design is quite save f digital control board. now get back to run sdcc, below steps show how to use sdcc to compile the source code. after the sdcc has installed in drive c:, we must set path to let the dos know where is the folder of exe files of sdcc. to compile just type sdcc program.c. if everything ok, we will get the machine code in hex file. however the hex file produced by sdcc has *.ihx extension. we can convert it to hex file with *.hex simply by a program packihx. see example below. the hex file produced by sdcc is only 1877 bytes! you can use 89c2051 instead of 89c4051 f u2! microsoft(r) windows 98 (c)copyright microsoft cp 1981-1999. c:\windows>cd\ c:\>cd sdcc c:\sdcc>cd app c:\sdcc\app>path=c:\sdcc\bin c:\sdcc\app>sdcc xtimer1.c library file /sdcc/share/sdcc/lib/small/libsdcc.lib library file /sdcc/share/sdcc/lib/small/libint.lib library file /sdcc/share/sdcc/lib/small/liblong.lib library file /sdcc/share/sdcc/lib/small/libfloat.lib c:\sdcc\app> c:\sdcc\app>packihx xtimer1.ihx>xtimer1.hex packihx: read 308 lines, wrote 122: ok. c:\sdcc\app> 程序資料下載.rar