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