void main() { byte sec; byte min; byte hrs; byte day; byte month; byte year; byte dow; ds1307_init(); /*ds1307_set_date_time(13,6,13,4,01,20,10); // used to set time for first time //13-Jun-2013-Thursday-01-20-10 delay_ms(1000);*/ while(True) { ds1307_get_date(day,month,year,dow); ds1307_get_time(hrs,min,sec); printf("\%02d,\%02d,\%02d \r\n",day,month,year); printf("\%02d,\%02d,\%02d \r\n",hrs,min,sec); delay_ms(1000); } }
int main() { int year=0, month=0, date=0, hour=0, minute=0, second=0, day=0; printf("----------DS1307----------\n\n"); if(!ds1307_init()) { printf("ds1307 init ERROR!\n"); return 1; } year = ds1307_get_year(); month = ds1307_get_mon(); date = ds1307_get_date(); hour = ds1307_get_hour(); minute = ds1307_get_min(); second = ds1307_get_sec(); day = ds1307_get_day(); printf("%d-%d-%d %d:%d:%d day%d \n",year,month,date,hour,minute,second,day); ds1307_end(); return 0; }
static int set_userport_rtc_enabled(int value, void *param) { int val = value ? 1 : 0; if (userport_rtc_ds1307_enabled == val) { return 0; } if (val) { ds1307_context = ds1307_init("USERDS1307"); userport_rtc_list_item = userport_device_register(&rtc_device); if (userport_rtc_list_item == NULL) { return -1; } ds1307_set_data_line(ds1307_context, 1); ds1307_set_clk_line(ds1307_context, 1); } else { if (ds1307_context) { ds1307_destroy(ds1307_context, ds1307_rtc_save); ds1307_context = NULL; } userport_device_unregister(userport_rtc_list_item); userport_rtc_list_item = NULL; } userport_rtc_ds1307_enabled = val; return 0; }
void main(main){ enable_interrupts( GLOBAL ); //enable_interrupts( INT_RDA ); // enable_interrupts( INT_RTCC ); // setup_adc(ADC_CLOCK_INTERNAL); //configura el converso setup_adc(ADC_CLOCK_DIV_32); setup_adc_ports(ALL_ANALOG); ds1307_init (); ///se inicializa el ds1307 delay_ms(1000); SET_TRIS_A( 0xFF ); //ds1307_set_date_time (9, 9, 14, 21, 22, 28, 10); /// se escribe en el displositivo fprintf(COM_int,"Hola Mundo"); while(true){ ds1307_get_date (day, month, yr, dow); /// se obtiene la fecha ds1307_get_time (hrs, min, sec); /// se obtiene la hora // fprintf(COM_int,"AT$MSGSND=4,\""); // fprintf(COM_int, "20%d%02d%02d, %d, %d, %d\"\n\r", yr, month, day, hrs, min, sec); set_adc_channel(0); valor=read_adc(); delay_ms(10); set_adc_channel(1); valor1=read_adc(); delay_ms(10); set_adc_channel(2); valor2=read_adc(); delay_ms(10); set_adc_channel(3); valor3=read_adc(); delay_ms(10); set_adc_channel(4); valor4=read_adc(); delay_ms(10); set_adc_channel(5); valor5=read_adc(); delay_ms(10); fprintf(COM_int, "#PT01,20%d%02d%02d,%02d%02d%02d,%Lu,%Lu,%Lu,%Lu,%Lu,%Lu,000,999$\"\n\r"yr,month, day, hrs, min, sec, valor, valor1, valor2, valor3, valor4, valor5); output_high(pin_c1); delay_ms(1000); output_low(pin_c1); delay_ms(1000); } }
int main (void) { if (i2c_open()<0) { printf("Apertura del bus I2C fallita\n"); return 1; } ds1307_init(); input_data(); set_data(giorno_in,mese_in,anno_in); printf("Data sul DS1307: %d/%d/%d\r\n",read_day(),read_month(),read_year()); input_ora(); set_ora(ora_in,minuto_in); while (1){ printf("Data sul DS1307: %02X/%02X/%02X\r\n", read_day(), read_month(), read_year()); printf("Ora sul DS1307: %02X:%02X:%02X\r\n",read_hour(),read_min(),read_sec()); sleep(10); } return 1; }
void init(void) { //in outputs intit //minutenleds + alarmLed //setze bit 1 =Ausgang DDRB |= (1 << 1); DDRB |= (1 << 3); DDRB |= (1 << 4); DDRB |= (1 << 5); DDRC |= (1 << 3); //AlarmLED // setze pin auf vdd = LED aus PORTB |= (1 << 1); PORTB |= (1 << 3); PORTB |= (1 << 4); PORTB |= (1 << 5); PORTC |= (1 << 3); //AlarmLED //Buzzer als Ausgang setzen und auf +5V schalten = ausgeschaltet DDRB |= (1 << 2); PORTB |= (1 << 2); //Mosfet als Ausgang und ausschalten DDRC |= (1 << 1); PORTC |= (1 << 1); //Matrix leeren PORTC &= ~(1 << 1); //Mosfet anschalten for (uint8_t i = 0; i <= 111; i++) { matrix[i].r = 0; matrix[i].g = 0;//TODO: evtl den gesamten BLock nach vorne verschieben matrix[i].b = 0; //War geplant damit am anfang erst einmal dunkel } ws2812_setleds(matrix, 111); PORTC |= (1 << 1); //init ds1307 ds1307_init(); }
void main() { //initialize data var_init(); //initialize timers and cp1 interrupt setup_timer_1(T1_INTERNAL | T1_DIV_BY_2); //div 2 - 26.2 ms overflow setup_ccp1(CCP_CAPTURE_FE); //with 819.2 us overflow for Timer0, motor's speed must be at least 20 RPS setup_timer_0(T0_INTERNAL | T0_DIV_16); //div 16 - 819.2 us overflow //enable interrupts enable_interrupts(INT_RB2|INT_RB3|INT_RB4|INT_RB5);; enable_interrupts(INT_EXT); enable_interrupts(INT_TIMER1); enable_interrupts(INT_CCP1); enable_interrupts(INT_TIMER0); enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); //initialize clock ds1307_init(); //test power on rgb_bits.blue = 0xF00F; rgb_bits.red = 0x0F0F; rgb_bits.green = 0x00FF; latch_write(rgb_bits.blue, rgb_bits.red, rgb_bits.green); //get the first values of date, time ds1307_get_time(hour, min, sec); ds1307_get_date(day, month, year, dow); // calculating hour hand's position for analog clock anal_hour = hour % 12; anal_hour = anal_hour * 5; anal_hour = anal_hour + (int8)(min / 12); // calculating hour, minute, day, month numbers to display in digital clock hour_h = (int8)(hour / 10); hour_l = hour % 10; min_h = (int8)(min / 10); min_l = min % 10; day_h = (int8)(day / 10); day_l = day % 10; month_h = (int8)(month / 10); month_l = month % 10; // main routine while(true) { // rs232 operation if (rs232_status == 11) { //notify the RS232 transmission for date, time update is successful latch_write(0x0000, 0x0FF0, 0x0000); rs232_status = 0; ds1307_set_date_time(day, month, year, dow, hour, min, sec); putc('O'); delay_ms(100); putc('K'); delay_ms(100); latch_ClearAll(); } // get the time value from ds1307 after each 5 minutes if(tick == 300) { ds1307_get_time(hour, min, sec); ds1307_get_date(day, month, year, dow); anal_hour = hour % 12; anal_hour = anal_hour * 5; anal_hour = anal_hour + (int8)(min / 12); tick = 1; } // change values of minute and hour at appropriate value of second and minute if(sec > 59) { sec = 0; min++; if(min > 59) { min = 0; ds1307_get_time(hour, min, sec); anal_hour = hour % 12; anal_hour = anal_hour * 5; anal_hour = anal_hour + (int8)(min / 12); } //refresh value for digital clock after each minute hour_h = (int8)(hour / 10); hour_l = hour % 10; min_h = (int8)(min / 10); min_l = min % 10; } //display routine if(circle_trigger == 1) { circle_trigger = 0; if ((smode % 2) == 1) latch_ClearAll(); digit_sec++; section_trigger = 1; section_count = MAX_SECTION; section_timer = 256 - (int8)(sigHall_timer / (MAX_SECTION * 8)) + tuning; while(circle_trigger == 0 && section_count > 0) { if(section_trigger == 1) { set_timer0(section_timer); section_trigger = 0; //data calculation fetch_data(); //shifting data latch_write(rgb_bits.blue, rgb_bits.red, rgb_bits.green); //smode change between continuous display and discrete display if ((smode % 2) == 1 && section_count > 1) latch_ClearAll(); section_count--; } } }// circle_trigger } // end of while(true) }
int main(void) { lcd_init(); ds1307_init(); adc_init(); timer_init(); asm("sei"); /* //test lcd_str("Hello, World"); lcd_gotoxy(1,0); lcd_str("by shtomik"); _delay_ms(1000); lcd_clr(); lcd_str("after clr");*/ start_t(); //test ds1307_setdate(12, 12, 31, 23, 01, 35); //смонтировать microSD res = pf_mount(&fs); if(res == FR_OK) { //диск смонтирован и мы продолжаем работу if(pf_open("test.txt") == FR_OK) { //открыли файл в корне test.txt //... pf_lseek(0); //заполняем буффер, надо набрать 512 байт инфы и писать //иначе будет много лишних пробелов //sprintf(buff, "%s\n%s", "Hello,World!", "by_sht"); //записываем его на карту pf_write(buff, 512, &br); //финализируем запись pf_write(NULL, 0, &br); pf_lseek(512); pf_write(buff, 512, &br); //финализируем запись pf_write(NULL, 0, &br); lcd_clr(); lcd_str("ok"); } else { //file not found or ... lcd_str("file not found"); } //демонтируем диск передав функции нулевой указатель pf_mount(NULL); lcd_clr(); lcd_str("file write"); } else { //не удалось смонтировать диск lcd_clr(); lcd_str("not flash"); } while( 1 ) { ; } return 0; }
main() { ds1307_init(); // Set date for -> 15 June 2005 Tuesday // Set time for -> 15:20:55 //ds1307_set_date_time(18,11,12,2,22,05,55); setup_adc(ADC_CLOCK_INTERNAL); //enables the a/d module set_adc_channel(0); //the next read_adc call will read channel 0 delay_us(10); //a small delay is required after setting the channel //aguarda 100ms delay_ms(100); //inicializa o display LCD inic_display(); while (true) { switch(tela){ case 0: display(0,0x01); update_clock(); read_temperature(); check_temperature(); show_temperature(); show_clock(); if(tecla_set_status && !tecla_menos_status && tecla_mais_status) tela = 2; if(tecla_set_status && tecla_menos_status && !tecla_mais_status) tela = 1; break; case 1: read_temperature(); configure_temperature(); break; case 2: //update_clock(); configure_time(); break; } //alterna o estado do pino D4 //output_toggle(PIN_D1); verifica_teclas(); //aguarda 500ms delay_ms (100); } }
/************************************************************************ * Main Program ***** Programa Principal * ************************************************************************/ void main() { setup_psp(PSP_DISABLED); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); setup_timer_2(T2_DIV_BY_16,0xFF,16); setup_timer_3(T3_DISABLED|T3_DIV_BY_1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_adc( ADC_OFF ); enable_interrupts(INT_TIMER1); enable_interrupts(INT_TIMER2); enable_interrupts(INT_RDA); enable_interrupts(INT_EXT1); enable_interrupts(global); str_init(print_date); str_init(print_time); set_timer1(0); init_ext_eeprom(); ds1307_init(); glcd_init(ON); readconfig(); draw_sect(); while (1) { if (firstrun==255) { glcd_fillscreen(OFF); glcd_loadscreen(); glcd_showlogo(); delay_ms(1500); menu_mainmenu(); firstrun = 0; write_eeprom(0x00, firstrun); } if (config==1) { menu_mainmenu(); if(UniTemp[0]==0x43) { write_eeprom(0x01, 1); } else if(UniTemp[0]==0x46) { write_eeprom(0x01, 2); } if(UniPres[0]==0x6D) { write_eeprom(0x02, 1); } else if(UniPres[0]==0x50) { write_eeprom(0x02, 2); } if(UniVel[0]==0x4E) { write_eeprom(0x03, 1); } else if(UniVel[0]==0x6B) { write_eeprom(0x03, 2); } else if(UniVel[0]==0x6D) { write_eeprom(0x03, 3); } update_readings(); button = !PRESSED; config=0; } if (uh>40) { twop[0]=":"; guion[0]="-"; spa[0]=" "; str_init(print_time); str_init(print_date); ds1307_get_time(aux_hr,aux_min,aux_sec); ds1307_get_date(aux_day, aux_month, aux_year, aux_dow); itoa(aux_day,10,print_day); itoa(aux_month,10,print_month); itoa(aux_year,10,print_year); switch(aux_dow) { case 0: { print_dow[0] = "D"; break; } case 1: { print_dow[0] = "L"; break; } case 2: { print_dow[0] = "M"; break; } case 3: { print_dow[0] = "I"; break; } case 4: { print_dow[0] = "J"; break; } case 5: { print_dow[0] = "V"; break; } case 6: { print_dow[0] = "S"; break; } } sprintf(print_date,"%s:%s-%s-%s",print_dow,print_day,print_month,print_year); //strcat(print_date,print_dow); //strcat(print_date,twop); //strcat(print_date,print_day); //strcat(print_date,guion); // strcat(print_date,print_month); //strcat(print_date,guion); //strcat(print_date,print_year); if(aop[0]==0x50) { aux_hr=aux_hr-20; } itoa(aux_hr,10,print_hr); itoa(aux_min,10,print_min); strcat(print_time,print_hr); strcat(print_time,twop); strcat(print_time,print_min); if ((aop[0]==0x41)||(aop[0]==0x50)) { strcat(print_time,twop); strcat(print_time,aop); } rcv_td=1; uh=0; } poll_ok(); lightbuttons(); while(bkbhit) { auxi = bgetc(); switch (auxi) { case 0x54: //T { type=1; str_init(string); break; } case 0x50: //P { type=2; str_init(string); break; } case 0x48: //H { type=3; str_init(string); break; } case 0x41: //A { type=4; str_init(string); break; } case 0x57: //W { type=5; str_init(string); break; } case 0x52: //R { type=6; str_init(string); break; } case 0x44: //D { type=7; str_init(string); break; } case 0x4C: //L { type=8; str_init(string); break; } case 0x56: //V { type=9; str_init(string); break; } case 0x42: //B { type=10; str_init(string); break; } } switch (type) { case 1: //Temperatura { if ((auxi!=0x0D)&&(auxi!=0x54)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(tprint); tt = atol(string); if(UniTemp[0]==0x46) { tt = ((tt*9)/5)+320; } strcat(temp_buffer_eeprom,string); eep+=3; sprintf(ttt,"%3.1w",tt); strcat(tprint,ttt); strcat(tprint,UniTemp); strcpy(t2_print,tprint); rcv_t=1; } break; } case 2: //Presion { if ((auxi!=0x0D)&&(auxi!=0x50)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(pprint); pp = atoi32(string); if(UniPres[0]==0x50) { pp = pp*10; sprintf(ppp,"%6.0w",pp); strcat(pprint,ppp); strcat(pprint,UniPres); } else { sprintf(ppp,"%4.1w",pp); strcat(pprint,ppp); strcat(pprint,UniPres); } rcv_p=1; } break; } case 3: //Humedad { if ((auxi!=0x0D)&&(auxi!=0x48)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="%"; str_init(hprint); hh = atol(string); sprintf(hhh,"%2.1w",hh); strcat(hprint,hhh); strcat(hprint,uni); rcv_h=1; } break; } case 4: //Altitud { if ((auxi!=0x0D)&&(auxi!=0x41)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="m"; str_init(aprint); aa = atol(string); sprintf(aaa,"%5.1w",aa); strcat(aprint,aaa); strcat(aprint,uni); rcv_a=1; } break; } case 5: //Clima { if ((auxi!=0x0D)&&(auxi!=0x57)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; ww = atoi(string); rcv_w=1; } break; } case 6: //Probabilidad de lluvia { if ((auxi!=0x0D)&&(auxi!=0x52)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; char uni[]="%"; str_init(pdlprint); ppdl = atol(string); sprintf(pppdl,"%2.0w",ppdl); strcat(pdlprint,pppdl); strcat(pdlprint,uni); rcv_pdl=1; } break; } case 7: //Direccion del viento { if ((auxi!=0x0D)&&(auxi!=0x44)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(dprint); dd = atol(string); switch(dd) { case 0: { dprint[0]="N"; dprint[1]="\0"; break; } case 1: { dprint[0]="N"; dprint[1]="E"; dprint[2]="\0"; break; } case 2: { dprint[0]="E"; dprint[1]="\0"; break; } case 3: { dprint[0]="S"; dprint[1]="E"; dprint[2]="\0"; break; } case 4: { dprint[0]="S"; dprint[1]="\0"; break; } case 5: { dprint[0]="S"; dprint[1]="O"; dprint[2]="\0"; break; } case 6: { dprint[0]="O"; dprint[1]="\0"; break; } case 7: { dprint[0]="N"; dprint[1]="O"; dprint[2]="\0"; break; } } rcv_d=1; } break; } case 8: //Intensidad de luz { if ((auxi!=0x0D)&&(auxi!=0x4C)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; ll = atoi(string); ll = ll*6.3+67; rcv_l=1; } break; } case 9: //Velocidad del viento { if ((auxi!=0x0D)&&(auxi!=0x56)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; str_init(vprint); vv = atoi32(string); if(UniVel[0]==0x6D) { vv = vv * 0.5144; } else if(UniVel[0]==0x6B) { vv = vv * 1.852; } else { } sprintf(vvv,"%4.1w",vv); strcat(vprint,vvv); strcat(vprint,UniVel); rcv_v=1; } break; } case 10: //Bat Status { if ((auxi!=0x0D)&&(auxi!=0x42)) { string[i] = auxi; i++; } if (auxi==0x0D) { i=0; bat1_st = atoi(string); rcv_bat1_st=1; } break; } } if(eep>=9) { update_eeprom(); eep=0; } update_readings(); glcd_update(); //END KBHIT } glcd_update(); //ENDWHILE } //ENDMAIN }