bool superTest() { int i, j; uint16_t a1; uint8_t numb, datas[9]; a1 = EE241_Test(); if (a1 != ERR_OK) return FALSE; //faz o teste da escrita de string a1 = EE241_WriteBlock(0x076, (uint8_t*) "076 Ting", sizeof("076 Ting")); if (a1 != ERR_OK) return FALSE; a1 = EE241_ReadBlock(0x076, datas, sizeof(datas)); if (a1 != ERR_OK) return FALSE; if (strcmp((char*) "076 Ting", (char*) datas) != 0) return FALSE; //faz o teste de todos os 1's em todos as posições da memória for (i = 0; i < 2048; i++) { //todas as posições da memória for (j = 1; j <= 128; j *= 2) { //todos os valores do walking 1's test a1 = EE241_WriteByte(i, j); //(1,2,4,8,32,64,128,256...) if (a1 != ERR_OK) return FALSE; a1 = EE241_ReadByte(i, &numb); if (numb != j) return FALSE; } } return TRUE; }
void LeMemoria(uint16_t n) { extern uint8_t valores[2048]; uint16_t d; for (d = 0; d < n; d += 3) { while (valores[0] == 0 || valores[1] == 0) { EE241_ReadBlock(d, valores, 3); WAIT1_Waitms(1); } if (d + 3 < n) { shiftRight(valores, 2048, 3); valores[0] = valores[1] = valores[2] = 0; } } }
void do_memory_with_sensor() { if (test_memory()) send_string("Ok - Memoria"); else send_string("Erro - Memoria"); while(!read_keys()); int restart = 0; char button_pressed; for(;;) { send_cmd(0x1, 26); send_string("6 para iniciar..."); /* Espera botao 6 */ while (restart == 0 && read_keys() != '6'); send_cmd(0x1, 26); send_string("Grav. iniciada."); /* Variaveis de contagem. */ float sum = 0, min = 5000, max = 0; int count = 0; EE241_Address initial_address = 0; /* Amostragem dos valores. */ while (read_keys() != '7') { uint16_t tension = getDigitalTension(); float tension_f; union Temperatura temp; /* Transforma a tensao em temperatura */ tension_f = (float)tension * 3300/65536; temp.temp_as_float = (tension_f - 600)/10; EE241_WriteBlock(initial_address, temp.temp_as_bytes, sizeof(float)); temp.temp_as_float = 0; /* Conferir resultado. */ memset(temp.temp_as_bytes, 0, sizeof(float)); EE241_ReadBlock(initial_address, temp.temp_as_bytes, sizeof(float)); /* Atualiza contadores */ sum += temp.temp_as_float; initial_address += sizeof(float); count++; /* Atualiza maximo e minimo */ if (temp.temp_as_float > max) max = temp.temp_as_float; if (temp.temp_as_float < min) min = temp.temp_as_float; /* Espera 1s; */ //wait_n_interruptions(16667); wait_n_interruptions(1667); } send_cmd(0x1, 26); send_string("Grav. finalizada."); restart = 0; while (!restart) { button_pressed = read_keys(); if (button_pressed == '6') restart = 1; /* Media, minimo ou maximo */ if (button_pressed == '3' || button_pressed == '4' || button_pressed == '5') { float data_print; char *text; char buffer[6]; memset(buffer, 0, 6); /* Seleciona valor a ser impresso */ if (button_pressed == '3') { data_print = sum/count; text = "Media = "; } else if (button_pressed == '4') { data_print = max; text = "Max. = "; } else { data_print = min; text = "Min. = "; } /* Calcula parte decimal da temperatura */ float decimal = data_print - (int) data_print; /* Imprime resultado com duas casas decimais. */ sprintf(buffer, "%d.%02d", (int) data_print, (int) (decimal * 100)); /* Manda para o LCD. */ send_cmd(0x1, 26); send_string(text); send_string(buffer); } /* Imprimir posicoes de memoria */ if (button_pressed == '8') { /* Imprime primeira posicao. */ union Temperatura temp; char buffer_data[6], buffer_address[6]; memset(buffer_data, 0, 6); memset(buffer_address, 0, 6); EE241_Address aux_address = 0x0; temp.temp_as_float = 0; memset(temp.temp_as_bytes, 0, sizeof(float)); EE241_ReadBlock(aux_address, temp.temp_as_bytes, sizeof(float)); float decimal = temp.temp_as_float - (int) temp.temp_as_float; sprintf(buffer_data, "%d.%02d", (int) temp.temp_as_float, (int) (decimal * 100)); sprintf(buffer_address, "0x%x", aux_address); send_cmd(0x1, 26); send_string(buffer_address); send_string(" - "); send_string(buffer_data); /* Imprime circularmente posicoes ate # for pressionado. */ do { button_pressed = read_keys(); if (button_pressed == '*') { /* Avanca na memoria */ aux_address += sizeof(float); if (aux_address >= initial_address) aux_address = 0; /* Le float da memoria. */ temp.temp_as_float = 0; memset(temp.temp_as_bytes, 0, sizeof(float)); EE241_ReadBlock(aux_address, temp.temp_as_bytes, sizeof(float)); /* Controi strings para impressao. */ float decimal = temp.temp_as_float - (int) temp.temp_as_float; sprintf(buffer_data, "%d.%02d", (int) temp.temp_as_float, (int) (decimal * 100)); sprintf(buffer_address, "0x%x", aux_address); /* Imprime posicao atual de memoria. */ send_cmd(0x1, 26); send_string(buffer_address); send_string(" - "); send_string(buffer_data); } } while (button_pressed != '#'); } } } }