/*******************************************************************************
**函    数: KeyEepromInit
**功    能: 所属 eeprom 初始化
**参    数: unitID      --单元号
**返    回: void
*******************************************************************************/
void KeyEepromInit(u8 unitID)
{
    unitID = unitID;
    //取消密码
    gPassword[0] = 0;
    gPassword[1] = 0;
    gPassword[2] = 0;
    gPassword[3] = 0;
    EEPROM_Write(ADDR_PASSWORD, 4, &gPassword[0]);
    
    gKeyPrevState.KeyType  = KEY_NONE;
    gKeyPrevState.KeyValue = 0xFF;
	memset(gKeyPrevState.KeyStatusVal,0,MAX_TOUCH_KEY);
    EEPROM_Write(ADDR_KEY_CURRENT_STATE,sizeof(KeySta_t),(u8*)&gKeyPrevState);
	
	gAirContionData.PowerSwitch = 0;
    gAirContionData.SetMaxTemp  = 32;
    gAirContionData.SetMinTemp  = 16;
    gAirContionData.SetMode     = AC_MODE_AUTO;
    gAirContionData.SetTemper   = 25;
    gAirContionData.SetWindSpeed= AC_WIND_AUTO;
    gAirContionData.SetWindSweep= 0;


    *(u16*)&(gDeveceRelate.AssistID)  = 0;
    *(u32*)&(gDeveceRelate.ObjectID)  = 0;
    gDeveceRelate.RelateType          = 0;
    gDeveceRelate.UnitNum             = 0;
    gDeveceRelate.UseFlag             = 1;  /*< 默认使能*/
    
    AirCondition_SaveData();
    AirCondition_SaveRelateData();
}
void CopyFlashToEEPROM (void) {
	unsigned char compare;
	unsigned int i;
	
	// Copies the contents of FLASH in Sequences[] to EEPROM
	if (EEPROM_Present()) {
		// Write Sequences data to external EEPROM
		EEPROM_Write(0x0000, (unsigned char *)Sequences, sizeof(Sequences));
		
		// Verify the external EEPROM contents
		for (i=0; i<sizeof(Sequences); i++) {
			compare = EEPROM_ReadChar(i);
			if (compare != Sequences[i]) {
				 Error();
				 return;	// abort	
			}	
		}
		EEPROM_Write(EEPROM_GetSize()-2, MAGIC, 2);	// initialize EEPROM magic number
		
		// Set up internal EEPROM start address and sequence length
		WriteWord(STARTSEQADD, 0x0000);			// enable normal playback		
		WriteWord(TOTALSEQADD, Seq_Count());	// identify how many sequences are defined
		ConfirmCommand();	
	} else {
		Error();
	}			
}
Example #3
0
static
#endif // EEPROM_INCLUDE_BYTE_FUNCS
void EEPROM_WriteWearLeveledByte(const uint16_t param, const uint8_t data) {
  uint16_t address = EEPROM_FindCurrentAddress(param);

  // Only perform the write if the new value is different from what's currently stored
  if (EEPROM_Read(address) == data)
    return;

  // Store the old status value
  uint8_t oldStatusValue = EEPROM_Read(address + EE_PARAM_BUFFER_SIZE);

  // Move pointer to the next element in the buffer, wrapping around if necessary
  if (++address == param + EE_PARAM_BUFFER_SIZE)
    address = param;

  // If self-programming is used in the application, insert code here
  // to wait for any self-programming operations to finish before
  // writing to the EEPROM.

  // Update the param buffer in the EEPROM
  EEPROM_Write(address, data);

  // Update the status buffer in the EEPROM
  EEPROM_Write(address + EE_PARAM_BUFFER_SIZE, oldStatusValue + 1);
}
Example #4
0
/***************************************************************************//**
 * @brief 	Copies the data from the Timer in RAM into its EEPROM address
 * @param   Address            This is the address 
 * @param   Timer_HighScore    This is a pointer to the timer in RAM
 * @return 	None.
 * @date	  14.11.2013 
*******************************************************************************/
void EEPROM_Set_HighScore(unsigned char Address, struct TimerStruct * Timer_HighScore)
{
  EEPROM_Write(Address,Timer_HighScore->Dmin);
  EEPROM_Write(Address + 1,Timer_HighScore->Umin);
  EEPROM_Write(Address + 2,Timer_HighScore->Dsec);
  EEPROM_Write(Address + 3,Timer_HighScore->Usec);
}
Example #5
0
/**
  * @brief  Settings_SaveParam
  * @param  None
  * @retval None
  */
