void main() { init();//初始化子程序 while(1) { if(aa==10) { aa=0; temp++; if(temp==1000) { temp=0; } bai=temp/100; shi=temp%100/10; ge=temp%10; write_add(23,bai); delay1(10); write_add(24,shi); delay1(10); write_add(25,ge); delay1(10); } bai=read_add(23); delay1(10); shi=read_add(24); delay1(10); ge=read_add(25); delay1(10); display(bai,shi,ge); } }
void i2c() { comm_init(); init_24c02(); while(temp!='#') { temp=_getkey(); if(temp=='&') { while(temp!='$') { temp=_getkey(); write_add(i++,temp); } i=0; } if(temp=='^') { while(read_add(t++)!='$') { printf("%c",read_add(t-1)); } t=0; } } }
int main(int argc, char ** argv) { if (argc<2) { fprintf(stderr, "usage: wcc [path] [memory budget in GB]\n"); exit(-1); } std::string path = argv[1]; long memory_bytes = (argc>=3)?atol(argv[2])*1024l*1024l*1024l:8l*1024l*1024l*1024l; Graph graph(path,atoi(argv[3])); graph.set_memory_bytes(memory_bytes); Bitmap * active_in = graph.alloc_bitmap(); Bitmap * active_out = graph.alloc_bitmap(); BigVector<VertexId> label(graph.path+"/label", graph.vertices); graph.set_vertex_data_bytes( graph.vertices * sizeof(VertexId) ); active_out->fill(); VertexId active_vertices = graph.stream_vertices<VertexId>([&](VertexId i){ label[i] = i; return 1; }); double start_time = get_time(); int iteration = 0; while (active_vertices!=0) { iteration++; printf("%7d: %d\n", iteration, active_vertices); std::swap(active_in, active_out); active_out->clear(); graph.hint(label); active_vertices = graph.stream_edges<VertexId>([&](Edge & e){ if (label[e.source]<label[e.target]) { if (write_min(&label[e.target], label[e.source])) { active_out->set_bit(e.target); return 1; } } return 0; }, active_in); } double end_time = get_time(); BigVector<VertexId> label_stat(graph.path+"/label_stat", graph.vertices); label_stat.fill(0); graph.stream_vertices<VertexId>([&](VertexId i){ write_add(&label_stat[label[i]], 1); return 1; }); VertexId components = graph.stream_vertices<VertexId>([&](VertexId i){ return label_stat[i]!=0; }); printf("%d components found in %.2f seconds\n", components, end_time - start_time); return 0; }
//向地址写n个字节数据,数据存放在指针P指的数组中 unsigned char write_n_add(unsigned char * p,unsigned char address,unsigned char n) { unsigned char i; for(i = 0; i < n; i++) { write_add((address + i),*(p + i)); //write_add(address++,*(p + i)); delay_ms(20);//一定要适当延时,不然写不进去 } return (address + i); }
/*------ 主函数 ------*/ void main() { INIT();//初始化IIC总线 timer_init();//初始化定时器,但不启动 sec=read_add(2);//上电后首先从芯片读取之前数据 if (sec>99)//防止读取错误 sec=0; TR0=1;//开始计时 while(1) { if (write==1)//1s钟到,可以写入 { write_add(2,sec); write=0;//写入后清零 } show_2_number(sec);//刷新 } }
void main() { uchar i,temp; init_24c02(); while(1) { for(i=0;i<=0xfe;i++) { write_add(i,i); delay(10); } for(i=0;i<=0xfe;i++) { temp=read_add(i); } while(1); } }
int main(int argc, char ** argv) { if (argc<3) { fprintf(stderr, "usage: pagerank [path] [iterations] [memory budget in GB]\n"); exit(-1); } std::string path = argv[1]; int iterations = atoi(argv[2]); long memory_bytes = (argc>=4)?atol(argv[3])*1024l*1024l*1024l:8l*1024l*1024l*1024l; Graph graph(path,atoi(argv[4])); graph.set_memory_bytes(memory_bytes); BigVector<VertexId> degree(graph.path+"/degree", graph.vertices); BigVector<float> pagerank(graph.path+"/pagerank", graph.vertices); BigVector<float> sum(graph.path+"/sum", graph.vertices); long vertex_data_bytes = (long)graph.vertices * ( sizeof(VertexId) + sizeof(float) + sizeof(float) ); graph.set_vertex_data_bytes(vertex_data_bytes); double begin_time = get_time(); degree.fill(0); graph.stream_edges<VertexId>( [&](Edge & e){ write_add(°ree[e.source], 1); return 0; }, nullptr, 0, 0 ); printf("degree calculation used %.2f seconds\n", get_time() - begin_time); fflush(stdout); graph.hint(pagerank, sum); graph.stream_vertices<VertexId>( [&](VertexId i){ pagerank[i] = 1.f / degree[i]; sum[i] = 0; return 0; }, nullptr, 0, [&](std::pair<VertexId,VertexId> vid_range){ pagerank.load(vid_range.first, vid_range.second); sum.load(vid_range.first, vid_range.second); }, [&](std::pair<VertexId,VertexId> vid_range){ pagerank.save(); sum.save(); } ); for (int iter=0;iter<iterations;iter++) { graph.hint(pagerank); graph.stream_edges<VertexId>( [&](Edge & e){ write_add(&sum[e.target], pagerank[e.source]); return 0; }, nullptr, 0, 1, [&](std::pair<VertexId,VertexId> source_vid_range){ pagerank.lock(source_vid_range.first, source_vid_range.second); }, [&](std::pair<VertexId,VertexId> source_vid_range){ pagerank.unlock(source_vid_range.first, source_vid_range.second); } ); graph.hint(pagerank, sum); if (iter==iterations-1) { graph.stream_vertices<VertexId>( [&](VertexId i){ pagerank[i] = 0.15f + 0.85f * sum[i]; return 0; }, nullptr, 0, [&](std::pair<VertexId,VertexId> vid_range){ pagerank.load(vid_range.first, vid_range.second); }, [&](std::pair<VertexId,VertexId> vid_range){ pagerank.save(); } ); } else { graph.stream_vertices<float>( [&](VertexId i){ pagerank[i] = (0.15f + 0.85f * sum[i]) / degree[i]; sum[i] = 0; return 0; }, nullptr, 0, [&](std::pair<VertexId,VertexId> vid_range){ pagerank.load(vid_range.first, vid_range.second); sum.load(vid_range.first, vid_range.second); }, [&](std::pair<VertexId,VertexId> vid_range){ pagerank.save(); sum.save(); } ); } } double end_time = get_time(); printf("%d iterations of pagerank took %.2f seconds\n", iterations, end_time - begin_time); }
//////////////////////////////////////////RETSET ///////////////////////// void reset() { write_add(0x07,0x7E); read_add(0xE1); read_add(0xE2); }
/////////////////////////NRF24L01 CONFIG/////////////////////// void nrf24_config() { char add1[5]={'a','a','a','a','a'}; CSN=0; CE=0; delay_ms(20); write_add(0x01,0x3f); write_add(0x02,0x03); write_add(0x03,0x03); write_add(0x04,0x4f); write_add(0x05,0x4c); write_add(0x06,0x07); write_add(0x11,0x20); write_add(0x1C,0x00); write_add(0x1D,0x00); write_add(0x00,0x0f); write_add(0x00,0x0f); delay_ms(5); CSN=1; CE=1; delay_ms(20); //write_buff(0x0a,add1,5); //write_buff(0x10,add1,5); }
void keyscan() { if(k1==0&&flag2!=0) { delay(5); if(k1==0&&flag2!=0) { flag=0; flag2=0; write_com(0x0c); init(); if(num!=0&&TR0==0) ET0=0; } while(k1==0); } if(k1==0) { delay(5); if(k1==0) { flag++; if(flag==1) { init2(); } switch(flag) { case 6 : write_com(0x80+0x40+0x04); break; case 7 : write_com(0x80+0x40+0x07); break; case 8 : write_com(0x80+0x40+0x0a); break; case 2 : init(); write_com(0x80+0x01); write_com(0x0f); break; case 3 : write_com(0x80+0x06); break; case 4 : write_com(0x80+0x09); break; case 5 : write_com(0x80+0x0d); break; case 9 : init3(); break; case 10: write_com(0x80+0x09); break; case 11: flag=0; write_com(0x01); write_com(0x0c); break; } } while(k1==0); } if(k2==0) { delay(5); if(k2==0) { if(flag==1) { if(ET0==0) { min2=0;sec2=0;num=0;secp=0; for(i=0;i<max;i++) { mins[i]=0;secs[i]=0;secps[i]=0; } max=0;ET0=1;flag2++; while(k2==0); } if(TR0==1) { num++; mins[num]=min2; secs[num]=sec2; secps[num]=secp; TR0=0; ET0=0; max=num; flag2++; while(k2==0); } } switch(flag) { case 6 : if(hour<23) hour++; else hour=0; writehour; delay(5); displayhour; write_com(0x80+0x40+0x04); break; case 7 : if(minute<59) minute++; else minute=0;writeminute; delay(5); displayminute; write_com(0x80+0x40+0x07); break; case 8 : if(second<59) second++; else second=0;writesecond; delay(5); displaysecond; write_com(0x80+0x40+0x0a); break; case 2 : year++; writeyear; delay(5); displayyear;write_com(0x80+0x01); break; case 3 : if(month<12) month++; else month=1;writemonth;delay(5); displaymonth; write_com(0x80+0x06); break; case 4 : if(day<31) day++; else day=1; writeday; delay(5); displayday; write_com(0x80+0x09); break; case 5 : if(week<8) week++; else week=2; writeweek;delay(5); displayweek; write_com(0x80+0x0d); break; case 9 : if(ahour<23) ahour++; else ahour=0; displaytwo(6,ahour); write_add(1,ahour); write_com(0x80+0x06); break; case 10: if(amin<59) amin++; else amin=0; displaytwo(9,amin); write_add(2,amin); write_com(0x80+0x09); break; } } while(k2==0); } if(k3==0&flag!=0) { delay(5); if(k3==0&flag!=0) { if(flag==1) { if(ET0==1&&TR0==1) { num++; flag2++; mins[num]=min2; secs[num]=sec2; secps[num]=secp; while(k3==0) { display2(); } } if(ET0==1&&TR0==0) { TR0=1; flag2++; } if(ET0==0) { if(num>1) num--; min2=mins[num]; sec2=secs[num]; secp=secps[num]; flag2++; } } switch(flag) { case 6 : if(hour>0) hour--; else hour=23; writehour;delay(5); displayhour; write_com(0x80+0x40+0x04); break; case 7 : if(minute>0) minute--; else minute=59; writeminute; delay(5); displayminute; write_com(0x80+0x40+0x07); break; case 8 : if(second>0) second--; else second=59; writesecond; delay(5); displaysecond; write_com(0x80+0x40+0x0a); break; case 2 : year--; writeyear; delay(5); displayyear; write_com(0x80+0x01); break; case 3 : if(month>1) month--; else month=12; writemonth; delay(5); displaymonth; write_com(0x80+0x06); break; case 4 : if(day>1) day--; else day=31;writeday; delay(5); displayday; write_com(0x80+0x09); break; case 5 : if(week>1) week--; else week=7;writeweek; delay(5); displayweek; write_com(0x80+0x0d); break; case 9 : if(ahour>0) ahour--; else ahour=23; displaytwo(6,ahour); write_add(1,ahour); write_com(0x80+0x06); break; case 10: if(amin>0) amin--; else amin=59; displaytwo(9,amin); write_add(2,amin); write_com(0x80+0x09); break; } } while(k3==0); } if(k4==0) { delay(5); if(k4==0&&ET1==0&&flag!=0) { if(num<max) num++; min2=mins[num]; sec2=secs[num]; secp=secps[num]; flag2++; } if(k4==0&&flag==0) { write_com(0x01); displaytemp(readtemp()); } } while(k4==0); }