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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
//****************************************************************
// --最简洁的的拿来就用保证没错^_^简洁至上!
//----------------------------------------------------------------
//--------------------------------//--------------------------------
//注意:以下为STC89系列的地址
//--------------------------------//--------------------------------
sfr isp_data = 0xe2;//ISP/IAP操作时的数据寄存器
sfr isp_addrh = 0xe3;//高地址
sfr isp_addrl = 0xe4;//低地址
sfr isp_cmd = 0xe5;//命令模式寄存器
sfr isp_trig = 0xe6;//命令触发寄存器
sfr isp_contr = 0xe7;//ISP/IAP控制寄存器
*/
/*
//--------------------------------//--------------------------------
//注意:以下为1T新STC系列的地址
//--------------------------------//--------------------------------
sfr isp_data = 0xc2;//ISP/IAP操作时的数据寄存器
sfr isp_addrh = 0xc3;//高地址
sfr isp_addrl = 0xc4;//低地址
sfr isp_cmd = 0xc5;//命令模式寄存器
sfr isp_trig = 0xc6;//命令触发寄存器
sfr isp_contr = 0xc7;//ISP_IAP控制寄存器
//----------------------------------------------------------------
uchar eeprom_read(uint addres);//
void eeprom_write(uint address,uchar wdata);//
void eeprom_eares(uint addres);//扇区擦除
//****************************************************************
// 扇区擦除
//----------------------------------------------------------------
void eeprom_eares(uint addres)
{
uchar i;
isp_addrl=addres; //低位地址
isp_addrh=addres>>8; //高位地址
isp_contr=0x01;
isp_contr=isp_contr|0x80; //设时间与充ISP操作。
isp_cmd=0x03; //扇区命命令
isp_trig=0x46; //触发
isp_trig=0xb9; //触发启动。
for(i=0;i<3;i++)
;
isp_addrl=0xff;
isp_addrh=0xff;
isp_contr=0x00;
isp_cmd=0x00;
isp_trig=0x00;
}
//****************************************************************
// 读数据
//----------------------------------------------------------------
unsigned char eeprom_read(unsigned int addres)
{
unsigned char i,z;
isp_addrl=addres; //低位地址
isp_addrh=addres>>8; //高位地址
isp_contr=0x01;
isp_contr=isp_contr|0x80; //设时间与充ISP操作。
isp_cmd=0x01; //写命令
isp_trig=0x46; //触发
isp_trig=0xb9; //触发启动。
for(i=0;i<3;i++)
;
isp_addrl=0xff;
isp_addrh=0xff;
isp_contr=0x00;
isp_cmd=0x00;
isp_trig=0x00;
z=isp_data;
return(z);
}
//****************************************************************
// 写数据
//----------------------------------------------------------------
void eeprom_write(unsigned int addres,unsigned char write_data)
{
unsigned char i;
isp_data=write_data; //要写入的数据。
isp_addrl=addres; //低位地址
isp_addrh=addres>>8; //高位地址
isp_contr=0x01;
isp_contr=isp_contr|0x80; //设时间与充ISP操作。
isp_cmd=0x02; //写命令
isp_trig=0x46; //触发
isp_trig=0xb9; //触发启动。
for(i=0;i<3;i++)
;
isp_addrl=0xff;
isp_addrh=0xff;
isp_contr=0x00;
isp_cmd=0x00;
isp_trig=0x00;
}
|