uint8_t Settings_SaveParam(const SettingsParam_TypeDef* param)
{
	uint8_t CS_byte = Settings_U8_CS(*(param->u8_data), param->num_bytes);

	EEPROM_Write((uint8_t*)param->u8_data, param->start_addr, param->num_bytes);
	EEPROM_Write(&CS_byte, param->start_addr + param->num_bytes, 1);

	return err_I2C_flag;
}
Example #6
0
/** function stores calibration table together with magic number and checksum */
static void touch_StoreCalibration(void)
{
  int      count;
  uint32_t temp = CALIBRATION_MAGIC_NUMBER, checksum;
  checksum = touch_CountChecksum(CALIBRATION_MAGIC_NUMBER, (uint32_t*) &calibrationMatrix, sizeof(calibrationMatrix) / 4);
  count    = EEPROM_Write(I2C0, EEPROM_DVK_ADDR, CALIBRATION_EEPROM_OFFSET, (uint8_t*) &temp, sizeof(temp));
  count   += EEPROM_Write(I2C0, EEPROM_DVK_ADDR, CALIBRATION_EEPROM_OFFSET + 4, (uint8_t*) &calibrationMatrix, sizeof(calibrationMatrix));
  count   += EEPROM_Write(I2C0, EEPROM_DVK_ADDR, CALIBRATION_EEPROM_OFFSET + 4 + sizeof(calibrationMatrix), (uint8_t*) &checksum, sizeof(checksum));
}
Example #7
0
static
#endif // EEPROM_INCLUDE_BYTE_FUNCS
uint8_t EEPROM_InitWearLeveledByte(const uint16_t param, const uint8_t data) {
  EEPROM_Write(param + EE_PARAM_BUFFER_SIZE, EE_STATUS_BUFFER_SIZE - 1);

  for (uint8_t i = 1; i < EE_STATUS_BUFFER_SIZE; ++i)
    EEPROM_Write(i + param + EE_PARAM_BUFFER_SIZE, i - 1);

  EEPROM_Write(param, data);
  return data;
}
Example #8
0
//---------------------------------------------------------------
void Calibrate(unsigned char channel_num,float K,float C) //общая функция калибровки
{
		unsigned long true_crc=0;
		channels[channel_num].calibrate.cal.K= K;
		channels[channel_num].calibrate.cal.C= C;
		EEPROM_Write(&channels[channel_num].calibrate.serialize,3,ADC_CALIBRATE_ADDR+channel_num*3);

		true_crc= (unsigned long)Calibrate_Get_CRC();//расчет текущей CRC калибровок
		EEPROM_Write(&true_crc,1,CALIBRATE_DEVICE_CRC_ADDR);//запомним CRC 	

		return;
}
/*
* Entry point
*/
void main() {
  // Variables
  char speedBuf[5] = {0,0,0,0,0};
  char totalBuf[] = {0,0,0,0,0,0,0,0,0,0};
  char empty[] = "                ";
  union eeprom_int totalKm;
  int kph = 1;

  // Initialization
  initialize();
  
  // 0x10 = first byte of the actual int value
  // 0x11 = second byte of the actual int value
  totalKm.memory[0] = EEPROM_Read(KM_ADDR);
  totalKm.memory[1] = EEPROM_Read(KM_ADDR+1);

  // 0xFF is 8 bit, an uint is 2 byte = 16 bit, so we need 0xFFFF
  if(totalKm.value == 0xFFFF) {
    totalKm.value = 0;
  }
  
  do {
    // Reads the value of the RA2 Analog knob.
    adcInput = ADC_Read(2);

    
    if(shouldUpdateSpeedometer == 1) {
      shouldUpdateSpeedometer = 0;
      // Update speedometer LCD here
      speed(speedBuf, adcInput, &kph);
      Lcd_Out(1,1,empty);
      Lcd_Out(1,1,"km/t: ");
      Lcd_Out(1,7,speedBuf);
    }
    
    if(shouldUpdateTotal) {
      shouldUpdateTotal = 0;
      // Update LCD and save total here
      total(totalBuf, &totalKm.value, kph);
      
      EEPROM_Write(KM_ADDR, totalKm.memory[0]);
      EEPROM_Write(KM_ADDR+1, totalKm.memory[1]);
      Lcd_Out(2,1,empty);
      Lcd_Out(2,1, "Total: ");
      Lcd_Out(2,8, totalBuf);
    }
    
  }while(1);
}
/*******************************************************************************
**函    数: KeyEepromInit
**功    能: 所属 eeprom 初始化
**参    数: unitID      --单元号
**返    回: void
*******************************************************************************/
void KeyEepromInit(u8 unitID)
{
    unitID = unitID;
    //取消密码
    gPassword[0] = 0;
    gPassword[1] = 0;
    gPassword[2] = 0;
    gPassword[3] = 0;
    EEPROM_Write(ADDR_PASSWORD, 4, &gPassword[0]);
    
    gKeyPrevState.KeyType  = KEY_NONE;
    gKeyPrevState.KeyValue = 0xFF;
	memset(gKeyPrevState.KeyStatusVal,0,MAX_TOUCH_KEY);
    EEPROM_Write(ADDR_KEY_CURRENT_STATE,sizeof(KeySta_t),(u8*)&gKeyPrevState);
}
void main(){
ADCON1 = 0b00001110;             // HABILITA CANAL AN0 E AN1
TRISA.RA0 = 1;
Lcd_Init ();                     // START LCD
Lcd_Cmd(_Lcd_Clear);             // CLEAR LCD
Lcd_Cmd(_LCD_CURSOR_OFF);        // TURN OFF LCD CURSOR
ADC_Init();
while(1){
adc_rd = ADC_Read(0);                        // GET ADC VALUE FROM 1ST CHANNEL
EEPROM_Write(0x08, adc_rd);       //ESCREVE "adc_rd" NA POSICAO 0x08 DA EEPROM
IntToStr(adc_rd, adcprint);                            // CONVERSION TO STRING
Lcd_out(1,1,"COUNTS..: ");
Lcd_Out_Cp(adcprint);                     // PRINTS ADC STEPS IN LCD FIRST ROW
if (diff != adc_rd){
BarSegmentNum = adc_rd /(1023 / 16);
                                    // CALCULATE NUMBERS OF BAR GRAPH SEGMENTS
Lcd_out(2,1,"                ");    // CLEARS LCD SECOND ROW
for (i = 0; i < BarSegmentNum; i++){
                               // LOOP TO PRINT EACH BAR SEGMENT IN SECOND ROW
CustomChar(2, i+1);}}           // PRINT CUSTOM CHARACTER FOR BARGRAPH SEGMENT
Delay_ms(750);                                        // STABILIZE LCD DISPLAY
diff = adc_rd;
// LCD SHOWS EEPROM VALUE
ADCeer = EEPROM_Read(0x08);                     // LE A POSICAO 0x08 DA EEPROM
ShortToStr (ADCeer, ADCeerSTR);
//Lcd_Cmd(_LCD_CLEAR);                                  // LIMPA A TELA DO LCD
Lcd_Out(2, 1, ADCeerSTR);
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);                                    // LIMPA A TELA DO LCD
}                                                                 // END WHILE
}                                                                  // END MAIN
Example #12
0
void MPU6050_GyroCalibration()
{
    int cycles = 7000;
    int i;
    int32_t x, y, z;
    GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0 );
    Gyro_Offset.X = 0;
    Gyro_Offset.Y = 0;
    Gyro_Offset.Z = 0;
    x = 0;
    y = 0;
    z = 0;
    Update_1000Hz = false;
    for(i = 0 ; i < cycles ; i++)
    {
        while (!Update_1000Hz);
        Update_1000Hz = false;
    	MPU9250_GetGyro();
    	x += Gyro.X;
    	y += Gyro.Y;
    	z += Gyro.Z;
    }
    Gyro_Offset.X = -x / cycles;
    Gyro_Offset.Y = -y / cycles;
    Gyro_Offset.Z = -z / cycles;
    EEPROM_Write();
	BEEP_On();
	Update_5Hz = false;
	while (!Update_5Hz);
	BEEP_Off();
    return ;
}
Example #13
0
void resetBootLoad(){
	addr= getFormatedAddress(ADMINCODE_ADDR);
	printf("reset addr: 0x%X\n",addr);
	s.adminCode 	= 0x03030303;
	s.doorCOde 		= 0x01010101;// codigo 1 1 1 1
	s.nRegist 		= 0;
	s.absRegist		= 0;
	s.checkBootLoad	= 0x69F02ADB;
	s.hr 			= 0;
	s.mm 			= 0;
	s.s 			= 0;
	s.year 			= 0;
	s.month 		= 0;
	s.day 			= 0;
	s.dayWeek 		= 0;
	printf("reset adminCode: 0x%X\n",s.adminCode);
	EEPROM_Write(&addr, &s,sizeof(Settings));
	//test
//	uint16_t addr1= 0;
//	Settings s;
//
//	EEPROM_Read(&addr1, &s,sizeof(Settings));
//
//	uint8_t * bla= (uint8_t*)&s;
//	int i=0;
//	for(i=0; i<48; ++i){
//		printf("Mem[%u]= %X\n",i,*(bla+i));
//	}
}
Example #14
0
/**
  * @brief  SavePreference
  * @param  None
  * @retval None
  */
