Night Light Saver V6
[10-10 20:38:44] 来源:http://www.88dzw.com 微机|单片机 阅读:8223次
文章摘要: 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 and/or modify it under the terms of the GNU Gener
Night Light Saver V6,标签:电路设计,http://www.88dzw.comLamp.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 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_6char 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 hourscode 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 functioncode 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(;;) ; }
- 上一篇:简易51试验板
《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