device address added
This commit is contained in:
parent
b140ceff68
commit
baa98357c1
41
device_address.c
Normal file
41
device_address.c
Normal file
@ -0,0 +1,41 @@
|
||||
#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);
|
||||
}
|
9
device_address.h
Normal file
9
device_address.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef DEVICE_ADDRESS_H
|
||||
#define DEVICE_ADDRESS_H
|
||||
|
||||
uint8_t get_device_address(void);
|
||||
void write_device_address(uint8_t address);
|
||||
uint8_t get_default_address(void);
|
||||
int is_valid_device_address(void);
|
||||
|
||||
#endif /*DEVICE_ADDRESS_H*/
|
Loading…
Reference in New Issue
Block a user