41 lines
757 B
C
41 lines
757 B
C
#include "device_address.h"
|
|
|
|
#define DEFAULT_MODBUS_ADDRESS (32)
|
|
|
|
uint8_t EEPROM_ReadByte(uint8_t __eeprom*adr)
|
|
{
|
|
while (EECR & (1<<EEWE));
|
|
EEAR = (uint16_t)adr;
|
|
EECR |= (1<<EERE);
|
|
return EEDR;
|
|
}
|
|
|
|
void EEPROM_WriteByte(uint8_t __eeprom*adr, uint8_t value)
|
|
{
|
|
while (EECR & (1<<EEWE));
|
|
EEAR = (uint16_t)adr;
|
|
EEDR = value;
|
|
EECR |= (1<<EEMWE);
|
|
EECR |= (1<<EEWE);
|
|
}
|
|
|
|
uint8_t get_device_address(void)
|
|
{
|
|
return EEPROM_ReadByte(0);
|
|
}
|
|
|
|
void write_device_address(uint8_t address)
|
|
{
|
|
EEPROM_WriteByte(0, address);
|
|
EEPROM_WriteByte(1, ~address);
|
|
}
|
|
|
|
uint8_t get_default_address(void)
|
|
{
|
|
return DEFAULT_MODBUS_ADDRESS;
|
|
}
|
|
|
|
int is_valid_device_address(void)
|
|
{
|
|
return (EEPROM_ReadByte(0) ^ EEPROM_ReadByte(1) == 0xFF);
|
|
} |