void main() { byte value,cmd; EEPROM_ADDRESS address; init_ext_eeprom(); do { do { printf("\r\nRead or Write: "); cmd=getc(); cmd=toupper(cmd); putc(cmd); } while ( (cmd!='R') && (cmd!='W') ); printf("\n\rLocation: "); address = gethex(); if(cmd=='R') printf("\r\nValue: %X\r\n",READ_EXT_EEPROM( address ) ); if(cmd=='W') { printf("\r\nNew value: "); value = gethex(); printf("\n\r"); WRITE_EXT_EEPROM( address, value ); } } while (TRUE); }
void main() { //T1CONL=0x30; //T1CONH=0xA0; setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_16); set_timer0(0); led_io=0; enable_interrupts(INT_TIMER0); enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); setup_io_dieukhien(); Speaker_io=0; setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard lcd_init(); delay_ms(10); init_DS1307(); delay_ms(10); init_ext_eeprom(); delay_ms(10); LED_LCD_IO=0; LED_LCD=1; Init_595(); menu_system=0; load_eeprom(); off_all_van(); while(true) { switch_menu(); } }
void eeprom_test() { int8 data; int8 wrote; int32 addr; int16 errors = 0; init_ext_eeprom(); // Fill eeprom with random data. printf("\n\r"); printf("writing"); // comment out for PIC16 srand(0x55); for(addr = 0; addr < EEPROM_SIZE; addr++) { write_ext_eeprom(addr, (int8)rand()); //comment out above and use line below for PIC16 //write_ext_eeprom(addr, 0x88); if((int8)addr == 0) putc('.'); } // Read the eeprom and check for errors. printf("\n\r"); printf("reading"); // comment out for PIC16 srand(0x55); for(addr = 0; addr < EEPROM_SIZE; addr++) { data = read_ext_eeprom(addr); wrote = (int8)rand(); //comment out above and use line below for PIC16 //wrote = 0x88; if(data != wrote) { printf("%lx: read %x, should be %x\n\r", addr, data, wrote); errors++; if(errors >= 10) break; } if((int8)addr == 0) putc('.'); } output_low(EEP_WP); printf("\n\r"); printf("done\n\r"); }
int8 master_macro_aws(int16 step){ int16 addr; int8 macro_cmd[2]; int16 macro_arg[2]; int8 macro_end; --step; addr = macro_address[0] + (step*6); init_ext_eeprom(); // port macro_cmd[0] = read_ext_eeprom(addr); ++addr; macro_arg[0] = read16_ext_eeprom(addr); ++addr; ++addr; // macro macro_cmd[1] = read_ext_eeprom(addr); ++addr; macro_arg[1] = read16_ext_eeprom(addr); ++addr; ++addr; macro_end = read_ext_eeprom(addr); // check basic structure if (macro_cmd[0] == 'P' && macro_cmd[1] == 'M') { RTC_read(); RTC_display(); fprintf(COM_A, "%c%Lu,%c%Lu\r\n", macro_cmd[0], macro_arg[0], // port macro_cmd[1], macro_arg[1]); // macro if (macro_arg[1] > 0 && macro_arg[1] < 17) { play_macro(macro_arg[1], macro_arg[0]); // [1] casts to int8 / [0] = port } } else { cmd_err(); macro_end = 59; } return (macro_end); }
main() { byte value,cmd; EEPROM_ADDRESS address; init_ext_eeprom(); do { do { printf("\r\nRead or Write: "); cmd=getc(); cmd=toupper(cmd); putc(cmd); } while ( (cmd!='R') && (cmd!='W') ); printf("\n\rLocation: "); #if sizeof(EEPROM_ADDRESS)==1 address = gethex(); #else #if EEPROM_SIZE>0xfff address = gethex(); #else address = gethex1(); #endif address = (address<<8)+gethex(); #endif if(cmd=='R') printf("\r\nValue: %X\r\n",READ_EXT_EEPROM( address ) ); if(cmd=='W') { printf("\r\nNew value: "); value = gethex(); printf("\n\r"); WRITE_EXT_EEPROM( address, value ); } } while (TRUE); }
/************************************************************************ * 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 }