查看:
17946
回复: 40 |
参赛作品《多功能遥控电子时钟》 (已完成)
|
|||
|
发表于2017-06-03 16:01:44
|
只看该作者
1#
电梯直达
【报名阶段需要填写的内容】 1. 参赛者姓名(必填项):
【作品正式发表(报名成功后进入设计阶段)需要填写的内容】 一、作品简介 例如,可以包括但不局限于以下内容: 1.作品的整机外观图片或焊接组装好的PCBA图片; 2.作品的研究背景、目的和功能、市场应用前景; 3.作品在创新性、趣味性、实用性甚至公益性方面,有哪些亮点可体现?
3.1.1 设计效果:
3.1.2 实际效果
3.1.3 运行效果 二、系统构架图 用流程图或思维导图等形式,描述您的作品的组成构架,即方案图。 三、硬件部分的描述 1.附上原理图&PCB实物图的图片或者源文件(官方建议大家尽量用源文件上传),如果是图片,请确保图片是清晰可辨的; 2.用文字把该作品的实现原理、系统的工作过程大致讲解一下。 显示电路部份,采用模块结构。多片串行显示,可以不局限于线路板大小,而可以将产品尺寸做大;
2、主板电路
以前做过一个版本是IR的,现在IR的遥控器手上难找,且IR的有方向性不能穿墙。将原IR部份电路改成RF方式的。另外增加了485的总线接口。可以与485总线的智能家居系统等实现系统对接。实现一定的模块功能。 主板到显示模块,输出外围了一个NMOS,可以实现PWM亮度调节,夜晚时分,可以自动调低亮度。
四、材料清单(BOM列表) 列出您这个作品所用到的主要器件(关键器件即可),比如单片机&ARM芯片、专用集成芯片(ASIC)、传感器、功能模块等。 如果所列出的芯片是来自我们立创商城上的,最好能写出该器件的商品编号或附上对应购买链接。 失误更正: 显示板BOM清单内,数码显示器LED1,正确型号为:FJ11001AH, 编号:C10687,购买链接:http://www.szlcsc.com/product/details_11231.html 五、软件部分的描述(选填) 如果您的作品涉及到软件,请列出作品对应的软件工作流程图,及关键部分的例程、源码(如果您想开源的话请上传全部源码)。 5.1、按键处理流程:
5.2 按键部份处理代码:
#include "Config.h" extern DATE date; extern TIME time; extern volatile Alam_t on_Alam; #if OPT_COUNTER extern volatile Counter_t on_Ct; #endif extern volatile uCHAR dis_buffer[11]; extern volatile WatchSet_t WatchSet; extern volatile WatchCfg_t WatchCofing; extern volatile XTIMER Timer[e_Timer_Max]; //------------------------------- //Function: Key Adjust Process //------------------------------- void Key_Adjust_Value(u8 dig, s8 v) { if(!WatchSet.in.item.set) return; if(!WatchSet.in.item.adj) return; dig = dig?10:0; v += dig; //己进入调整状态 switch(WatchSet.item){ case MENUMOD_ITEM_TIME: Watch_Set_Time(WatchSet.sub, v); break; case MENUMOD_ITEM_DATE: Watch_Set_Date(WatchSet.sub, v); break; #if OPT_COUNTER case MENUMOD_ITEM_COUNT: Watch_Set_Count(WatchSet.sub, v); break; #endif case MENUMOD_ITEM_ALAM0: case MENUMOD_ITEM_ALAM1: case MENUMOD_ITEM_ALAM2: case MENUMOD_ITEM_ALAM3: case MENUMOD_ITEM_ALAM4: case MENUMOD_ITEM_ALAM5: case MENUMOD_ITEM_ALAM6: case MENUMOD_ITEM_ALAM7: case MENUMOD_ITEM_ALAM8: case MENUMOD_ITEM_ALAM9: Watch_Set_Alam(WatchSet.item-MENUMOD_ITEM_ALAM0, WatchSet.sub, v); break; default: break; } } //------------------------------- //Function: Key action Process //------------------------------- void KeyProcess(void) { uCHAR Keytemp,Out = 200,i; Keytemp = IR_KeyB(); if(Keytemp==KEY_SEL_NOSEL)return; Beeper(TRUE, 100, 0); if(IS_TIMERSTART(e_Timer_SET)) { RESET_TIMER(e_Timer_SET); } else { START_TIMER(e_Timer_SET, 25000); } if(on_Alam.inw) { memclr(&on_Alam, sizeof(Alam_t)); return; #if OPT_COUNTER } else if(on_Ct.full && on_Ct.use) { on_Ct.use = FALSE; on_Ct.full = FALSE; return; #endif } switch(Keytemp) { case KEY_SEL_DIG0: case KEY_SEL_DIG1: case KEY_SEL_DIG2: case KEY_SEL_DIG3: case KEY_SEL_DIG4: case KEY_SEL_DIG5: case KEY_SEL_DIG6: case KEY_SEL_DIG7: case KEY_SEL_DIG8: case KEY_SEL_DIG9: //己进入调整状态 Keytemp -= KEY_SEL_DIG0; Key_Adjust_Value(TRUE, Keytemp); if(!WatchSet.in.item.set) break; if(!WatchSet.in.item.adj) break; case KEY_SEL_SET: if(WatchSet.in.item.show) { Alert_t* alam = WatchCofing.alart+WatchSet.sub; if(WatchSet.item==MENUSHOW_ITEM_ALAM) { if(alam->on) { alam->on = FALSE; if(on_Alam.id==WatchSet.sub) { memclr(&on_Alam, sizeof(Alam_t)); } } else { alam->on = TRUE; } Watch_Show_Alam(WatchSet.sub); WatchCofing.dirty = TRUE; } break; #if OPT_COUNTER } else if(on_Ct.use) { on_Ct.use = FALSE; break; #endif } if(WatchSet.in.item.set) { if(WatchSet.in.item.adj) { //调整设置项目 //WatchSet.in.item.adj = FALSE; WatchSet.sub++; if(WatchSet.item==MENUMOD_ITEM_DATE){ if(WatchSet.sub>=7) { ExitMenu(TRUE); break; } } else { if(WatchSet.sub>=6) { ExitMenu(TRUE); break; } } } else { WatchSet.sub = 0; WatchSet.item++; if(WatchSet.item>=MENUMOD_ITEM_MAX) { ExitMenu(TRUE); break; } } Watch_Show_SetItem(WatchSet.item, WatchSet.sub); break; //WatchSet.in.item.adj = TRUE; } WatchSet.in.items = 0; WatchSet.in.item.set = TRUE; WatchSet.sub = 0; WatchSet.item = MENUMOD_ITEM_TIME; Watch_Show_SetItem(MENUMOD_ITEM_TIME, 0); break; case KEY_SEL_INC: if(WatchSet.in.item.set) { Key_Adjust_Value(FALSE, 1); break; #if OPT_COUNTER } else if(on_Ct.use && on_Ct.pause) { on_Ct.base = SecondsToTime(TimeToSeconds(time)+on_Ct.run); on_Ct.pause = FALSE; break; #endif } //显示闹钟 if(WatchSet.in.item.show) { WatchSet.sub++; if(WatchSet.sub>9) { WatchSet.in.item.show = FALSE; } } else { WatchSet.in.item.show = TRUE; WatchSet.item = MENUSHOW_ITEM_ALAM; WatchSet.sub = 0; } Watch_Show_Alam(WatchSet.sub); break; case KEY_SEL_DEC: if(WatchSet.in.item.set) { //己进入调整状态 if(WatchSet.in.item.adj) { Key_Adjust_Value(FALSE, -1); } else { WatchSet.sub = 0; WatchSet.in.item.adj = TRUE; Watch_Show_SetItem(WatchSet.item, 0); } break; } if(WatchSet.in.item.show ) { ExitMenu(TRUE); #if OPT_COUNTER } else if(on_Ct.use){ on_Ct.pause = TRUE; break; #endif } else { //显示日期 WatchSet.in.items = 0; WatchSet.in.item.show = TRUE; WatchSet.item = MENUSHOW_ITEM_DATE; Watch_Display_Date(date); } break; } } void ExitMenu(char force) { if(IS_TIMEROVER(e_Timer_SET)||force) { if(WatchSet.in.item.modify) { switch(WatchSet.item) { case MENUMOD_ITEM_TIME: Watch_Save_Time(); break; case MENUMOD_ITEM_DATE: Watch_Save_Date(); break; #if OPT_COUNTER case MENUMOD_ITEM_COUNT: Watch_Save_Count();//show the countdown time break; #endif case MENUMOD_ITEM_ALAM0: case MENUMOD_ITEM_ALAM1: case MENUMOD_ITEM_ALAM2: case MENUMOD_ITEM_ALAM3: case MENUMOD_ITEM_ALAM4: case MENUMOD_ITEM_ALAM5: case MENUMOD_ITEM_ALAM6: case MENUMOD_ITEM_ALAM7: case MENUMOD_ITEM_ALAM8: case MENUMOD_ITEM_ALAM9: Save_WatchCofing(); break; default: WatchSet.in.items = 0; break; } } WatchSet.sub = 0; WatchSet.item = 0; WatchSet.temp = 0; WatchSet.in.items = 0; STOP_TIMER(e_Timer_SET); } } 5.3 按键/遥控读取部份代码 #include "Config.h" extern volatile _Bool Synch; extern volatile u8 RF_data; extern volatile XTIMER Timer[e_Timer_Max]; const u8 rfcodes[] = { 0XCC, 0X03, 0X0C, 0X0F, 0X30, 0X33, 0X3C, 0X3F, 0XC0, 0XC3, 0XCF, 0XF0 }; void Key_Init(void) { set_io_isinput(PORT_KEY_SET, BIT_KEY_SET); set_io_isinput(PORT_KEY_INC, BIT_KEY_INC); set_io_isinput(PORT_KEY_DEC, BIT_KEY_DEC); set_io_pushpull(PORT_KEY_SET, BIT_KEY_SET); set_io_pushpull(PORT_KEY_INC, BIT_KEY_INC); set_io_pushpull(PORT_KEY_DEC, BIT_KEY_DEC); } uCHAR GetKeyVal(void) { char temp, i; static key_bak, key_temp=KEY_SEL_NOSEL; temp = 0; if(!get_bit(PORT_KEY_SET, BIT_KEY_SET)) { temp |= BIT(0); } if(!get_bit(PORT_KEY_INC, BIT_KEY_INC)) { temp |= BIT(1); } if(!get_bit(PORT_KEY_DEC, BIT_KEY_DEC)) { temp |= BIT(2); } if(temp == KEY_SEL_NOSEL) { //unpressed key_temp = KEY_SEL_NOSEL; return KEY_SEL_NOSEL; } //the last key event not free if(key_temp==temp) return KEY_SEL_NOSEL; //key noise filter if(!IS_TIMERSTART(e_Timer_KeyFilter)) { key_bak = temp; START_TIMER(e_Timer_KeyFilter, 10); } else if(key_bak!=temp) { //key changed in filter STOP_TIMER(e_Timer_KeyFilter); return KEY_SEL_NOSEL; } if(!IS_TIMEROVER(e_Timer_KeyFilter)) return KEY_SEL_NOSEL; STOP_TIMER(e_Timer_KeyFilter); key_temp = temp; if(temp==0x01) { return KEY_SEL_SET; } else if(temp==0x02) { return KEY_SEL_INC; } else if(temp==0x04) { return KEY_SEL_DEC; } else { //KEY_SEL_MOV,KEY_SEL_POW if(temp==0x03) { return KEY_SEL_MOV; } else if(temp==0x05) { return KEY_SEL_POW; } } return KEY_SEL_NOSEL; } uCHAR IR_KeyB(void) { uCHAR Keytemp; static uCHAR RF_Temp = 0xFF; if(!Synch) { Keytemp = GetKeyVal(); } else { Synch = FALSE; if(IS_TIMERSTART(e_Timer_Remote)) { if(!IS_TIMEROVER(e_Timer_Remote)) { return KEY_SEL_NOSEL; } STOP_TIMER(e_Timer_Remote); } //遥控解码间隙超时 START_TIMER(e_Timer_Remote, 300); for(Keytemp=0; Keytemp<12; Keytemp++) { if(rfcodes[Keytemp]==RF_data) { Synch = TRUE; break; } } if(Synch) { switch(Keytemp) { case 10: Keytemp = KEY_SEL_SET; break; case 11: Keytemp = KEY_SEL_DEC; break; } } Synch = FALSE; } return Keytemp; }
5.4 电子表核心处理代码 #include "Config.h" #if OPT_COUNTER volatile Counter_t on_Ct = {0}; #endif volatile Alam_t on_Alam = {0, 0, 0, 0}; volatile uCHAR dis_buffer[11]; volatile WatchSet_t WatchSet; extern DATE date; extern TIME time; extern volatile WatchCfg_t WatchCofing; extern volatile XTIMER Timer[e_Timer_Max]; //----------------------------------- #define isLeampyear(year) ((year%4==0&&year%100!=0)||(year%400==0)) //----------------------------------- //led show codes //0~9, ' ', -, A, C, H const uCHAR LED[] = { 0XDE,0X06,0XEC,0XAE,0X36, //0~4 0XBA,0XFA,0X0E,0XFE,0XBE, //5~9 0x00, //String - ' ' 0X20, //String - '-' 0X7E, //String - 'A' 0XD8, //String - 'C' 0X76, //String - 'H' 0XD6, //String - 'U' 0X5E, //String - 'N' 0XF0, //String - 't' 0XD0, //String - 'L' 0X01 //String - '.' }; const uCHAR SEGMENT[] = { 0x08,0x04,0x02,0x80,0x40,0x10,0x20,0x01 }; //----------------------------------- //FUNCTION: DISPLAY THE DATA //----------------------------------- static void Watch_Update_Display(void) { uCHAR i; uCHAR v; for(i=0; i<11; i++) { v = *(dis_buffer+i); if(v>=LEDWORD_USEDEF) { MC74HC595_Shift(v-LEDWORD_USEDEF); } else { MC74HC595_Shift(LED[v]); } } MC74HC595_Update(); } void write_DisBuffer(u8 ID, u8 v) { *(dis_buffer+ID) = v; } u8 read_DisBuffer(u8 ID) { return *(dis_buffer+ID); } //---------------------------------- //FUNCTION: display the year //---------------------------------- void Watch_Display_Date(DATE date) { write_DisBuffer(LEDITEM_MAIN_1, math_div(date.year, 10)); //year ten write_DisBuffer(LEDITEM_MAIN_2, math_mod(date.year, 10)); //year signed write_DisBuffer(LEDITEM_MAIN_3, LEDWORD_LINE); //"-" write_DisBuffer(LEDITEM_MAIN_4, math_div(date.month, 10)); //month ten write_DisBuffer(LEDITEM_MAIN_5, math_mod(date.month, 10)); //month signed write_DisBuffer(LEDITEM_MAIN_6, LEDWORD_LINE); //"-" write_DisBuffer(LEDITEM_MAIN_7, math_div(date.day, 10)); //date ten write_DisBuffer(LEDITEM_MAIN_8, math_mod(date.day, 10)); //date signed write_DisBuffer(LEDITEM_WEEK, math_mod(date.week, 10)); //week if(WatchSet.in.item.show) { write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_WORDA); write_DisBuffer(LEDITEM_TEMP_L, LEDWORD_WORDT); } Watch_Update_Display(); } //---------------------------------- //Function: display the date //---------------------------------- void Watch_Display_Time(TIME time) { uCHAR temp; static u8 scrow = TRUE; write_DisBuffer(LEDITEM_MAIN_1, math_div(time.hour, 10)); //Hour ten write_DisBuffer(LEDITEM_MAIN_2, math_mod(time.hour, 10)); //Hour signed write_DisBuffer(LEDITEM_MAIN_3, LEDWORD_LINE); //"-" write_DisBuffer(LEDITEM_MAIN_4, math_div(time.min, 10)); //minute ten write_DisBuffer(LEDITEM_MAIN_5, math_mod(time.min, 10)); //minute signed write_DisBuffer(LEDITEM_MAIN_6, LEDWORD_LINE); //"-" write_DisBuffer(LEDITEM_MAIN_7, math_div(time.sec, 10)); //second ten write_DisBuffer(LEDITEM_MAIN_8, math_mod(time.sec, 10)); //second signed if(!WatchSet.in.items) { #if OPT_COUNTER if(on_Ct.use) { if(!on_Ct.full) { on_Ct.segLeds |= SEGMENT[on_Ct.sCount++]; if(on_Ct.sCount>=6) { on_Ct.sCount = 0; } on_Ct.segLeds &= ~SEGMENT[on_Ct.sCount]; write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_WORDC); write_DisBuffer(LEDITEM_TEMP_L, LEDWORD_DIG0); write_DisBuffer(LEDITEM_WEEK, LEDWORD_USEDEF+on_Ct.segLeds); } else { if(scrow) { write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_BLANK); write_DisBuffer(LEDITEM_TEMP_L, LEDWORD_BLANK); write_DisBuffer(LEDITEM_WEEK, LEDWORD_BLANK); } else { write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_WORDC); write_DisBuffer(LEDITEM_TEMP_L, LEDWORD_DIG0); write_DisBuffer(LEDITEM_WEEK, LEDWORD_LINE); } scrow = !scrow; } } else #endif if(on_Alam.inw) { if(scrow) { write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_WORDA); write_DisBuffer(LEDITEM_TEMP_L, on_Alam.id); write_DisBuffer(LEDITEM_WEEK, LEDWORD_LINE); } else { write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_BLANK); write_DisBuffer(LEDITEM_TEMP_L, LEDWORD_BLANK); write_DisBuffer(LEDITEM_WEEK, LEDWORD_BLANK); } scrow = !scrow; } else { temp = Temperature_Read(); if(temp>=100) { write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_LINE); write_DisBuffer(LEDITEM_TEMP_L, LEDWORD_LINE); } else { write_DisBuffer(LEDITEM_TEMP_H, math_div(temp, 10)); write_DisBuffer(LEDITEM_TEMP_L, math_mod(temp, 10)); } write_DisBuffer(LEDITEM_WEEK, math_mod(date.week, 10)); //week } } Watch_Update_Display(); } void Watch_Display_Temp(s8 temp) { if(temp>=0) { write_DisBuffer(LEDITEM_TEMP_H, math_div(temp, 10)); write_DisBuffer(LEDITEM_TEMP_L, math_mod(temp, 10)); } else { write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_LINE); write_DisBuffer(LEDITEM_TEMP_L, (0-temp)); } Watch_Update_Display(); } //---------------------------------- //Function: Adjust the time //---------------------------------- void setv(uCHAR ID, s8 v, const char min, const char max) { s8 ss = -1; if(v>=10) { ss = v-10; if((ss>=min)&&(ss<=max))write_DisBuffer(ID, ss); } else { ss = (char)(read_DisBuffer(ID)+v); if(ss > max) { write_DisBuffer(ID, min); } else if(ss < min) { write_DisBuffer(ID, max); } else { write_DisBuffer(ID, (uCHAR)ss); } } if(v!=0)WatchSet.in.item.modify = TRUE; } void setCV(uCHAR ID, s8 v, const char min, const char max) { setv(ID, v, min, max); //更新闪烁缓存数值 WatchSet.temp = read_DisBuffer(ID); } static TIME Watch_Adjust_Time(char AdjItem, s8 val) { TIME new_time; switch(AdjItem){ case 0: setCV(LEDITEM_MAIN_1, val, 0, 2); if(read_DisBuffer(LEDITEM_MAIN_1)==2){ setv(LEDITEM_MAIN_2, val, 0, 3); } break; case 1: if(read_DisBuffer(LEDITEM_MAIN_1)==2){ setCV(LEDITEM_MAIN_2, val, 0, 3); } else { setCV(LEDITEM_MAIN_2, val, 0, 9); } break; case 2: setCV(LEDITEM_MAIN_4, val, 0, 5); break; case 3: setCV(LEDITEM_MAIN_5, val, 0, 9); break; case 4: setCV(LEDITEM_MAIN_7, val, 0, 5); break; case 5: setCV(LEDITEM_MAIN_8, val, 0, 9); break; default: break; } new_time.hour = math_mux(read_DisBuffer(LEDITEM_MAIN_1),10) + read_DisBuffer(LEDITEM_MAIN_2); new_time.min = math_mux(read_DisBuffer(LEDITEM_MAIN_4),10) + read_DisBuffer(LEDITEM_MAIN_5); new_time.sec = math_mux(read_DisBuffer(LEDITEM_MAIN_7),10) + read_DisBuffer(LEDITEM_MAIN_8); Watch_Update_Display(); return new_time; } //--------------------------------- //Function: Adjust date //--------------------------------- void Adjust_Date_Value(u8 ID) { u8 month, x; u16 year = 2000; uCHAR lagermonth[] = {1,3,5,7,8,10,12}; year += read_DisBuffer(LEDITEM_MAIN_1)*10 + read_DisBuffer(LEDITEM_MAIN_2); month = read_DisBuffer(LEDITEM_MAIN_4)*10 + read_DisBuffer(LEDITEM_MAIN_5); if(month==2) { if(read_DisBuffer(LEDITEM_MAIN_7)==2) { if(isLeampyear(year)) { setv(LEDITEM_MAIN_8, 0, 0, 8); } else { setv(LEDITEM_MAIN_8, 0, 0, 9); } } } else if(read_DisBuffer(LEDITEM_MAIN_7)==3) { for(x=0; x<sizeof(lagermonth); x++) { if(month==lagermonth[x]) { setv(LEDITEM_MAIN_8, 0, 0, 1); break; } } if(x>=sizeof(lagermonth)) { write_DisBuffer(LEDITEM_MAIN_8, 0); } } //更新闪烁缓存数值 if(ID==LEDITEM_MAIN_8) { WatchSet.temp = read_DisBuffer(LEDITEM_MAIN_8); } } static DATE Watch_Adjust_Date(char AdjItem, s8 val) { u8 month; DATE new_date; switch(AdjItem){ case 0: //Year-H setCV(LEDITEM_MAIN_1, val, 0, 9); break; case 1: //Year-L setCV(LEDITEM_MAIN_2, val, 0, 9); break; case 2: //Month-H setCV(LEDITEM_MAIN_4, val, 0, 1); if(read_DisBuffer(LEDITEM_MAIN_4)) { setv(LEDITEM_MAIN_5, val, 0, 2); } else { setv(LEDITEM_MAIN_5, val, 1, 9); } Adjust_Date_Value(LEDITEM_MAIN_4); break; case 3: //Month-L if(read_DisBuffer(LEDITEM_MAIN_4)) { setCV(LEDITEM_MAIN_5, val, 0, 2); } else { setCV(LEDITEM_MAIN_5, val, 1, 9); } Adjust_Date_Value(LEDITEM_MAIN_5); break; case 4: //DAY-H month = read_DisBuffer(LEDITEM_MAIN_4)*10 + read_DisBuffer(LEDITEM_MAIN_5); if(month==2) { setCV(LEDITEM_MAIN_7, val, 0, 2); } else { setCV(LEDITEM_MAIN_7, val, 0, 3); } Adjust_Date_Value(LEDITEM_MAIN_7); break; case 5: if(read_DisBuffer(LEDITEM_MAIN_7)==3) { setCV(LEDITEM_MAIN_8, val, 0, 1); } else { setCV(LEDITEM_MAIN_8, val, 0, 9); } Adjust_Date_Value(LEDITEM_MAIN_8); break; case 6: setCV(LEDITEM_WEEK, val, 0, 6); break; default: break; } new_date.year = math_mux(read_DisBuffer(LEDITEM_MAIN_1),10) + read_DisBuffer(LEDITEM_MAIN_2); new_date.month = math_mux(read_DisBuffer(LEDITEM_MAIN_4),10) + read_DisBuffer(LEDITEM_MAIN_5); new_date.day = math_mux(read_DisBuffer(LEDITEM_MAIN_7),10) + read_DisBuffer(LEDITEM_MAIN_8); new_date.week = read_DisBuffer(LEDITEM_WEEK); Watch_Update_Display(); return new_date; } //--------------------------------- //Check alam time //--------------------------------- void Watch_Start_Alam(void) { u8 i; u16 nowtime; Alert_t alam; static u8 beepn = 0; nowtime = (time.hour<<8)+time.min; if((nowtime>=0x0700)&&(nowtime<0x1200)) { //7:00~18:00 MC74HC595_Light_Set(80); } else { MC74HC595_Light_Set(30); } if(WatchSet.in.item.set) return; if(on_Alam.enb) { if(on_Alam.inw) { if(on_Alam.time==nowtime) { if(IS_TIMERSTART(e_Timer_Beep)) { if(!IS_TIMEROVER(e_Timer_Beep)) return; } if(++beepn<3) { Beeper(TRUE, 150, 150); } else { beepn = 0; Beeper(TRUE, 150, 250); } } else { on_Alam.inw = FALSE; if(on_Alam.cnt==0) on_Alam.enb = FALSE; } } else { if((nowtime-on_Alam.time)>=3) { on_Alam.inw = TRUE; on_Alam.cnt--; on_Alam.time = nowtime; } } } if(time.sec) return; for(i=0; i<10; i++) { alam = WatchCofing.alart[i]; if(!alam.on) continue; if((alam.begin>alam.end)&&(date.week>alam.end)&&(date.week<alam.begin)) continue; if((alam.begin<alam.end)&&((date.week<alam.begin)||(date.week>alam.end))) continue; if((alam.begin==alam.end)&&(date.week!=alam.begin))continue; if(nowtime==alam.time) { on_Alam.inw = TRUE; on_Alam.enb = TRUE; on_Alam.cnt = 2; on_Alam.id = i; on_Alam.time = nowtime; beepn = 0; return; } } } void Watch_Show_SetItem(MENUMOD_ITEM mi, char sub) { switch(mi) { case MENUMOD_ITEM_TIME: write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_WORDC); write_DisBuffer(LEDITEM_TEMP_L, LEDWORD_WORDH); write_DisBuffer(LEDITEM_WEEK, LEDWORD_BLANK); Watch_Display_Time(time); Watch_Adjust_Time(sub, 0); break; case MENUMOD_ITEM_DATE: write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_WORDC); write_DisBuffer(LEDITEM_TEMP_L, LEDWORD_WORDU); Watch_Display_Date(date); Watch_Adjust_Date(sub, 0); break; #if OPT_COUNTER case MENUMOD_ITEM_COUNT: write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_WORDC); write_DisBuffer(LEDITEM_TEMP_L, 0); write_DisBuffer(LEDITEM_WEEK, LEDWORD_LINE); Watch_Display_Time(on_Ct.set); Watch_Adjust_Time(sub, 0); break; #endif case MENUMOD_ITEM_ALAM0: case MENUMOD_ITEM_ALAM1: case MENUMOD_ITEM_ALAM2: case MENUMOD_ITEM_ALAM3: case MENUMOD_ITEM_ALAM4: case MENUMOD_ITEM_ALAM5: case MENUMOD_ITEM_ALAM6: case MENUMOD_ITEM_ALAM7: case MENUMOD_ITEM_ALAM8: case MENUMOD_ITEM_ALAM9: Watch_Show_Alam(mi-MENUMOD_ITEM_ALAM0); Watch_Adjust_Time(sub, 0); break; } } //++++++++++++++++++++++++++++++++++ //+ Grounp: time + //++++++++++++++++++++++++++++++++++ //--------------------------------- //Function:Watch_Set_ time //--------------------------------- void Watch_Set_Time(char item, char val) { Watch_Display_Time(time); time = Watch_Adjust_Time(item, val); } //--------------------------------- //--------------------------------- void Watch_Save_Time(void) { Writetime(time); } //+++++++++++++++++++++++++++++++++Grounp: Count down++++++++++++++++++++++++++ #if OPT_COUNTER //--------------------------------- //Function: Watch_Set_ count down //--------------------------------- void Watch_Set_Count(char item, char val) { Watch_Display_Time(on_Ct.set); on_Ct.set = Watch_Adjust_Time(item, val); } //--------------------------------- //--------------------------------- void Watch_Start_Count(void) { u32 setV; if(!on_Ct.use) return; setV = TimeToSeconds(on_Ct.set); if(on_Ct.pause) { Watch_Display_Time(SecondsToTime(setV-on_Ct.run)); return; } if(!on_Ct.full) { if(math_Time(time, on_Ct.base)==0) goto COUNT_DISPLAY; on_Ct.run += math_Time(time, on_Ct.base); on_Ct.base = time; if(on_Ct.run>=setV) { on_Ct.run = setV; on_Ct.full = TRUE; STOP_TIMER(e_Timer_Count); START_TIMER(e_Timer_Alam, 30000); } } else { if(IS_TIMEROVER(e_Timer_Alam)) { on_Ct.use = FALSE; on_Ct.full = FALSE; STOP_TIMER(e_Timer_Alam); STOP_TIMER(e_Timer_Count); return; } else { Beeper(TRUE, 300, 500); if(IS_TIMERSTOP(e_Timer_Count)) { START_TIMER(e_Timer_Count, 400); } } } COUNT_DISPLAY: if(IS_TIMEROVER(e_Timer_Count)) { RESET_TIMER(e_Timer_Count); Watch_Display_Time(SecondsToTime(setV-on_Ct.run)); } } void Watch_Save_Count(void) { time = Readtime(); on_Ct.run = 0; on_Ct.sCount = 0; on_Ct.segLeds= 0; on_Ct.full = FALSE; on_Ct.pause = FALSE; on_Ct.use = TRUE; on_Ct.base = time; START_TIMER(e_Timer_Count, 150); } #endif //++++++++++++++++++++++++++++++++++Grounp: Alam++++++++++++++++++++++++++++++++ //--------------------------------- //Function: show the alam time //--------------------------------- void Watch_Show_Alam(char alamID) { u8 s; Alert_t alam; alam = WatchCofing.alart[alamID]; write_DisBuffer(LEDITEM_TEMP_H, LEDWORD_WORDA); write_DisBuffer(LEDITEM_TEMP_L, alamID); s = (u8)(alam.time>>8); write_DisBuffer(LEDITEM_MAIN_1, math_div(s, 10)); //Hour ten write_DisBuffer(LEDITEM_MAIN_2, math_mod(s, 10)); //Hour signed write_DisBuffer(LEDITEM_MAIN_3, LEDWORD_LINE); //"-" s = (u8)(alam.time); write_DisBuffer(LEDITEM_MAIN_4, math_div(s, 10)); //minute ten write_DisBuffer(LEDITEM_MAIN_5, math_mod(s, 10)); //minute signed write_DisBuffer(LEDITEM_MAIN_6, LEDWORD_BLANK); //"." write_DisBuffer(LEDITEM_MAIN_7, alam.begin); write_DisBuffer(LEDITEM_MAIN_8, alam.end); if(alam.on) { write_DisBuffer(LEDITEM_WEEK, LEDWORD_LINE); } else { write_DisBuffer(LEDITEM_WEEK, LEDWORD_BLANK); } Watch_Update_Display(); } //--------------------------------- //Funtion: Watch_Set_ Alam time //--------------------------------- void Watch_Set_Alam(char alamID, char item, char val) { u8 v; Alert_t* alam; TIME alamTime; Watch_Show_Alam(alamID); switch(item) { case 0: setCV(LEDITEM_MAIN_1, val, 0, 2); if(read_DisBuffer(LEDITEM_MAIN_1)==2){ setv(LEDITEM_MAIN_2, val, 0, 3); } break; case 1: if(read_DisBuffer(LEDITEM_MAIN_1)==2){ setCV(LEDITEM_MAIN_2, val, 0, 3); } else { setCV(LEDITEM_MAIN_2, val, 0, 9); } break; case 2: setCV(LEDITEM_MAIN_4, val, 0, 5); break; case 3: setCV(LEDITEM_MAIN_5, val, 0, 9); break; case 4: setCV(LEDITEM_MAIN_7, val, 0, 6); break; case 5: setCV(LEDITEM_MAIN_8, val, 0, 6); break; } WatchCofing.dirty = TRUE; alam = WatchCofing.alart+alamID; alam->on = TRUE; alam->time = (read_DisBuffer(LEDITEM_MAIN_1)*10+read_DisBuffer(LEDITEM_MAIN_2))<<8; alam->time += (read_DisBuffer(LEDITEM_MAIN_4)*10+read_DisBuffer(LEDITEM_MAIN_5)); alam->begin = read_DisBuffer(LEDITEM_MAIN_7); alam->end = read_DisBuffer(LEDITEM_MAIN_8); write_DisBuffer(LEDITEM_WEEK, LEDWORD_LINE); Watch_Update_Display(); } //--------------------------------- //--------------------------------- void Watch_Save_Alam(void) { } //++++++++++++++++++++++++++++++++Grounp: Date+++++++++++++++++++++++++++++++++ //--------------------------------- //Function: set the date //--------------------------------- void Watch_Set_Date(char item, char val) { Watch_Display_Date(date); date = Watch_Adjust_Date(item, val); } //--------------------------------- //--------------------------------- void Watch_Save_Date(void) { Writedaliy(date); } //--------------------------------- //--------------------------------- void Watch_Flash_SetItem(void) { uCHAR i, item; static char scrow = TRUE; if(WatchSet.in.item.adj) { switch(WatchSet.sub) { case 0: item = LEDITEM_MAIN_1; break; case 1: item = LEDITEM_MAIN_2; break; case 2: item = LEDITEM_MAIN_4; break; case 3: item = LEDITEM_MAIN_5; break; case 4: item = LEDITEM_MAIN_7; break; case 5: item = LEDITEM_MAIN_8; break; default: item = LEDITEM_WEEK; break; } if(scrow) { WatchSet.temp = *(dis_buffer+item); *(dis_buffer+item) = LEDWORD_BLANK; } else { *(dis_buffer+item) = WatchSet.temp; } } scrow = !scrow; Watch_Update_Display(); } //--------------------------------- //--------------------------------- void Watch_Init(void) { uCHAR i; MC74HC595_Init(); for(i=0; i<11; i++) { dis_buffer[i] = LEDWORD_LINE; } Watch_Update_Display(); Ds1302_Init(); } 5.5 电子表核心数据结构 typedef struct { uCHAR hour; uCHAR min; uCHAR sec; }TIME; typedef struct { uCHAR year; uCHAR month; uCHAR day; uCHAR week; }DATE; typedef struct { u8 on:1; //响闹开关 u8 begin:6; //响闹周期开始 u8 end; //响闹周期结束 u16 time; //响闹时间 }Alert_t; typedef struct { u8 dirty; u8 leddute; u16 rfaddr; //==================== //Alert Set //==================== Alert_t alart[10]; }WatchCfg_t; typedef struct { u8 enb:1; //闹钟已经打开 u8 inw:1; //闹钟正在运行 u8 id:6; //闹钟编号 u8 cnt; //重复提醒次数 u16 time; //最后一次响闹时间 }Alam_t; #if OPT_COUNTER typedef struct { u8 use:1; u8 full:1; u8 pause:1; u8 sCount:5; u8 segLeds; TIME run; TIME set; TIME base; }Counter_t; #endif typedef struct { union { struct { u8 set:1; //in set statu u8 adj:1; //in adjust statu u8 show:1; //in show alam item or date u8 modify:1; //item is modify }item; u8 items; }in; u8 item; //main set item u8 sub; //sub set item u8 temp; //backup digtal value }WatchSet_t; 5.6 主任务程序 Main.c /* MAIN.C file * * Copyright (c) 2002-2005 STMicroelectronics */ #include "Config.h" DATE date; TIME time; extern volatile _Bool Synch; extern volatile Alam_t on_Alam; #if OPT_COUNTER extern volatile Counter_t on_Ct; #endif extern volatile WatchSet_t WatchSet; extern volatile WatchCfg_t WatchCofing; extern volatile XTIMER Timer[e_Timer_Max]; void memclr(void* src, u8 len) { while(len--){ *((u8*)src+len) = 0x00; } } void RESTART(void) { WWDG_CR |= BIT(7); WWDG_CR &= ~BIT(6); } #if OPT_WATCHDOGDEMON void Watchdog_Init(void) { WWDG_CR &= ~BIT(7); //Stop Window watchdog WWDG_CR = 0x7F; IWDG_KR = 0xCC; //启动IWDG IWDG_KR = 0x55; //解除 PR 及 RLR 的写保护 IWDG_RLR = 0xff; //看门狗计数器重装载数值 IWDG_PR = 0x06; //分频系数为256,最长超时时间为:1.02S IWDG_KR = 0xAA; //刷新IDDG,避免产生看门狗复位,同时恢复 PR 及 RLR 的写保护状态 } #else void Watchdog_Init(void) {_asm("nop"); } #endif /********************************************* 函数功能:系统内部时钟配置 *********************************************/ void Init_SystemClock(void) { //时钟配置为内部RC,16M CLK_CKDIVR &= ~(BIT(4)|BIT(3)); } void Ready(void) { START_TIMER(e_Timer_RunTick, 500); //in 800mS } //_Bool on = FALSE; void doTaskScheduler(void) { static s8 taskID = -1, c=0; Decode_Task(); switch(taskID) { case 0: Beeper_Task(); break; case 1: KeyProcess();//Countflag break; case 2: if(c)Watch_Start_Alam(); break; case 3: Temperature_Task(); break; case 4: ExitMenu(FALSE); break; case 5: #if OPT_COUNTER if(!WatchSet.in.items && on_Ct.use) { Watch_Start_Count(); } break; #endif default: taskID = -1; if(!IS_TIMEROVER(e_Timer_RunTick)) break; RESET_TIMER(e_Timer_RunTick); if(WatchSet.in.items) { if(WatchSet.in.item.adj) { Watch_Flash_SetItem(); } } else { c = 1; date = Readdaliy(); time = Readtime(); #if OPT_COUNTER if(!on_Ct.use) #endif { Watch_Display_Time(time); } } break; } ++taskID; } void InitDeviceConfig(void) { memclr((void*)0, 1024); Load_WatchCofing(); Watch_Init(); //TimerInit(); Key_Init(); Beeper_Init(); Decode_Init(); Temperature_Init(); SystemTimer_Init(); //初始化系统定时器,软定时器时钟源 Watchdog_Init(); _asm("rim"); //开总中断 } int main(void) { Init_SystemClock(); //Init Device Hardware InitDeviceConfig(); Ready(); for(;;) { RESETWDT(); doTaskScheduler(); } } 单帖长度限制,部份代码,后面跟贴附上 六、作品演示 请上传您的作品的功能演示到腾讯视频,并编辑到本楼(或附上视频链接)。按要求上传视频可获得5分,具体详见活动规则。 演示视频: https://v.qq.com/x/page/i0541pw1mvs.html 七、总结 例如您在完成该作品过程中的一些体会、碰到的技术问题或调试经验、作品的未来规划,及对我们主办方的建议和意见等。 小朋友的暑假快结束了,这个项目的时间也所剩无几。因为工作的原因,也因为小朋友磨蹭的原因,这个项目过程中也耽误了不少的时间,只到在距结束不到一周的时间才开始写代码。还好因为这个项目是十多年之前做过的,只需要做一些移植。但是因为电路结构的变化,以前对十年前水平的不满意,还是对代码进行了大手术。在暑假中带孩子完成这个项目还是挺有成就感的。孩子在过程中焊接了全部的电路,而我只做一些指导,进行程序调试。以及明天22号还需要演示,我只负责录象以及视频的剪辑等等。希望通过这样的项目可以让孩子了解并喜欢发明(开发)这个行业。培养他的动手能力等。
想重制的请下载资料:重制资料.rar |
|||
|
发表于2017-06-05 10:10:38
|
只看该作者
2#
欢迎参与! 您已经报名成功! 您现在就可以开始进行设计工作了,后期相关内容请在一楼编辑进行完善。 当前所有参赛选手分值统计表及活动详细介绍见: http://www.szlcsc.com/go/17523dej |
|||
|
发表于2017-06-14 18:25:48
|
只看该作者
3#
>楼主已完成主动传播,恭喜再获5分。 >参赛选手分值统计表及活动详细介绍见:http://www.szlcsc.com/go/17523dej >报名成功后只需在朋友圈发布特定的图文内容即视为主动传播,这就是传说中的“送分题”,详询立创君微信号:LCSCSZ。 |
|||
|
发表于2017-07-14 16:18:41
|
只看该作者
4#
|
|||
|
发表于2017-07-14 16:20:38
|
只看该作者
5#
这是爸爸给我的提纲
|
|||
|
发表于2017-07-14 17:13:11
|
只看该作者
6#
博智小朋友,你很棒哦,加油~
|
|||
|
发表于2017-07-14 18:14:54
|
只看该作者
7#
谢谢叔叔的支持。 |
|||
|
发表于2017-07-18 14:08:22
|
只看该作者
8#
强
|
|||
|
发表于2017-07-18 14:32:37
|
只看该作者
9#
能不能先练好写字
|
|||
|
发表于2017-07-18 16:08:53
|
只看该作者
10#
厉害咯,这字比我写得还好
|
|||
|
发表于2017-07-18 16:09:44
|
只看该作者
11#
强!我十岁的时候还在玩泥巴
|
|||
|
发表于2017-07-18 16:25:36
|
只看该作者
12#
,
|
|||
|
发表于2017-07-19 18:37:04
|
只看该作者
13#
感谢大家的回复。我是孩子爸爸。一直没有时间上来看贴子。板子画好好多天了,一直没有发嘉力创打样。今天终于发出了。 这个小项目也只是给十岁的儿子暑假一些学习之外的工作,让他接触电工这个行业。了解中间的流程,培养下爱好、增加一些暑期的趣味性。电子专业的学生后续也可以能参考下这个小的设计。现在要做的就是从以前版本到现在版本的移植。原来的主芯片是AT4052,现在主芯片是STM8S003。需要好好改改了,估计程序还要花好几天时间来改。当然这些工作只能我来做。小朋友就来打个酱油。让他来参与。小朋友工作的照片附几张给大家评评是不是有范。 画板。只是怎么都走不通。
在立创论坛发贴。 这个我让他把字码到屏上的,一不留神就偷懒就传照片了。是因为电脑装的输入法不够好?毕竟我们电脑都是五笔的,没有好的拼音输入法。
|
|||
|
发表于2017-07-19 18:38:57
|
只看该作者
14#
小朋友的语言组织能力有限,不知道怎么写。所以写个题纲给他。根据题纲写的,也算勉强通畅,只是错别字不少。
|
|||
|
发表于2017-07-19 18:40:39
|
只看该作者
15#
还算工整,孩子的字长大后一定会比我写的好。不,是现在就写得比我好。
|
|||
|
发表于2017-07-20 22:37:42
|
只看该作者
16#
|
|||
|
发表于2017-07-21 21:37:47
|
只看该作者
17#
小朋友字迹工整不少,进步挺大。
|
|||
|
发表于2017-07-22 10:07:18
|
只看该作者
18#
谢谢叔叔的支持。 |
|||
|
发表于2017-07-22 11:44:36
|
只看该作者
19#
485接口电路 硬件接法是可以自动收发的,之前 看过科技老顽童的帖子,就是这个电路。 这个挺好,做485通讯,只需要两个I/O口(TX与RX)就够了,不需要控制脚。 |
|||
|
发表于2017-07-25 16:21:21
|
只看该作者
20#
这是硬件收发自动转换电路,485平常只能工作在半功状态,双功会造成通讯乱码。
|
|||
|
发表于2017-07-25 16:24:53
|
只看该作者
21#
小朋友看你发的这句表扬,乐了大半天。上面全部批评都略过,只看这一句让我们看了好几次。
|
|||
|
发表于2017-07-25 18:17:47
|
只看该作者
22#
|
|||
|
发表于2017-07-29 17:58:48
|
只看该作者
23#
暗光下用电脑 最好开灯哦 不然对视力影响很大 小孩子更应该注意保护视力
|
|||
|
发表于2017-08-04 13:12:16
|
只看该作者
24#
小朋友不错,加油~
|
|||
|
发表于2017-08-07 22:26:57
|
只看该作者
25#
您好,我想咨询一下,您的进度如何,方便透漏一下吗?我挺感兴趣的这个项目。
|
|||
|
发表于2017-08-12 18:20:45
|
只看该作者
26#
|
|||
|
发表于2017-08-12 18:23:06
|
只看该作者
28#
|
|||
|
发表于2017-08-12 18:24:54
|
只看该作者
29#
|
|||
|
发表于2017-08-12 18:30:55
|
只看该作者
30#
现在要开始写程序了。 |
|||
|
发表于2017-08-18 22:32:52
|
只看该作者
31#
抓紧时间,加油!
|
|||
|
发表于2017-08-19 14:00:26
|
只看该作者
32#
我们会加油的! |
|||
|
发表于2017-08-21 22:39:38
|
只看该作者
33#
数码万年历电路及程序,十年前写的,基于89C4052 |
|||
|
发表于2017-08-21 22:58:58
|
只看该作者
34#
|
|||
|
发表于2017-08-21 23:32:31
|
只看该作者
35#
5.7 测温程序 Temperature.c #include "Config.h" // ------------------------------------------------------------ // Welcome you use the NTC Ad Value Calc // Compary: Zhuhai Utronpower .co.ltd // Author :Yijunping // Email :junping1982@163.com // Msn :junping1982@hotmail.com // ------------------------------------------------------------ // NTC B value is 3950 // NTC resistance is 10 KOhm with temperature at 25 C // AD precision is 10Bit // Ntc connect Gnd // ------------------------------------------------------------ //ADCSample.c #if OPT_ADCUSE extern short GetSampleValue(void); extern void ADCSample_Init(void); extern void ADCSample_Task(void); extern volatile XTIMER Timer[e_Timer_Max]; static u8 b_Temp_Init = TRUE; static u8 s_Pos, s_Temps[16] = {0}; static const u16 AD_Result[80] = { 0x363,0x35B,0x353,0x34B,0x342,0x33A,0x331,0x328,0x31F,0x315, 0x30C,0x302,0x2F8,0x2ED,0x2E3,0x2D8,0x2CE,0x2C3,0x2B8,0x2AD, 0x2A1,0x296,0x28B,0x27F,0x274,0x268,0x25C,0x251,0x245,0x23A, 0x22E,0x222,0x217,0x20B,0x200,0x1F5,0x1E9,0x1DE,0x1D3,0x1C8, 0x1BD,0x1B3,0x1A8,0x19E,0x194,0x18A,0x180,0x176,0x16C,0x163, 0x15A,0x150,0x148,0x13F,0x136,0x12E,0x126,0x11E,0x116,0x10E, 0x107,0x100,0xF9,0xF2,0xEB,0xE4,0xDE,0xD8,0xD2,0xCC, 0xC6,0xC1,0xBB,0xB6,0xB1,0xAC,0xA7,0xA2,0x9E,0x99 }; static const char Temp_Value[80] = { -9,-8,-7,-6,-5,-4,-3,-2,-1,0, 1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50, 51,52,53,54,55,56,57,58,59,60, 61,62,63,64,65,66,67,68,69,70 }; void Temperature_Init(void) { ADCSample_Init(); START_TIMER(e_Timer_Temp, 5000); } void Temperature_Task(void) { char t; short v; ADCSample_Task(); if(!IS_TIMEROVER(e_Timer_Temp)) return; v = GetSampleValue(); for(t=0; t<80; t++) { if(AD_Result[t]>v) continue; v = Temp_Value[t]; break; } if(t>=80) { b_Temp_Init = TRUE; return; } if(b_Temp_Init) { s_Pos = 0; b_Temp_Init = FALSE; for(t=0; t<16; t++) { s_Temps[t] = (char)v; } } else { s_Temps[s_Pos++] = (char)v; if(s_Pos>15) s_Pos = 0; } } char Temperature_Read(void) { char t; s16 sum = 0; //未初始化返回3位数的一个错误 if(b_Temp_Init) return 100; for(t=0; t<16; t++) { sum += s_Temps[t]; } return (char)(sum>>4); } #else void Temperature_Init(void) {_asm("nop"); } void Temperature_Task(void) {_asm("nop"); } char Temperature_Read(void) { return 100; } #endif |
|||
|
发表于2017-08-21 23:42:47
|
只看该作者
37#
5.9 DS1302驱动 DS1302.C #include "Config.h" #define EnbWP() WriteBrust(REG_WRITE_WP, 0x80) #define DisenbWP() WriteBrust(REG_WRITE_WP, 0x00) //------------------------------------ //Function: Write the select registal //------------------------------------ static void WriteBrust(uCHAR Reg,uCHAR Data) { uCHAR i; Reg &= 0xfe;//Write opertion clr_bit(PORT_DS_CLK, BIT_DS_CLK); set_bit(PORT_DS_CE, BIT_DS_CE); Delay_us(5); //Write Register for(i = 0; i < 8; i++) { if(Reg & 0x01) { set_bit(PORT_DS_DAT, BIT_DS_DAT); } else { clr_bit(PORT_DS_DAT, BIT_DS_DAT); } Delay_us(2); set_bit(PORT_DS_CLK, BIT_DS_CLK); Delay_us(5); clr_bit(PORT_DS_CLK, BIT_DS_CLK); Delay_us(2); Reg >>= 1; } //Write data for(i = 0; i < 8; i++) { if(Data & 0x01) { set_bit(PORT_DS_DAT, BIT_DS_DAT); } else { clr_bit(PORT_DS_DAT, BIT_DS_DAT); } Delay_us(2); set_bit(PORT_DS_CLK, BIT_DS_CLK); Delay_us(5); clr_bit(PORT_DS_CLK, BIT_DS_CLK); Delay_us(2); Data >>= 1; } clr_bit(PORT_DS_CE, BIT_DS_CE); } //------------------------------------ //Function: read the select registal //------------------------------------ static uCHAR ReadBrust(uCHAR Reg) { uCHAR i,temp; Reg |= 0x01;//Read opertion clr_bit(PORT_DS_CLK, BIT_DS_CLK); set_bit(PORT_DS_CE, BIT_DS_CE); Delay_us(5); //Write Register for(i = 0; i < 8; i++) { if(Reg & 0x01){ set_bit(PORT_DS_DAT, BIT_DS_DAT); } else { clr_bit(PORT_DS_DAT, BIT_DS_DAT); } Delay_us(2); set_bit(PORT_DS_CLK, BIT_DS_CLK); Delay_us(5); clr_bit(PORT_DS_CLK, BIT_DS_CLK); Delay_us(2); Reg >>= 1; } //Read DATA temp = 0x00; set_io_isinput(PORT_DS_DAT, BIT_DS_DAT); Delay_us(5); for(i = 0; i < 8; i++) { temp >>= 1; //Delay_us(5); if(get_bit(PORT_DS_DAT, BIT_DS_DAT)) temp |= 0x80; set_bit(PORT_DS_CLK, BIT_DS_CLK); Delay_us(5); clr_bit(PORT_DS_CLK, BIT_DS_CLK); Delay_us(2); } clr_bit(PORT_DS_CE, BIT_DS_CE); set_io_isoutput(PORT_DS_DAT, BIT_DS_DAT); return temp; } //------------------------------------ //Function: Dec conver to hex //------------------------------------ static uCHAR DecConHex(uCHAR temp) { uCHAR x; //Com(*temp); x = (temp / 10) << 4; x += (temp % 10); return x; } //------------------------------------ //Function: Hex conver to Dec //------------------------------------ static uCHAR HexConDec(uCHAR temp) { uCHAR x; //Com(*temp); x = ((temp >> 4) & 0x0f); x = (x<<3)+(x<<1); //* 10; x += (temp & 0x0f); return x; } //------------------------------------ //Function: Write time //------------------------------------ void Writetime(TIME Source) { DisenbWP(); WriteBrust(REG_WRITE_HOUR, DecConHex(Source.hour)); WriteBrust(REG_WRITE_MINTER, DecConHex(Source.min)); WriteBrust(REG_WRITE_SECOND, DecConHex(Source.sec)); EnbWP(); } //------------------------------------ //Function: write daliy //------------------------------------ void Writedaliy(DATE Source) { DisenbWP(); WriteBrust(REG_WRITE_YEAR, DecConHex(Source.year)); WriteBrust(REG_WRITE_MONTH, DecConHex(Source.month)); WriteBrust(REG_WRITE_DAY, DecConHex(Source.day)); WriteBrust(REG_WRITE_WEEK, Source.week); EnbWP(); } //------------------------------------ //Function:Write alam time //------------------------------------ void WriteAlamtime(TIME Source, char alamID) { uCHAR alamBase; if(alamID>10) return; DisenbWP(); alamBase = RAM_WRITE_ALERT0 + (alamID<<2)+(alamID<<1); //alamID*6 WriteBrust(alamBase, DecConHex(Source.hour)); WriteBrust(alamBase + 2, DecConHex(Source.min)); WriteBrust(alamBase + 4, DecConHex(Source.sec)); EnbWP(); } //------------------------------------ //Function: read time //------------------------------------ TIME Readtime(void) { TIME time; EnbWP(); time.hour = HexConDec(ReadBrust(REG_READ_HOUR)); time.min = HexConDec(ReadBrust(REG_READ_MINTER)); time.sec = HexConDec(ReadBrust(REG_READ_SECOND)); return time; } //------------------------------------ //Function: read daliy //------------------------------------ DATE Readdaliy(void) { DATE date; EnbWP(); date.year = HexConDec(ReadBrust(REG_READ_YEAR)); date.month = HexConDec(ReadBrust(REG_READ_MONTH)); date.day = HexConDec(ReadBrust(REG_READ_DAY)); date.week = ReadBrust(REG_READ_WEEK); return date; } //------------------------------------ //Function: read time //------------------------------------ TIME ReadAlamtime(char alamID) { TIME time; uCHAR alamBase; if(alamID>10) return; EnbWP(); alamBase = RAM_WRITE_ALERT0 + (alamID<<2)+(alamID<<1); //alamID*6 time.hour = HexConDec(ReadBrust(alamID)); time.min = HexConDec(ReadBrust(alamID + 2)); time.sec = HexConDec(ReadBrust(alamID + 4)); return time; } //------------------------------------ //Function: DS1302 Initial //------------------------------------ void Ds1302_Init(void) { TIME time; DATE date; set_io_isoutput(PORT_DS_CE, BIT_DS_CE); set_io_isoutput(PORT_DS_DAT, BIT_DS_DAT); set_io_isoutput(PORT_DS_CLK, BIT_DS_CLK); set_io_pushpull(PORT_DS_CE, BIT_DS_CE); set_io_pushpull(PORT_DS_DAT, BIT_DS_DAT); set_io_pushpull(PORT_DS_CLK, BIT_DS_CLK); set_bit(PORT_LED_CLK, BIT_LED_CLK); clr_bit(PORT_LED_LOAD, BIT_LED_LOAD); time = Readtime(); date = Readdaliy(); DisenbWP(); WriteBrust(REG_WRITE_SECOND, 0x80|time.sec);//pause WriteBrust(REG_WRITE_TRICK, 0x00);//Disable Change if((date.year==0)&&(date.month==1)&&(date.day==1)) { //Update to Init Date, 2017/08/01/W2 date.year = 17; date.month = 8; date.day = 1; date.week = 2; Writedaliy(date); //Update to Init TIme, 12:00:00 time.hour = 12; time.min = 0; time.sec = 0; Writetime(time); } else { WriteBrust(REG_WRITE_SECOND, time.sec);//start } EnbWP(); } 5.10 算法库(主要是节省程序代码空间)Math.c #include "Config.h" #if OPT_COUNTER u32 TimeToSeconds(TIME t) { u32 s = 0; s = math_mux(t.hour,3600)+math_mux(t.min,60)+t.sec; //s = (t.hour<<16)+(t.min<<8)+t.sec; return s; } TIME SecondsToTime(u32 s) { TIME t; t.hour = math_div(s, 3600); s = math_mod(s, 3600); t.min = math_div(s, 60); s = math_mod(s, 60); //t.hour = (uCHAR)(s>>16); //t.min = (uCHAR)(s>>8); t.sec = (uCHAR)s; return t; } u8 math_div(u32 s, u16 c) { return (u8)(s/c); } u8 math_mod(u32 s, u16 c) { return s%c; } u32 math_mux(u8 s, u16 c) { return (u32)s*c; } u32 math_Time(TIME a, TIME b) { u32 aV, bV; aV = TimeToSeconds(a); bV = TimeToSeconds(b); if(bV>=aV) return 0; return aV-bV; } #else u8 math_div(u8 s, u16 c) { return (u8)(s/c); } u8 math_mod(u8 s, u16 c) { return s%c; } u32 math_mux(u8 s, u16 c) { return (u32)s*c; } #endif |
|||
|
发表于2017-08-22 17:10:43
|
只看该作者
38#
有收获的就好啊
|
|||
|
发表于2017-08-22 20:13:02
|
只看该作者
39#
谢谢!
|
|||
|
发表于2017-08-22 22:22:29
|
只看该作者
40#
项目已经完成,公开了部份原代码,上传了重制资料,以及十年前基于AT89C4052芯片的源代码。请在相关楼层下载
|
|||
|
发表于2017-08-26 13:52:21
|
只看该作者
41#
恭喜楼主获得了第二届立创商城电子制作节入围奖,虽然距离30强还有些小差距,30强&入围奖名单:http://club.szlcsc.com/article/details_8910_1.html
但到明年的第三届电子制作节,带上您更成熟的作品参赛时,也许就能一举夺冠了呢,现在,有众多优秀作品让你参考,投票:http://club.szlcsc.com/article/details_8913_1.html |
|