-
Notifications
You must be signed in to change notification settings - Fork 0
/
AT93C56A.cpp
91 lines (86 loc) · 1.83 KB
/
AT93C56A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "AT93C56A.h"
#include "mbed.h"
AT93C56A::AT93C56A(PinName eecs,PinName eeck,PinName eedi,PinName eedo): _eecs(eecs),_eeck(eeck),_eedi(eedi),_eedo(eedo){
_eecs=0; // Active High State
_eeck=0;
};
void AT93C56A::vSend(unsigned short usCommand)
{
signed char i=10;
_eedi=1; //SB
_eecs=1; // Chip Select High
wait_us(1); // SB Clock Generation
_eeck=1;
wait_us(1);
_eeck=0;
while(i>=0)
{
_eedi = (usCommand>>i)&0x01;
i--;
wait_us(1);
_eeck=1;
wait_us(1);
_eeck=0;
}
}
void AT93C56A::vWriteEnable()
{
vSend(EE_EWEN);
wait_us(1);
_eecs=0; //Chip Select Low
}
void AT93C56A::vWriteDisable()
{
vSend(EE_EWDS);
wait_us(1);
_eecs=0; //Chip Select Low
}
void AT93C56A::vErase(unsigned short usAddr)
{
vSend(EE_ERASE|usAddr);
wait_us(1);
_eecs=0;
/** wait busy flag clear */
wait_us(1); // tcs > 250ns @2.7V
_eecs=1;
wait_us(1); // tsv < 250ns @2.7V
while(_eedo==0); // 0.1ms < twp < 10ms
_eecs=0;
}
void AT93C56A::vWrite(unsigned short usAddr, unsigned char ucData)
{
signed char i=7;
vSend(EE_WRITE|usAddr);
for(i=7;i>=0;i--)
{
_eedi = (int)( (ucData>>i)&0x0001 );
wait_us(1);
_eeck=1;
wait_us(1);
_eeck=0;
}
_eecs=0;
/** wait busy flag clear */
wait_us(1); // tcs > 250ns @2.7V
_eecs=1;
wait_us(1); // tsv < 250ns @2.7V
while(_eedo==0); // 0.1ms < twp < 10ms
_eecs=0;
}
unsigned char AT93C56A::ucRead(unsigned short usAddr)
{
unsigned char data=0;
signed char i=7;
vSend(EE_READ|usAddr);
wait_us(1);
for(i=7;i>=0;i--)
{
_eeck=1;
wait_us(1);
_eeck=0;
data = data | (_eedo<<i);
wait_us(1);
}
_eecs=0;
return data;
}