Night Light Saver V6
[05-30 04:13:38] 来源:http://www.88dzw.com 单片机电路图 阅读:8704次
文章摘要:saver6.pdf I built the board with universal pcb and put it under the lamp fixture. SW1 and 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
Night Light Saver V6,标签:电路图讲解,电路图练习,http://www.88dzw.comsaver6.pdf
I built the board with universal pcb and put it under the lamp fixture. SW1 and SW2 are small tact switch. To press them I need a small rod made by bamboo.
Figure 3: Bottom view with Ni-MH battery |
Software
The 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 for update clock, check SW2, blink LED and update output bit will be executed every 1/10s. The task that controls output instead, will be executed every one second. For different preset time, time on, time off, you can edit the source code and recompile with sdcc easily. I provide sample scheduler scanning function, scan_pgm( ). If you want to modify the code for all 8-bit output on P1 similar to the Miniature Real-time Controller. You may have open collector driver, the same hardware and modify a little bit of the source code.
/* Copyright (C) 2004 Wichit Sirichote, kswichit@kmitl.ac.th, 20 December 2004 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (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 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ #include #define tick_test P3_0 // 10Hz/2 output for clock calibration#define LED P3_7#define output1 P1_6 char status; int count, i;char tick, flag1, temp, timer1, timer2; char hour,min,sec,sec10; // you may press set time button whenever you want the lamp turns on // for winter season you may press ealier than local time // for summer more late, time will shift relatively! // period will be 22:00 - 18:00 = 4 hours code char time_on1[] = {18,00}; code char time_off1[] = {22,00}; // another scheduler, the 3rd byte will write to P1 // you may replace control_output function by scan_pgm function code char pgm1[]={18,00,0x80,19,00,0,20,0x80,1,21,00,0}; char _sdcc_external_startup() { return 1; // skip static and global variables initialization } scan_pgm() { char i; for(i=0; i<4; i++) { if(hour == pgm1[i*3] && min == pgm1[i*3+1]) P1 = ~pgm1[i*3+2]; } } control_output() { if(hour == time_on1[0] && min == time_on1[1]) status = 0; if(hour == time_off1[0] && min == time_off1[1]) status = 1; } blink_led() { if(flag1&1) { if(++timer1>1) { 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 for 10Hz tick++; tick_test ^= 1; // test tick for 10Hz/2 or 5Hz time(); set_time(); blink_led(); update_output(); } main() { TMOD = 0x01; // timer1 and timer0 = mode 1 EA = ET0 = TR0 = 1; // enable timer0 interrupt, start timer PCON |= 1; // enable IDLE mode, to extend backup period for(;;) ; } |
- 上一篇:ID卡考勤机电路
《Night Light Saver V6》相关文章
- › Night Light Saver V6
- 在百度中搜索相关文章:Night Light Saver V6
- 在谷歌中搜索相关文章:Night Light Saver V6
- 在soso中搜索相关文章:Night Light Saver V6
- 在搜狗中搜索相关文章:Night Light Saver V6