void Settings_EraseParam(const SettingsParam_TypeDef* param)
{
	uint8_t ErasedData[param->num_bytes + 1];

	memset(ErasedData, 0xFF, param->num_bytes);
	EEPROM_Write(ErasedData, param->start_addr, param->num_bytes);
}
void SP_BT_US1Press() {
                               if(Press>=10)
                               {
                               EEPROM_Write(0x00, StartVoltset);
                               Delay_ms(50);
                               EEPROM_Write(0x01, StepVoltset);
                               Delay_ms(50);
                               EEPROM_Write(0x02, StopVoltset);
                               Delay_ms(50);
                               EEPROM_Write(0x06,PulseRate);
                               Delay_ms(50);
                               EEPROM_Write(0x05, ZapNum);
                               EEPROM_Write(0x04, ZapNum>>8);
                               Delay_ms(50);
                               Press=0;
                               }
/**
    Stores a given int by splitting it into low and high order bits
    and puts them into banks next to each other
    
    @param eepromadrs - the starting address in EEPROM to store the split int
    @param val - the int to be stored
*/
void storeAn3(char eepromadrs, int val)
{
    EEPROM_Write(eepromadrs, val & 0xFF);
    Delay_Ms(5);
    EEPROM_Write(eepromadrs + 1, (val >> 8) & 0xFF);
    Delay_Ms(5);
}
Example #17
0
/***************************************************************************//**
 * @brief 	Write the timer on RAM to the EEPROM
 * @param   None
 * @return 	None
 * @date	  13.11.2013 
*******************************************************************************/
void EEPROM_Write_All_Timers(struct TimerStruct * Timer_HighA, struct TimerStruct * Timer_HighB, struct TimerStruct * Timer_HighC)
{
  EEPROM_Set_HighScore(EEPROM_ADDRESS_1,Timer_HighA);
  EEPROM_Set_HighScore(EEPROM_ADDRESS_2,Timer_HighB);
  EEPROM_Set_HighScore(EEPROM_ADDRESS_3,Timer_HighC);  
  //Set the flag, which means data is into the EEPROM
  EEPROM_Write(EEPROM_ADDRESS_FLAG,WRITTEN_FLAG_SET);
}
Example #18
0
void SaveNumberToEEProm(void)
{
    EEPROM_Write(0x00, MobileNumber[0]);
    EEPROM_Write(0x01, MobileNumber[1]);
    EEPROM_Write(0x02, MobileNumber[2]);
    EEPROM_Write(0x03, MobileNumber[3]);
    EEPROM_Write(0x04, MobileNumber[4]);
    EEPROM_Write(0x05, MobileNumber[5]);
    EEPROM_Write(0x06, MobileNumber[6]);
    EEPROM_Write(0x07, MobileNumber[7]);
}
/*******************************************************************************
**功    能: 设置用户密码
**参    数: *pData      --输入参数
             *rLen       --返回参数长度
             *rData      --返回参数存放地址
**返    回: TRUE/FALSE
********************************************************************************/
MsgResult_t Set_Password_Attr(UnitPara_t *pData)
{
    gPassword[0] = pData->data[0] - '0';
    gPassword[1] = pData->data[1] - '0';
    gPassword[2] = pData->data[2] - '0';
    gPassword[3] = pData->data[3] - '0';
    EEPROM_Write(ADDR_PASSWORD, 4, &gPassword[0]);
    
    return COMPLETE;
}
void VirginCheck(void)
{
   uint8_t cBuffer[20];
   
   //EEPROM_Test();  
   memset((uint8_t *)cBuffer, 0x00, 19);
   
   
   // EEPROM_Write(GAINSPAN_SIGNATURE_ADDR, "12345678", GAINSPAN_SIGNATURE_LEN);
    EEPROM_Read(GAINSPAN_SIGNATURE_ADDR, cBuffer, GAINSPAN_SIGNATURE_LEN);
   
   EEPROM_Read(GAINSPAN_SIGNATURE_ADDR, cBuffer, GAINSPAN_SIGNATURE_LEN);
   EEPROM_Read(98, cBuffer, GAINSPAN_SIGNATURE_LEN);
   cBuffer[GAINSPAN_SIGNATURE_LEN+1]=0;
   
   if(strcmp((char const *)GainspanSignature, (char const*)cBuffer))                       // write signature "Gainspan"
   {
     EEPROM_Write(GAINSPAN_SIGNATURE_ADDR, "Gainspan", GAINSPAN_SIGNATURE_LEN);
     EEPROM_Read(GAINSPAN_SIGNATURE_ADDR, cBuffer, GAINSPAN_SIGNATURE_LEN);
     strcpy(str_config_ssid, (char const*)ATLIBGS_ADK_SSID);  
     AtLibGs_GetMAC((char *)cBuffer);
     
     strncat(str_config_ssid, (char const*)&cBuffer[9],2);
     strncat(str_config_ssid, (char const*)&cBuffer[12],2);
     strncat(str_config_ssid, (char const*)&cBuffer[15],2);
     
     EEPROM_Write(GAINSPAN_SSID_ADDR, str_config_ssid, GAINSPAN_SSID_MAX_LEN); 
   }
#if 1 
   memset(str_config_ssid, 0x00, GAINSPAN_SSID_MAX_LEN);
   EEPROM_Read(GAINSPAN_SSID_ADDR, str_config_ssid, GAINSPAN_SSID_MAX_LEN);                       // read SSID from EEPROM
  
   EEPROM_Read(GAINSPAN_CHANNEL_ADDR, &wifi_channel, GAINSPAN_CHANNEL_MAX_LEN);                   // read WiFi channel from EEPROM

    if(wifi_channel<1 || wifi_channel>14)                                                     // something wrong, set to default channel
    {
      wifi_channel = 6;
      EEPROM_Write(GAINSPAN_CHANNEL_ADDR, &wifi_channel, GAINSPAN_CHANNEL_MAX_LEN);
    }
#endif
} 
void gravaEEPROM() {
   unsigned short eeprom_adress;          //Variável auxiliar local
   eeprom_adress = EEPROM_Read(0x00);     //Lemos o valor do endereço zero e salvamos em eeprom_adress
   EEPROM_Write(eeprom_adress, cont);     //Salvamos o valor atual de cont no endereço de número "eeprom_adress"
   delay_ms(10);
   

   
   if(eeprom_adress == MAX_ADRESS)        //Teste se eeprom_adress é igual a 127
      eeprom_adress = INIT_ADRESS;
   else
      eeprom_adress++;                    //Incrementa eeprom_adress
   
   EEPROM_Write(0x00, eeprom_adress);     //Salva o valor de aux2 no endereço 00 da eeprom
   
   delay_ms(10);

   led2 = 0x01;
   delay_ms(500);
   led2 = 0x00;
}
Example #22
0
//---------------------------------------------------------------
void Calibrate_Set_Flag(unsigned char channel,unsigned char flag)//установить/снять флаг калиброванности канала
{
    unsigned long true_crc=0;

	if(flag==SET)
	{
			channels[channel].calibrate.cal.calibrate=1;//установим/снимем флаг калибровки
			EEPROM_Write(&channels[channel].calibrate.serialize,3,ADC_CALIBRATE_ADDR+channel*3);		
	}
	else
	{
		if(flag==RESET)
		{
			channels[channel].calibrate.cal.calibrate=0;//установим/снимем флаг калибровки
			EEPROM_Write(&channels[channel].calibrate.serialize,3,ADC_CALIBRATE_ADDR+channel*3);
		}
	}

  	true_crc= (unsigned long)Calibrate_Get_CRC();//расчет текущей CRC калибровок
	EEPROM_Write(&true_crc,1,CALIBRATE_DEVICE_CRC_ADDR);//запомним CRC 	
}
void leEEPROM(){
   unsigned short eeprom_adress;          //Variável auxiliar local
   eeprom_adress = EEPROM_Read(0x00);     //Lemos o endereço 0h da EEPROM e armazemos o valor em eeprom_adress

   if(eeprom_adress == 0xFF) {            //Testando eeprom_adress, EEPROM limpa? Sim...
      EEPROM_Write(0x00, INIT_ADRESS);    //Força escrita do valor 1 no endereço 0x00;
      delay_ms(10);                       //Tempo para escrita
   } else if(eeprom_adress == INIT_ADRESS)
      cont = EEPROM_Read(MAX_ADRESS);
   else
      cont = EEPROM_Read(eeprom_adress - 0x01);
}
Example #24
0
// Save settings to EEPROM
void SaveSettings_EEPROM(void) {
	uint32_t *ptr = (uint32_t *)&Settings;
	uint8_t i;
	uint32_t data;

	EEPROM_Unlock();
	for (i = 0; i < sizeof(Settings); i += 4) {
		data = *ptr++;
		if (data != EEPROM_Read(DATA_EEPROM_START_ADDR + i)) EEPROM_Write(DATA_EEPROM_START_ADDR + i,data);
	}
	EEPROM_Lock();
}
Example #25
0
/***************************************************************************//**
 * @brief 	Reset the timer in RAM and then copies zeros to the addresses in EEPROM
 * @param   Timer_HighA    This is a RAM variable for the first timer
 * @param   Timer_HighB    This is a RAM variable for the second timer
 * @param   Timer_HighC    This is a RAM variable for the third timer
 * @return 	None
 * @date	  14.11.2013 
*******************************************************************************/
void Reset_HighScores(struct TimerStruct * Timer_HighA, struct TimerStruct * Timer_HighB, struct TimerStruct * Timer_HighC)
{
  //Reset all timer to Zero  
  Reset_Timer(Timer_HighA);
  Reset_Timer(Timer_HighB);
  Reset_Timer(Timer_HighC);
  //Set to Zero all the EEPROM addresses
  EEPROM_Set_HighScore(EEPROM_ADDRESS_1,Timer_HighA);
  EEPROM_Set_HighScore(EEPROM_ADDRESS_2,Timer_HighB);
  EEPROM_Set_HighScore(EEPROM_ADDRESS_3,Timer_HighC);
  //Erase the flag, which means no data is into the EEPROM
  EEPROM_Write(EEPROM_ADDRESS_FLAG,WRITTEN_FLAG_NOT_SET);
}
Example #26
0
void main(void)
{
     char rom_data[7];
     
     //setup UART
     UART1_Init(9600);      //setup UART for 9600bps comm
     UART1_Write_Text("mikroC EEPROM TEST\n");
     
     //write to EEPROM
     EEPROM_Write(0, '1');    //write data
     Delay_ms(20);            //needed to ensure correct write/read
     
     EEPROM_Write(1, '2');    //write data
     Delay_ms(20);            //needed to ensure correct write/read
     
     EEPROM_Write(2, '3');    //write data
     Delay_ms(20);            //needed to ensure correct write/read
     
     //Read from EEPROM
     IntToStr((int)EEPROM_Read(0), rom_data);      //read data
     UART1_Write_Text("EEPROM Data : ");
     UART1_Write_Text(rom_data);
     UART_Write('\n');
     Delay_ms(20);            //needed to ensure correct write/read
     
     IntToStr((int)EEPROM_Read(1), rom_data);      //read data
     UART1_Write_Text("EEPROM Data : ");
     UART1_Write_Text(rom_data);
     UART_Write('\n');
     Delay_ms(20);            //needed to ensure correct write/read
     
     IntToStr((int)EEPROM_Read(2), rom_data);      //read data
     UART1_Write_Text("EEPROM Data : ");
     UART1_Write_Text(rom_data);
     UART_Write('\n');
     Delay_ms(20);            //needed to ensure correct write/read
     
     while(1);
}
Example #27
0
//----------------------------------------------------------------
void Calibrate_Set_Default(void)//установка калибровки по умолчанию(отключена)
{
		unsigned char i=0;
	    unsigned long true_crc=0;		

		for(i=0;i<CHANNEL_NUMBER;i++)
		{
			Calibrate_Set_Flag(i,RESET);
		}
		
		true_crc= (unsigned long)Calibrate_Get_CRC();//расчет текущей CRC калибровок
		EEPROM_Write(&true_crc,1,CALIBRATE_DEVICE_CRC_ADDR);//запомним CRC 		
}
void main() {            // FUNCAO PRINCIPAL: MAIN
ADCON1 = 0x07;           // CONFIGURA ENTRADAS AN COMO E/S DIGITAIS
CMCON = 7;               // DESLIGA COMPARADORES
// CONFIGURACOES E/S E ESTADOS INICIAIS [BINARIO]
   TRISA = 0b00000000;            PORTA = 0b00000000;
   TRISB = 0b00000110;         // PORTB = 0b00000000;
   TRISC = 0b00000000;            PORTC = 0b00000000;
// ESTADOS INICIAIS DOS ACESSORIOS
BUZZER = 1;
// MENSAGEM INICIAL NO LCD
Lcd_Init();                                 // INICIA O LCD
Lcd_Cmd(_LCD_CLEAR);                        // LIMPA A TELA DO LCD
Lcd_Cmd(_LCD_CURSOR_OFF);                   // DESLIGA O CURSOR
Lcd_Out(1, 1, msg_2); 
Lcd_Out(2, 1, msg_1);
Delay_ms(1500);
Lcd_Cmd(_LCD_CLEAR);                        // LIMPA A TELA DO LCD
while (1) {
if (!INT2) {
BUZZER = 0; Delay_ms(15); BUZZER = 1; Delay_ms(50);
BUZZER = 0; Delay_ms(15); BUZZER = 1;       // SIRENE SOA DUAS VEZES CURTAS
// EEPROM_Write(unsigned short address, unsigned short data);
EEPROM_Write(0x08, 'K');               //ESCREVE "K" NA POSICAO 0x08 DA EEPROM
Lcd_Cmd(_LCD_CLEAR);                        // LIMPA A TELA DO LCD
Lcd_Out(1, 1, msg_1);
Lcd_Out(2, 1, msg_3);   
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);                        // LIMPA A TELA DO LCD
} else if (!INT1) {
BUZZER = 0; Delay_ms(15); BUZZER = 1;       // SIRENE SOA UMA VEZ CURTA
// EEPROM_Read(unsigned short address);
INFO = EEPROM_Read(0x08);                   // LE A POSICAO 0x08 DA EEPROM
ShortToStr (INFO, INFO_s);
Lcd_Cmd(_LCD_CLEAR);                        // LIMPA A TELA DO LCD
Lcd_Out(1, 1, msg_1);
Lcd_Out(2, 1, msg_4);   
Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR);                        // LIMPA A TELA DO LCD
Lcd_Out(1,1,INFO_s);   
Lcd_Out_Cp(" = DECIMAL");      
Lcd_Cmd(_LCD_SECOND_ROW);
Lcd_Chr_Cp(0+INFO);    
Lcd_Out_Cp(" =  CHARACTER");   
Delay_ms(2500);
Lcd_Cmd(_LCD_CLEAR);}                       // LIMPA A TELA DO LCD
else {
Lcd_Out(1, 1, msg_5);                       
Lcd_Out(2, 1, msg_6);
}                                                                  // FIM ELSE
 }                                                               // FIM  WHILE
  }                                                                // FIM MAIN
