Загрузил(а) файлы в ''
Добавлена проверка адреса на наличие ошибок перед чтением из ПЗУ.
This commit is contained in:
parent
baa98357c1
commit
67f31a96dc
@ -1,41 +1,46 @@
|
|||||||
#include "device_address.h"
|
#include "device_address.h"
|
||||||
|
|
||||||
#define DEFAULT_MODBUS_ADDRESS (32)
|
uint8_t EEPROM_ReadByte(uint32_t adr)
|
||||||
|
{
|
||||||
uint8_t EEPROM_ReadByte(uint8_t __eeprom*adr)
|
while (EECR & (1<<EEPE));
|
||||||
{
|
EEAR = adr;
|
||||||
while (EECR & (1<<EEWE));
|
EECR |= (1<<EERE);
|
||||||
EEAR = (uint16_t)adr;
|
return EEDR;
|
||||||
EECR |= (1<<EERE);
|
}
|
||||||
return EEDR;
|
|
||||||
}
|
void EEPROM_WriteByte(uint32_t adr, uint8_t value)
|
||||||
|
{
|
||||||
void EEPROM_WriteByte(uint8_t __eeprom*adr, uint8_t value)
|
while (EECR & (1<<EEPE));
|
||||||
{
|
EEAR = adr;
|
||||||
while (EECR & (1<<EEWE));
|
EEDR = value;
|
||||||
EEAR = (uint16_t)adr;
|
EECR |= (1<<EEMPE);
|
||||||
EEDR = value;
|
EECR |= (1<<EEPE);
|
||||||
EECR |= (1<<EEMWE);
|
}
|
||||||
EECR |= (1<<EEWE);
|
|
||||||
}
|
uint8_t get_device_address(void)
|
||||||
|
{
|
||||||
uint8_t get_device_address(void)
|
if(is_valid_device_address())
|
||||||
{
|
{
|
||||||
return EEPROM_ReadByte(0);
|
return EEPROM_ReadByte(0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
void write_device_address(uint8_t address)
|
{
|
||||||
{
|
return get_default_address();
|
||||||
EEPROM_WriteByte(0, address);
|
}
|
||||||
EEPROM_WriteByte(1, ~address);
|
}
|
||||||
}
|
|
||||||
|
void write_device_address(uint8_t address)
|
||||||
uint8_t get_default_address(void)
|
{
|
||||||
{
|
EEPROM_WriteByte(0, address);
|
||||||
return DEFAULT_MODBUS_ADDRESS;
|
EEPROM_WriteByte(1, ~address);
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_valid_device_address(void)
|
uint8_t get_default_address(void)
|
||||||
{
|
{
|
||||||
return (EEPROM_ReadByte(0) ^ EEPROM_ReadByte(1) == 0xFF);
|
return DEFAULT_MODBUS_ADDRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int is_valid_device_address(void)
|
||||||
|
{
|
||||||
|
return ((EEPROM_ReadByte(0) ^ EEPROM_ReadByte(1)) == 0xFF);
|
||||||
}
|
}
|
@ -1,9 +1,12 @@
|
|||||||
#ifndef DEVICE_ADDRESS_H
|
#ifndef DEVICE_ADDRESS_H
|
||||||
#define DEVICE_ADDRESS_H
|
#define DEVICE_ADDRESS_H
|
||||||
|
#include <stdint.h>
|
||||||
uint8_t get_device_address(void);
|
#include <avr/io.h>
|
||||||
void write_device_address(uint8_t address);
|
#define DEFAULT_MODBUS_ADDRESS (32)
|
||||||
uint8_t get_default_address(void);
|
|
||||||
int is_valid_device_address(void);
|
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*/
|
#endif /*DEVICE_ADDRESS_H*/
|
Loading…
Reference in New Issue
Block a user