Ejemplo n.º 1
0
//********************************************************************************************************************
//Función que pone a cero el contador de muestras tomadas.
//********************************************************************************************************************
BOOL Reset_CNT_Muestras_Tomadas()
{
    WORD_VAL Resultado;
    BYTE Reintentos = 0;

    Resultado.Val = 0;

    //Escritura del valor a 0
    do
    {
        EEPROM_WriteByte(Resultado.byte.LB, DIR_CNT_MUESTRAS_TOMADAS);
        EEPROM_WriteByte(Resultado.byte.HB, DIR_CNT_MUESTRAS_TOMADAS+1);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(DIR_CNT_MUESTRAS_TOMADAS)!=Resultado.byte.LB)||(EEPROM_ReadByte(DIR_CNT_MUESTRAS_TOMADAS+1)!=Resultado.byte.HB))&&(Reintentos<3));

    //Comprobación final..
    if(Reintentos==3)
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
Ejemplo n.º 2
0
//********************************************************************************************************************
//Función que incrementa en uno, el contador que recoge el total de muestras tomadas, almacenándolo en EEPROM.
//********************************************************************************************************************
BOOL Inc_CNT_Muestras_Tomadas()
{
    WORD_VAL Resultado;
    BYTE Reintentos = 0;

    //Lectura del valor actual e incremento de una unidad.
    Resultado.Val = (WORD)(Read_CNT_Muestras_Tomadas()+1);

    //Actualilzación del valor en memoria.
    do
    {
        EEPROM_WriteByte(Resultado.byte.LB, DIR_CNT_MUESTRAS_TOMADAS);
        EEPROM_WriteByte(Resultado.byte.HB, DIR_CNT_MUESTRAS_TOMADAS+1);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(DIR_CNT_MUESTRAS_TOMADAS)!=Resultado.byte.LB)||(EEPROM_ReadByte(DIR_CNT_MUESTRAS_TOMADAS+1)!=Resultado.byte.HB))&&(Reintentos<3));

    //Comprobación final..
    if(Reintentos==3)
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
Ejemplo n.º 3
0
//********************************************************************************************************************
//Función que pone a cero el contador de veces que el micro se ha despertado.
//********************************************************************************************************************
BOOL Reset_CNT_Despiertes()
{
    WORD_VAL Resultado;
    BYTE Reintentos = 0;

    Resultado.Val = 0;

    //Escritura del valor a 0
    do
    {
        EEPROM_WriteByte(Resultado.byte.LB, DIR_CNT_DESPIERTES);
        EEPROM_WriteByte(Resultado.byte.HB, DIR_CNT_DESPIERTES+1);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(DIR_CNT_DESPIERTES)!=Resultado.byte.LB)||(EEPROM_ReadByte(DIR_CNT_DESPIERTES+1)!=Resultado.byte.HB))&&(Reintentos<3));

    //Comprobación final..
    if(Reintentos==3)
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
Ejemplo n.º 4
0
//********************************************************************************************************************
//Función que incrementa en uno, el contador que recoge las veces que el micro se ha despertado, almacenándolo en EEPROM.
//********************************************************************************************************************
BOOL Inc_CNT_Despiertes()
{
    WORD_VAL Resultado;
    BYTE Reintentos = 0;

    //Lectura del valor actual e incremento.
    Resultado.Val = (WORD)(Read_CNT_Despiertes()+1);

    //Actualización del valor en memoria
    do
    {
        EEPROM_WriteByte(Resultado.byte.LB, DIR_CNT_DESPIERTES);
        EEPROM_WriteByte(Resultado.byte.HB, DIR_CNT_DESPIERTES+1);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(DIR_CNT_DESPIERTES)!=Resultado.byte.LB)||(EEPROM_ReadByte(DIR_CNT_DESPIERTES+1)!=Resultado.byte.HB))&&(Reintentos<3));

    //Comprobación final..
    if(Reintentos==3)
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
Ejemplo n.º 5
0
void naiboard_eeprom_writestatusbyte(uint8_t statusbyte) {
	if (naiboard_eeprom_readstatusbyte() == statusbyte) { // Not updating if not necessary
		printf_P(PSTR("naiboard-eeprom: status byte up-to-date, no update necessary.\n"));
		return;
	}

	printf_P(PSTR("naiboard-eeprom: updating status byte.\n"));
	EEPROM_WriteByte(naiboard_eepromcounter_page, naiboard_eepromcounter_addr, ~statusbyte);

	if (naiboard_eeprom_readstatusbyte() != statusbyte) { // If the read back value is not correct
		printf_P(PSTR("naiboard-eeprom: status byte read back error.\n"));
		naiboard_eeprom_increasecounter();
		// Trying writing again to a different EEPROM byte
		printf_P(PSTR("naiboard-eeprom: updating status byte again.\n"));
		EEPROM_WriteByte(naiboard_eepromcounter_page, naiboard_eepromcounter_addr, ~statusbyte);
	}
}
Ejemplo n.º 6
0
void EEPROM_Erase()
{
	uint16_t var_eepromAddress_u16;

	for(var_eepromAddress_u16=0;var_eepromAddress_u16<C_MaxEepromSize_U16;var_eepromAddress_u16++)
	{
		EEPROM_WriteByte(var_eepromAddress_u16,0xffu); // Write Each memory location with OxFF
	}
}
Ejemplo n.º 7
0
void EEPROM_WriteString(uint16_t var_eepromAddress_u16, char *ptr_stringPointer_u8)
{

	do
	{
		EEPROM_WriteByte(var_eepromAddress_u16,*ptr_stringPointer_u8); //Write a byte from RAM to EEPROM
		ptr_stringPointer_u8++;								//Increment the RAM Address
		var_eepromAddress_u16++;								//Increment the Eeprom Address
	}while(*(ptr_stringPointer_u8-1) !=0);
}
Ejemplo n.º 8
0
void EEPROM_WriteNBytes(uint16_t var_eepromAddress_u16, uint8_t *ptr_ramAddress_u8, uint16_t var_numOfBytes_u16)
{
	while(var_numOfBytes_u16 !=  0)
	{
		EEPROM_WriteByte(var_eepromAddress_u16,*ptr_ramAddress_u8); //Write a byte from RAM to EEPROM
		var_eepromAddress_u16++;					   //Increment the Eeprom Address
		ptr_ramAddress_u8++;						   //Increment the RAM Address
		var_numOfBytes_u16--;					   //Decrement NoOfBytes after writing each Byte
	}
}
Ejemplo n.º 9
0
/* The function is called during DAQ to record the data into the memory*/
void record_ADC_data()
{
	digital_x_axis= ADC_X();
	digital_y_axis= ADC_Y();
	digital_z_axis= ADC_Z();
	int16_t deviation_mean;
	uint8_t deviation_MSB;
	uint8_t deviation_LSB;
	
	/* Condition- if the movement in X-Y plane is greater than the threshold */
	if(digital_x_axis>(Zero_G_XAxis+horizontal_movement_threshold)||digital_x_axis<(Zero_G_XAxis-horizontal_movement_threshold)|| digital_y_axis>(Zero_G_YAxis+horizontal_movement_threshold)||digital_y_axis<(Zero_G_YAxis-horizontal_movement_threshold))
	 {
		 /* Condition- if the count of values recorded is less than the max memory space */
		 if(i<7999)			//CH01- from 499-7999
		 	 {
				PORTC |= 0b00100000; // LED ON
				  
			 	 if(digital_z_axis>One_G_ZAxis)
				  {
					  deviation_mean=digital_z_axis-One_G_ZAxis;
					
				  }
				  else
				  {
					  deviation_mean=One_G_ZAxis-digital_z_axis;
				  }
				  /*CH01 begins*/
				    deviation_LSB = deviation_mean & 0x0F;
				    deviation_MSB = deviation_mean >> 8;
			 	/* digitalInput_ZAxis_Array[i]=digital_z_axis-One_G_ZAxis;
			 	 else
			 	 digitalInput_ZAxis_Array[i]=One_G_ZAxis-digital_z_axis;*/
				 EEPROM_WriteByte(1,i,deviation_LSB);
				 EEPROM_WriteByte(2,i,deviation_MSB);
				 /*CH01 ends*/
			 	 _delay_ms(20);
			 	 i++;
				  
				 PORTC &= 0b11011111; // LED OFF
				 
		 	 }
	 }
Ejemplo n.º 10
0
/***************************************************EEPROM*****************************************
 				Writes and Reads a character to and from EEPROM
*****************************************************TEST*****************************************/
void eeprom_test()
{
	 unsigned char eeprom_address=0x00, write_char = 'X', read_char;
	 
	UART_Printf("Connections SCL->P0.6 SDA->P0.7");
	UART_Printf("Make connections and hit 'k' to test! ");
        while(UART_RxChar()!='k');
	 UART_TxString("\n\rEeprom Write: ");      //Print the message on UART
	 UART_TxChar(write_char);			         //Print the char to be written 
	 EEPROM_WriteByte(eeprom_address,write_char);	// Write the data at memoryLocation	0x00

	 UART_TxString("  Eeprom Read: ");            //Print the message on UART
	 read_char = EEPROM_ReadByte(eeprom_address);	// Read the data from memoryLocation 0x00
	 UART_TxChar(read_char);	
}
/***************************************************EEPROM*****************************************
 				Writes and Reads a character to and from EEPROM
*****************************************************TEST*****************************************/
void eeprom_test()
{	 
    unsigned char eeprom_address = 0x00, write_char = 'X', read_char;

    for(write_char='A';write_char<='Z';write_char++) /* Eeprom Write and read A-Z */
    {
        UART_Printf("\n\rEeprom Write: %c    ",write_char); //Print the message on UART
        EEPROM_WriteByte(eeprom_address, write_char); // Write the data at memoryLocation	0x00


        read_char = EEPROM_ReadByte(eeprom_address);  // Read the data from memoryLocation 0x00
        UART_Printf("Eeprom Read: %c",read_char); //Print the message on UART
    }
    
    while (1);
}
Ejemplo n.º 12
0
//********************************************************************************************************************
//Función que pone al sistema en modo de recuperación de la batería.
//Acciones: Desconexión del modem.
//********************************************************************************************************************
BOOL Activar_Modo_Recuperacion()
{
    BYTE Reintentos = 0;

    //Actualización en memoria del nuevo estado del sistema: Recuperación de batería.
    do
    {
        EEPROM_WriteByte(RECUPERACION, DIR_ESTADO_SISTEMA);
        Reintentos++;
    }
    while((EEPROM_ReadByte(DIR_ESTADO_SISTEMA)!=RECUPERACION)&&(Reintentos<3));

    //Comprobación final..
    if(Reintentos==3)
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
Ejemplo n.º 13
0
//********************************************************************************************************************
//Función que pone al sistema del modo normal de funcionamiento.
//Acciones: Conexión del modem.
//********************************************************************************************************************
BOOL Desactivar_Modo_Recuperacion()
{
    BYTE Reintentos = 0;

    //Actualización en memoria del nuevo estado del sistema: Modo Normal.
    do
    {
        EEPROM_WriteByte(NORMAL, DIR_ESTADO_SISTEMA);
        Reintentos++;
    }
    while((EEPROM_ReadByte(DIR_ESTADO_SISTEMA)!=NORMAL)&&(Reintentos<3));

    //Comprobación final..
    if(Reintentos==3)
    {
        return FALSE;
    }
    else
    {
        return TRUE;
    }
}
/* start the main program */
void main() 
{
   unsigned char eeprom_address=0x00, write_char = 'X', read_char;

  /* Initialize the lcd before displaying any thing on the lcd */
    LCD_Init(4,2,16);												  
 
   while(1)
    {					
	   	   LCD_GoToLine(1);							// Move the cursor to first line
           LCD_DisplayString("Eeprom Write: ");         //Display the message on first line
		   LCD_DisplayChar(write_char);			        //Display the char to be written 
		   EEPROM_WriteByte(eeprom_address,write_char);	// Write the data at memoryLocation	0x00

		   LCD_GoToLine(2);							// Move the cursor to Second line
		   LCD_DisplayString("Eeprom Read: ");          //Display the message on first line
		   read_char = EEPROM_ReadByte(eeprom_address);	// Read the data from memoryLocation 0x00
		   LCD_DisplayChar(read_char);			        //Display the read data 

	  }		

  }
Ejemplo n.º 15
0
//********************************************************************************************************************
//Función que realiza el guardado de la muestra pasada como argumento, en la dirección indicada.
//Se guarda el timestamp asociado a la muestra.
//********************************************************************************************************************
BOOL Guarda_Muestra_EEPROM(SENSORES Muestra, WORD Direccion)
{
    WORD_VAL Medida;
    BYTE Reintentos = 0;
    BYTE Suma = 0;

    //Escritura de la TIMESTAMP///////////////////////
    rtccFechaHora FechaHoraReloj = Lectura_FechaHora_Reloj();
    Reintentos = 0;
    do
    {
        EEPROM_WriteByte(FechaHoraReloj.f.DiaMes, Direccion);
        EEPROM_WriteByte(FechaHoraReloj.f.Mes, Direccion+1);
        EEPROM_WriteByte(FechaHoraReloj.f.Ano, Direccion+2);
        EEPROM_WriteByte(FechaHoraReloj.f.Hora, Direccion+3);
        EEPROM_WriteByte(FechaHoraReloj.f.Minutos, Direccion+4);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(Direccion)!=FechaHoraReloj.f.DiaMes)||(EEPROM_ReadByte(Direccion+1)!=FechaHoraReloj.f.Mes)||
           (EEPROM_ReadByte(Direccion+2)!=FechaHoraReloj.f.Ano)||(EEPROM_ReadByte(Direccion+3)!=FechaHoraReloj.f.Hora)||
           (EEPROM_ReadByte(Direccion+4)!=FechaHoraReloj.f.Minutos))&&(Reintentos<3));
    //Si no se realizó correctamente, salimos.
    if(Reintentos==3){return FALSE;}


    //Escritura de la TEMPERATURA///////////////////////
    Reintentos = 0;
    do
    {
        Medida.Val = (WORD)Muestra.Temperatura;
        EEPROM_WriteByte(Medida.byte.LB, Direccion+5);
        EEPROM_WriteByte(Medida.byte.HB, Direccion+6);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(Direccion+5)!=Medida.byte.LB)||(EEPROM_ReadByte(Direccion+6)!=Medida.byte.HB))&&(Reintentos<3));
    //Si no se realizó correctamente, salimos.
    if(Reintentos==3){return FALSE;}

    //Escritura de la PLUVIOMETRIA/////////////////////
    Reintentos = 0;
    do
    {
        Medida.Val = (WORD)Muestra.Pluviometria;
        EEPROM_WriteByte(Medida.byte.LB, Direccion+7);
        EEPROM_WriteByte(Medida.byte.HB, Direccion+8);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(Direccion+7)!=Medida.byte.LB)||(EEPROM_ReadByte(Direccion+8)!=Medida.byte.HB))&&(Reintentos<3));
    //Si no se realizó correctamente, salimos.
    if(Reintentos==3){return FALSE;}

    //Escritura de la VELOCIDAD DEL AIRE///////////////
    Reintentos = 0;
    do
    {
        Medida.Val = (WORD)Muestra.Vel_Aire;
        EEPROM_WriteByte(Medida.byte.LB, Direccion+9);
        EEPROM_WriteByte(Medida.byte.HB, Direccion+10);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(Direccion+9)!=Medida.byte.LB)||(EEPROM_ReadByte(Direccion+10)!=Medida.byte.HB))&&(Reintentos<3));
    //Si no se realizó correctamente, salimos.
    if(Reintentos==3){return FALSE;}

    //Escritura del NIVEL DEL LA BATERIA///////////////
    Reintentos = 0;
    do
    {
        Medida.Val = (WORD)Muestra.Nivel_Bateria;
        EEPROM_WriteByte(Medida.byte.LB, Direccion+11);
        EEPROM_WriteByte(Medida.byte.HB, Direccion+12);
        Reintentos++;
    }
    while(((EEPROM_ReadByte(Direccion+11)!=Medida.byte.LB)||(EEPROM_ReadByte(Direccion+12)!=Medida.byte.HB))&&(Reintentos<3));
    //Si no se realizó correctamente, salimos.
    if(Reintentos==3){return FALSE;}

    //CHECKSUM: DDMMYYHHMMTTTTPPPPVVVVBBBB + CHK
    Suma = Calcula_Cheksum_Muestra(FechaHoraReloj, Muestra);

    //Escritura de la suma de comprobación CHECKSUM///////////////
    Reintentos = 0;
    do
    {
        EEPROM_WriteByte(Suma, Direccion+13);
        Reintentos++;
    }
    while((EEPROM_ReadByte(Direccion+13)!=Suma)&&(Reintentos<3));
    //Si no se realizó correctamente, salimos.
    if(Reintentos==3){return FALSE;}

    //Si se llegó aquí, es que todo el proceso fué correcto.
    return TRUE;
}
Ejemplo n.º 16
0
static void naiboard_eeprom_writecounter(void) {
	EEPROM_WriteByte(EE_COUNTER_PAGE, EE_COUNTER_PAGEVAL, ~naiboard_eepromcounter_page);
	EEPROM_WriteByte(EE_COUNTER_PAGE, EE_COUNTER_ADDRVAL, ~naiboard_eepromcounter_addr);
}