int eeprom_main(int argc, char *argv[]) { if (argc >= 2) { if (!strcmp(argv[1], "start")) eeprom_start(); if (!strcmp(argv[1], "save_param")) eeprom_save(argv[2]); if (!strcmp(argv[1], "load_param")) eeprom_load(argv[2]); if (!strcmp(argv[1], "erase")) eeprom_erase(); if (!strcmp(argv[1], "test")) eeprom_test(); if (0) { /* these actually require a file on the filesystem... */ if (!strcmp(argv[1], "reformat")) eeprom_ioctl(FIOC_REFORMAT); if (!strcmp(argv[1], "repack")) eeprom_ioctl(FIOC_OPTIMIZE); } } errx(1, "expected a command, try 'start'\n\t'save_param /eeprom/parameters'\n\t'load_param /eeprom/parameters'\n\t'erase'\n"); }
/* start the main program */ void main() { UART_Init(9600); UART_TxString("\n\rTest menu Utra x51 v1.1\r\n 1:GPIO Blink\r\n 2:LCD \n\r 3:7-Segment\n\r 4:RTC\n\r 5:EEPROM\n\r 6:ADC\n\r 7:Keypad \n\r Enter option:"); UART_TxString("\n\rReset the board after test is done"); mm_option = UART_RxChar(); while(1) { switch(mm_option) { case '1': gpio_test(); break; case '2': LCD_test(); break; case '3': seg_test(); break; case '4': rtc_test(); break; case '5': eeprom_test(); break; //eeprom case '6': adc_test(); break; case '7': keypad_test();break; default:break; } } }
/* start the main program */ void main() { UART_Init(9600); UART_TxString("\n\rPIC Ultra baord menu v2.0\r\n 1:GPIO Blink\r\n 2:LCD 8-bit \n\r 3:LCD 4-bit\n\r 4:7-Segment\n\r 5:RTC\n\r 6:EEPROM\n\r 7:ADC\n\r 8:Keypad \n\r Enter option:"); UART_TxString("\n\rReset the board after test is done"); mm_option = UART_RxChar(); while(1) { switch(mm_option) { case '1': gpio_test(); break; case '2': LCD_8bit_test(); break; case '3': LCD_4bit_test(); break; case '4': seg_test(); break; case '5': rtc_test(); break; case '6': eeprom_test(); break; //eeprom case '7': adc_test(); break; case '8': keypad_test();break; default:break; } } }
int main( void ) { uint8_t nSensors, i; int16_t decicelsius; uint8_t error; uart_init((UART_BAUD_SELECT((BAUD),F_CPU))); #ifndef OW_ONE_BUS ow_set_bus(&PINA,&PORTA,&DDRA,PA6); #endif sei(); uart_puts_P( NEWLINESTR "DS18X20 1-Wire-Reader Demo by Martin Thomas" NEWLINESTR ); uart_puts_P( "-------------------------------------------" ); nSensors = search_sensors(); uart_put_int( (int)nSensors ); uart_puts_P( " DS18X20 Sensor(s) available:" NEWLINESTR ); #if DS18X20_VERBOSE for (i = 0; i < nSensors; i++ ) { uart_puts_P("# in Bus :"); uart_put_int( (int)i + 1); uart_puts_P(" : "); DS18X20_show_id_uart( &gSensorIDs[i][0], OW_ROMCODE_SIZE ); uart_puts_P( NEWLINESTR ); } #endif for ( i = 0; i < nSensors; i++ ) { uart_puts_P( "Sensor# " ); uart_put_int( (int)i+1 ); uart_puts_P( " is a " ); if ( gSensorIDs[i][0] == DS18S20_FAMILY_CODE ) { uart_puts_P( "DS18S20/DS1820" ); } else if ( gSensorIDs[i][0] == DS1822_FAMILY_CODE ) { uart_puts_P( "DS1822" ); } else { uart_puts_P( "DS18B20" ); } uart_puts_P( " which is " ); if ( DS18X20_get_power_status( &gSensorIDs[i][0] ) == DS18X20_POWER_PARASITE ) { uart_puts_P( "parasite" ); } else { uart_puts_P( "externally" ); } uart_puts_P( " powered" NEWLINESTR ); } #if DS18X20_EEPROMSUPPORT if ( nSensors > 0 ) { eeprom_test(); } #endif if ( nSensors == 1 ) { uart_puts_P( NEWLINESTR "There is only one sensor " "-> Demo of \"DS18X20_read_decicelsius_single\":" NEWLINESTR ); i = gSensorIDs[0][0]; // family-code for conversion-routine DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ); _delay_ms( DS18B20_TCONV_12BIT ); DS18X20_read_decicelsius_single( i, &decicelsius ); uart_put_temp( decicelsius ); uart_puts_P( NEWLINESTR ); } for(;;) { // main loop error = 0; if ( nSensors == 0 ) { error++; } uart_puts_P( NEWLINESTR "Convert_T and Read Sensor by Sensor (reverse order)" NEWLINESTR ); for ( i = nSensors; i > 0; i-- ) { if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, &gSensorIDs[i-1][0] ) == DS18X20_OK ) { _delay_ms( DS18B20_TCONV_12BIT ); uart_puts_P( "Sensor# " ); uart_put_int( (int) i ); uart_puts_P(" = "); if ( DS18X20_read_decicelsius( &gSensorIDs[i-1][0], &decicelsius) == DS18X20_OK ) { uart_put_temp( decicelsius ); } else { uart_puts_P( "CRC Error (lost connection?)" ); error++; } uart_puts_P( NEWLINESTR ); } else { uart_puts_P( "Start meas. failed (short circuit?)" ); error++; } } uart_puts_P( NEWLINESTR "Convert_T for all Sensors and Read Sensor by Sensor" NEWLINESTR ); if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) { _delay_ms( DS18B20_TCONV_12BIT ); for ( i = 0; i < nSensors; i++ ) { uart_puts_P( "Sensor# " ); uart_put_int( (int)i + 1 ); uart_puts_P(" = "); if ( DS18X20_read_decicelsius( &gSensorIDs[i][0], &decicelsius ) == DS18X20_OK ) { uart_put_temp( decicelsius ); } else { uart_puts_P( "CRC Error (lost connection?)" ); error++; } uart_puts_P( NEWLINESTR ); } #if DS18X20_MAX_RESOLUTION int32_t temp_eminus4; for ( i = 0; i < nSensors; i++ ) { uart_puts_P( "Sensor# " ); uart_put_int( i+1 ); uart_puts_P(" = "); if ( DS18X20_read_maxres( &gSensorIDs[i][0], &temp_eminus4 ) == DS18X20_OK ) { uart_put_temp_maxres( temp_eminus4 ); } else { uart_puts_P( "CRC Error (lost connection?)" ); error++; } uart_puts_P( NEWLINESTR ); } #endif } else { uart_puts_P( "Start meas. failed (short circuit?)" ); error++; } #if DS18X20_VERBOSE // all devices: uart_puts_P( NEWLINESTR "Verbose output" NEWLINESTR ); DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ); _delay_ms( DS18B20_TCONV_12BIT ); DS18X20_read_meas_all_verbose(); #endif if ( error ) { uart_puts_P( "*** problems - rescanning bus ..." ); nSensors = search_sensors(); uart_put_int( (int) nSensors ); uart_puts_P( " DS18X20 Sensor(s) available" NEWLINESTR ); error = 0; } _delay_ms(3000); } }
//*********************************************************************** // 主程序 //*********************************************************************** void main(void) { unsigned char qq; // unsigned char adxl_state; unsigned char mmc_state; unsigned char eeprom_state; for (qq=0;qq<0xf0;qq++) { _NOP(); } WDT_Init(); //看门狗设置 // _DINT(); Clock_Init(); //系统时钟设置 delay_ms(100); //延时100ms Port_Init(); //系统初始化,设置IO口属性 GM8125_Init(0); delay_ms(100); DeBug_Print_Str("System Start!\r\n"); TimerA_init(); mmc_state = mmc_test(); if ( mmc_state == 1) { DeBug_Print_Str("MMC Verify Success!\r\n"); cardSize = MMC_ReadCardSize(); SDsizeDisplay(cardSize); SD_File_Create(); } else { DeBug_Print_Str("MMC Verify Failure!\r\n"); } //延时100ms _EINT(); eeprom_state = eeprom_test(); if ( eeprom_state == 1) { DeBug_Print_Str("EEPROM Verify Success!\r\n"); } else { DeBug_Print_Str("EEPROM Verify Failure!\r\n"); } Init_ADXL345(); //初始化ADXL345 devid=Single_Read_ADXL345(0X00); //读出的数据为0XE5,表示正确 if(devid!=0XE5) { DeBug_Print_Str("No ADXL345\r\n"); } else { DeBug_Print_Str("ADXL345 init Success!\r\n"); } while(1) { /* adxl_state = ADXL345_Work(&X_data,&Y_data,&Z_data); if (adxl_state == FALSE) { DeBug_Print_Str("Adxl345 no work!\r\n"); } delay_ms(5); ProcessingData(); delay_ms(5); */ while (0 == ConnectFlag) { gprs_band_rate(); DeBug_Print_Str("GPRS BandRate Set OK!\r\n"); delay_ms(1000); gprs_check_china_mobile(); DeBug_Print_Str("GPRS Check China Mobile OK!\r\n"); delay_ms(1000); ConnectFlag = gprs_connect_server();//while (connect ok) if (1 == ConnectFlag) { DeBug_Print_Str("GPRS Connect Server is OK!\r\n"); LogFlag=0; //登上服务器后将logon标志置零 } else { DeBug_Print_Str("GPRS Connect Server Fail!\r\n"); } delay_ms(1000); } while(1 == ConnectFlag) { DoRcv(); if(LogFlag) { SendData(); } delay_ms(1000); } //delay_ms(1000); } }
uint8_t perform_selftest(bool show_progress, bool jumper_test) { errors = 0; if (!show_progress) { bus_pirate_configuration.quiet = true; } /* Alert the user to perform the required manual operations if needed. */ if (show_progress && jumper_test) { /* Print alert. */ BPMSG1163; BPMSG1251; /* Wait for a character to come in. */ user_serial_read_byte(); } /* Start the test procedure. */ BPMSG1164; /* Check whether AUX0 goes HIGH when requested. */ BP_AUX0 = HIGH; BP_AUX0_DIR = OUTPUT; BPMSG1165; check_result(BP_AUX0, HIGH); BP_AUX0 = LOW; BP_AUX0_DIR = INPUT; /* Check whether the LED line goes HIGH when requested. */ BP_LEDMODE = HIGH; BP_LEDMODE_DIR = OUTPUT; BPMSG1166; check_result(BP_LEDMODE, HIGH); BP_LEDMODE = LOW; /* Check whether the pull-up line goes HIGH when requested. */ BP_PULLUP_ON(); BPMSG1167; check_result(BP_PULLUP, HIGH); /* Check whether the pull-up line goes LOW when requested. */ BP_PULLUP_OFF(); BPMSG1168; check_result(BP_PULLUP, LOW); /* Check whether the regulated voltage line goes HIGH when requested. */ BP_VREG_ON(); bp_delay_ms(PWR_STATE_TEST_DELAY); BPMSG1169; check_result(BP_VREGEN, HIGH); #ifdef BUSPIRATEV4 /* Test the internal EEPROM. */ BPMSG1265; /* Check the I2C flash clock line. */ BPMSG1266; check_result(BP_EE_SCL, HIGH); /* Check the I2C flash data line. */ BPMSG1267; check_result(BP_EE_SDA, HIGH); /* Check the I2C flash WRITE PROTECT line. */ BPMSG1268; check_result(BP_EE_WP, HIGH); /* Performs a more complete EEPROM test. */ BPMSG1269; check_result(eeprom_test(), true); #endif /* BUSPIRATEV4 */ /* ADC check. */ BPMSG1170; /* Turn ADC on. */ ADCON(); #ifdef BUSPIRATEV4 /* Check whether the voltage coming in from the USB port is within range. */ BPMSG1270; perform_adc_test(BP_ADC_USB, V5L, V5H); #endif /* BUSPIRATEV4 */ /* Check whether the +5v rail output is within range. */ BPMSG1171; perform_adc_test(BP_ADC_5V0, V5L, V5H); #ifdef BUSPIRATEV4 /* Test the +5v pull-up line. */ BP_5VPU_ON(); BPMSG1171; bpSP; BPMSG1172; bp_delay_ms(PWR_STATE_TEST_DELAY); perform_adc_test(BP_ADC_VPU, V5L, V5H); BP_5VPU_OFF(); if (jumper_test) { /* * Check whether the +3.3v rail output is within range when measured from * outside the board circuitry, once a jumper wire is manually placed * between the +3.3v rail pin and the ADC input pin. */ BPMSG1174; perform_adc_test(BP_ADC_PROBE, V33L, V33H); } /* * Check whether the +3.3v rail output is within range when measured from * inside the board circuitry. */ BPMSG1173; perform_adc_test(BP_ADC_3V3, V33L, V33H); /* Test the +3.3v pull-up line. */ BP_3V3PU_ON(); BPMSG1173; bpSP; BPMSG1172; bp_delay_ms(PWR_STATE_TEST_DELAY); perform_adc_test(BP_ADC_VPU, V33L, V33H); BP_3V3PU_OFF(); #elif defined(BUSPIRATEV3) if (jumper_test) { /* * Check whether the +5v pull-up output is within range when measured from * outside the board circuitry, once a jumper wire is manually placed * between the +5v pull-up pin and the ADC input pin. */ BPMSG1172; perform_adc_test(BP_ADC_VPU, V5L, V5H); } /* Check whether the +3.3v rail output is within range. */ BPMSG1173; perform_adc_test(BP_ADC_3V3, V33L, V33H); if (jumper_test) { /* * Check whether the +3.3v rail output is within range when measured from * outside the board circuitry, once a jumper wire is manually placed * between the +3.3v rail pin and the ADC input pin. */ BPMSG1174; perform_adc_test(BP_ADC_PROBE, V33L, V33H); } #endif /* BUSPIRATEV4 || BUSPIRATEV3 */ /* Turn ADC off. */ ADCOFF(); /* * Pull all I/O pins HIGH with pull-ups deactivated, and check the pins * state afterwards. */ BPMSG1175; IODIR &= ~ALLIO; IOLAT |= ALLIO; bp_delay_ms(PIN_STATE_TEST_DELAY); perform_pins_state_test(HIGH); /* * Pull all I/O pins LOW with pull-ups active and check the pins state * afterwards. */ BPMSG1176; IOLAT &= ~ALLIO; if (jumper_test) { #ifdef BUSPIRATEV4 BP_3V3PU_ON(); #endif /* BUSPIRATEV4 */ BP_PULLUP_ON(); } bp_delay_ms(PIN_STATE_TEST_DELAY); perform_pins_state_test(LOW); if (jumper_test) { /* * Pull all I/O pins HIGH with pull-ups active and check the pins state * afterwards. */ /* TODO: should this be done without jumpers too? */ BPMSG1177; IODIR |= ALLIO; bp_delay_ms(PIN_STATE_TEST_DELAY); perform_pins_state_test(HIGH); #ifdef BUSPIRATEV4 BP_3V3PU_OFF(); #endif /* BUSPIRATEV4 */ } if (show_progress && jumper_test) { /* * Alert the user to check the LED on/off states, and prompt for a key * to be pressed to continue. */ BP_VREG_ON(); BP_MODELED_ON(); #ifdef BUSPIRATEV4 BP_USBLED_ON(); #endif /* BUSPIRATEV4 */ BPMSG1178; MSG_ANY_KEY_TO_EXIT_PROMPT; user_serial_read_byte(); #ifdef BUSPIRATEV4 BP_USBLED_OFF(); #endif /* BUSPIRATEV4 */ BP_MODELED_OFF(); BP_VREG_OFF(); } bp_reset_board_state(); BPMSG1179; bp_write_dec_byte(errors); BPMSG1180; bus_pirate_configuration.quiet = false; return errors; }