Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / libdragonfly / eeprom.c @ 865

History | View | Annotate | Download (936 Bytes)

1
#include <avr/io.h>
2
#include "eeprom.h"
3

    
4
int eeprom_put_byte(unsigned int uiAddress, unsigned char ucData) {
5
    /* Wait for completion of previous write */
6
    while(EECR & (1<<EEWE));
7
    /* Set up address and data registers */
8
    EEAR = uiAddress;
9
    EEDR = ucData;
10
    /* Write logical one to EEMWE */
11
    EECR |= (1<<EEMWE);
12
    /* Start eeprom write by setting EEWE */
13
    EECR |= (1<<EEWE);
14
    
15
    return 0;
16
}
17

    
18
int eeprom_get_byte(unsigned int uiAddress, unsigned char *byte) {
19
    /* Wait for completion of previous write */
20
    while(EECR & (1<<EEWE));
21
    /* Set up address register */
22
    EEAR = uiAddress;
23
    /* Start eeprom read by writing EERE */
24
    EECR |= (1<<EERE);
25
    /* get data from data register */
26
    *byte=EEDR;
27
    
28
    return 0;
29
}
30

    
31

    
32
unsigned char get_robotid(void) {
33
    unsigned char ret;
34
    
35
    eeprom_get_byte(EEPROM_ROBOT_ID_ADDR, &ret);
36
    
37
    return ret;
38
}