night light saver v6 latest design of night light saver circuit built with at89c2051. nice firmware using c coding developed with sdcc. this new version has internal ni-mh battery backup, reset button simple time setting. now the circuit board was embedded with lamp fixture. preset turn on period is from 18:00 to 22:00 everyday. you may let the saver turn on whenever you want. the period of time on can be reprogrammed with sdcc. howvere this project is not recommended f beginner. the circuit uses transfmerless supply no galvanic isolation! figure 1: embedded saver with lamp fixture hardware deionfigure 1 shows complete hardware schematic of the night light saver v6.0. the ac line was protected f1, a 1a fuse. any sht circuit caused by saver's components will blow the fuse. r1 c1 limit current to the +5v zener diode, d3. r2 disges capacit c1 when power terminal of the circuit was opened. the super capacit c2,+5v 0.01f filters dc supply. d4 acts as unidirectional switch f current supplied to mcu. bt1 is +3v 60mah ni-mh battery f backup the mcu when main power failed. the ging current is approx. 2ma with ac main lives. when main power failed, bt1 supplies approx. 4ma to the mcu. with fully ged, it could be able to provide backup time approx. 15hrs. the mcu runs with +vbackup. sw1 helps reset the mcu, in case of brownout voltage by bt1. c4 internal pull-down resist fms simple reset circuit. the mcu, 89c2051 runs with 3.579mhz xtal. sw2 is f clock setting, when pressed, time will be 18:00. p3.7 drives tick led with small sink current. r5, 4.7k limits less than one ma f d5. p3.0 provides 5hz clock signal f calibration. the output bit is p1.6. it drives pnp transist, q1. r3 limits base current. r5 pull base pin to +v when p1.6 is logic '1' to fully turn off q1. r4 limits dc current injected to q2, mac97 small triac. lp1 is incescent 25w lamp. the lamp's wattage can be up to 40w.figure 2: complete schematic of night light saver v6.0saver6.pdf i built the board with universal pcb put it under the lamp fixture. sw1 sw2 are small tact switch. to press them i need a small rod made by bamboo. figure 3: bottom view with ni-mh batterysoftwarethe source program is beautiful coding with c language. after timer initialization then idle mode is entered by setting bit0 in pcon register. the timer0 overflows 10 times per second. tasks f update clock, check sw2, blink led update output bit will be executed every 1/10s. the task that controls output instead, will be executed every one second. f different preset time, time on, time off, you can edit the source code recompile with sdcc easily. i provide sample scheduler scanning function, scan_pgm( ). if you want to modify the code f all 8-bit output on p1 similar to the miniature real-time controller. you may have open collect driver, the same hardware modify a little bit of the source code. /* lamp.c night light saver v6.0, 89c2051 runs with 3.579mhz xtal the source code was compiled with sdcc. copyright (c) 2004 wichit sirichote, kswichit@kmitl.ac.th, 20 december 2004 this program is free software; you can redistribute it / modify it under the terms of the gnu general public license as published by the free software foundation; either version 2, (at your option) any later version. this program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability fitness f a particular purpose. see the gnu general public license f me details. */#include #define tick_test p3_0 // 10hz/2 output f clock calibration#define led p3_7#define output1 p1_6 status;int count, i; tick, flag1, temp, timer1, timer2; hour,min,sec,sec10;// you may press set time button whenever you want the lamp turns on // f winter season you may press ealier than local time // f summer me late, time will shift relatively! // period will be 22:00 - 18:00 = 4 hourscode time_on1[] = {18,00}; code time_off1[] = {22,00};// another scheduler, the 3rd byte will write to p1 // you may replace control_output function by scan_pgm functioncode pgm1[]={18,00,0x80,19,00,0,20,0x80,1,21,00,0}; _sdcc_external_startup() { return 1; // skip static global variables initialization }scan_pgm() { i; f(i=0; i1) { flag1 &= ~1; // clear flag1.0 timer1=0; led = 1; // turns off led } } }void time () /* update real-time clock */ { if (++sec10 >= 10) /* 100ms * 10 = 1 s */ { led = 0; control_output(); // control output every second sec10 = 0; flag1 |=1; if (++sec >= 60) {sec = 0; if (++min >= 60) {min = 0; if (++hour >= 24) {hour = 0; } } } } } set_time() { if((p3&4)==0) { status = 0; hour = 18; min = 0; sec = 0; timer2=0; } }update_output() { if(status) output1 = 1; else output1 =0; // update output bit }void timer_isr(void) interrupt 1 using 1 { th0 = 0x8b; tl0 = 0x7f; // reload with 35711 f 10hz tick++; tick_test ^= 1; // test tick f 10hz/2 5hz time(); set_time(); blink_led(); update_output(); } main() { tmod = 0x01; // timer1 timer0 = mode 1 ea = et0 = tr0 = 1; // enable timer0 interrupt, start timer pcon |= 1; // enable idle mode, to extend backup period f(;;) ; } figure 4 shows start time at 18:00 when sw2 was pressed. the lamp will turn on until 22:00 everyday. since the preset time, 18:00 can set whenever sw2 was pressed, so if you want to change time on, f examples in summer season, sun will set lately, suppose you want the lamp to be turned on at 19:00, you just press sw2 at 19:00. the day after it will turn on at 19:00, however time off will shift to 23:00. figure 4: preset time on f winterfigure 5 shows a complete lamp fixture with cover 25w lamp. i have been tested the energy saving lamp, 5w sylvania, it also wks fine.figure 5: with 25w lamp cover download schematicsaver6.pdf firmwarelamp.c lamp.rarc compilersdcc.zip sdcc.zipcad 9.1 schematic filena