source: ISPProgrammer/ISPprog/ISP_Lockbits.pas

Last change on this file was 363, checked in by chronos, 13 years ago
  • Added: Package ISPProgrammer for in-system programming of various chips. Supports Dallas ISP protocol, Presto, Rabbit RFU and some others Atmel devices.
File size: 3.8 KB
Line 
1unit ISP_Lockbits;
2
3{$MODE Delphi}
4
5interface
6
7function ISPReadLockBits(var lb:byte):integer;
8function ISPWriteLockBits(lb:byte):integer;
9function AnyLock:boolean;
10
11implementation
12
13uses Delays, Globals, Processors, SPI;
14
15function ISPReadLockBits(var lb:byte):integer;
16var data:array[0..2] of byte;
17begin
18 Result:=0;
19 case Signatures[devicenr].algo_lb of
20 ALGO_LB_2323:
21 begin
22 data[0] := $58;
23 data[1] := $00;
24 data[2] := $00;
25 WriteBytes(@data, 3);
26 lb:=ReadByte;
27 lb:=$f9 or ((lb and $40) shr 4) or ((lb and $80) shr 6);
28 end;
29 ALGO_LB_TINY, ALGO_LB_2333, ALGO_LB_MEGA:
30 begin
31 data[0] := $58;
32 data[1] := $00;
33 data[2] := $00;
34 WriteBytes(@data, 3);
35 lb:=ReadByte;
36 end;
37 ALGO_LB_89S51:
38 begin
39 data[0] := $24;
40 data[1] := $00;
41 data[2] := $00;
42 WriteBytes(@data, 3);
43 lb:=ReadByte xor $ff;
44 end;
45 ALGO_LB_89S8253, ALGO_LB_89S2051:
46 begin
47 data[0] := $24;
48 data[1] := $00;
49 data[2] := $00;
50 WriteBytes(@data, 3);
51 lb:=ReadByte;
52 end;
53 else
54 Result:=-1; // no ISP command to read lock bits
55 end;
56end;
57
58function ISPWriteLockBits(lb:byte):integer;
59var data:array[0..3] of byte;
60begin
61 Result:=0;
62 case Signatures[devicenr].algo_lb of
63 ALGO_LB_89x: // 89S53/8252
64 begin
65 data[0] := $ac;
66 data[1] := $07 or (lb and $e0);
67 data[2] := $00;
68 WriteBytes(@data, 3);
69 Sync;
70 WaitMS(Signatures[devicenr].prog_time);
71 end;
72 ALGO_LB_89S51: // 89S51/52
73 begin
74 // Mode 1, no lock protection
75 data[0] := $ac;
76 data[1] := $e0;
77 data[2] := $00;
78 data[3] := $00;
79 WriteBytes(@data, 4);
80 Sync;
81 WaitMS(Signatures[devicenr].prog_time);
82 if (lb and $04) = 0 then
83 begin
84 // Mode 2, lock bit 1 activated
85 data[0] := $ac;
86 data[1] := $e1;
87 data[2] := $00;
88 data[3] := $00;
89 WriteBytes(@data, 4);
90 Sync;
91 WaitMS(Signatures[devicenr].prog_time);
92 end;
93 if (lb and $08) = 0 then
94 begin
95 // Mode 3, lock bit 2 activated
96 data[0] := $ac;
97 data[1] := $e2;
98 data[2] := $00;
99 data[3] := $00;
100 WriteBytes(@data, 4);
101 Sync;
102 WaitMS(Signatures[devicenr].prog_time);
103 end;
104 if (lb and $10) = 0 then
105 begin
106 // Mode 4, lock bit 3 activated
107 data[0] := $ac;
108 data[1] := $e3;
109 data[2] := $00;
110 data[3] := $00;
111 WriteBytes(@data, 4);
112 Sync;
113 WaitMS(Signatures[devicenr].prog_time);
114 end;
115 end;
116 ALGO_LB_STD, ALGO_LB_TINY, // AVR
117 ALGO_LB_2323, ALGO_LB_2333:
118 begin
119 data[0] := $ac;
120 data[1] := $f9 or (lb and $06);
121 data[2] := $00;
122 data[3] := $00;
123 WriteBytes(@data, 4);
124 Sync;
125 WaitMS(Signatures[devicenr].prog_time);
126 end;
127 ALGO_LB_MEGA: // ATmega
128 begin
129 data[0] := $ac;
130 data[1] := $e0;
131 data[2] := $00;
132 data[3] := $c0 or (lb and $3f);
133 WriteBytes(@data, 4);
134 Sync;
135 WaitMS(Signatures[devicenr].prog_time);
136 end;
137 ALGO_LB_89S8253, ALGO_LB_89S2051: // AT89S8253, AT89S2051/4051
138 begin
139 data[0] := $ac;
140 data[1] := $e0 or (lb and $07);
141 data[2] := $00;
142 data[3] := $00;
143 WriteBytes(@data, 4);
144 Sync;
145 WaitMS(Signatures[devicenr].prog_time);
146 end;
147 else
148 Result:=-1; // no ISP command to write lock bits
149 end;
150end;
151
152function AnyLock:boolean;
153var i:integer;
154begin
155 Result:=true;
156 for i:=0 to 7 do
157 if (Signatures[devicenr].lockbits[i] <> '') then
158 Exit;
159 Result:=false;
160end;
161
162end.
Note: See TracBrowser for help on using the repository browser.