Example #29
0
static rt_bool_t calibration_data_save(calculate_data_t *data)
{
    rt_uint8_t count;
    rt_uint8_t *buf;
    count = sizeof(calculate_data_t) + 1;
    buf = (rt_uint8_t *)rt_malloc(count);
    buf[0] = CALIBRATION_DATA_MAGIC;
    rt_memcpy(&buf[1], data, count - 1);
    /* power up the eeprom */
    EEPROM_PowerDown(DISABLE);
    /* erase the page for touch data */
    EEPROM_Erase(CALIBRATION_DATA_PAGE);
    EEPROM_Write(0, CALIBRATION_DATA_PAGE, buf, MODE_8_BIT, count);
    rt_free(buf);
    return RT_TRUE;
}
Example #30
0
void EEPROM_PutTitle(char* ptitle,int index,int maxlen)
{

	int n = maxlen>EEPROMADDRSTRLEN  ? EEPROMADDRSTRLEN : maxlen;
	int a;
	if (_iseepromenabled )
	{	a = (index*EEPROMADDRSTRLEN) + EEPROMADDRSTRMIN;
		if (a+n<EEPROMADDRSTRMAX)
		{	if (EEPROM_CheckCache(ptitle,index,maxlen)==FALSE)
			{	EEPROM_Write(a,(unsigned char*)ptitle,n);
				EEPROM_PutCache(ptitle,index,maxlen);
			}
		}
	} 

}