mbed EPROM 27256 Vpp 12.5V Writter Functions Blank Check(SW = 0): Check blank(all 1) erased EPROM Write(SW = 1): Write Hex file(TEST1.HEX) to EPROM Read(SW = 2): Read from EPROM and dump to local file(TEST1.DMP) Copy(SW = 3): Read from dump image file(TEST1.DMP) and write to EPROM
main.cpp
00001 /*mbed EPROM 27256 Vpp 12.5V Writter 00002 Functions 00003 Blank Check(SW = 0): Check blank(all 1) erased EPROM 00004 Write(SW = 1): Write Hex file(TEST1.HEX) to EPROM 00005 Read: Read from EPROM and dump to local file(TEST1.DMP) 00006 Copy: Read from dump image file(TEST1.DMP) and write to EPROM 00007 */ 00008 #include "mbed.h" 00009 #include "TextLCD.h" 00010 00011 LocalFileSystem local("mbed"); 00012 BusInOut DATA(p5, p6, p7, p8, p9, p10, p11, p12); 00013 BusOut ADRS(p13, p14); 00014 DigitalOut RD(p15); 00015 DigitalOut WR(p16); 00016 DigitalOut RESET(p17); 00017 DigitalOut CE(p18); 00018 DigitalOut OE(p19); 00019 DigitalOut VCP_0V(p20); 00020 DigitalOut VCP_5V(p21); 00021 DigitalIn BTN(p22); 00022 BusIn SW(p23, p24); 00023 TextLCD lcd(p25, p26, p27, p28, p29, p30); 00024 00025 DigitalOut LED_BUSY(LED1); 00026 DigitalOut LED_5V(LED2); 00027 DigitalOut LED_12V(LED3); 00028 DigitalOut LED_RETRY(LED4); 00029 00030 #define _HIGH 1 00031 #define _LOW 0 00032 00033 #define SET_READ DATA.input() 00034 #define SET_WRITE DATA.output() 00035 00036 #define PORT_A 0 00037 #define PORT_B 1 00038 #define PORT_C 2 00039 #define CONTRL 3 00040 00041 #define MAX_ADDRESS 1024 00042 00043 union UNION1{ 00044 struct HEX{ 00045 uint8_t marker; 00046 uint8_t length[2]; 00047 uint8_t offset[4]; 00048 uint8_t rectype[2]; 00049 uint8_t data[64]; 00050 } h; 00051 char hex_line[137]; 00052 } u; 00053 00054 union UNION2{ 00055 uint16_t address; 00056 uint8_t hl_address[2]; 00057 } a; 00058 00059 FILE *fp; 00060 char hex_filename[] = "/mbed/test1.hex"; 00061 char out_filename[] = "/mbed/test1.dmp"; 00062 char in_filename[] = "/mbed/test1.dmp"; 00063 00064 short ROM_write(uint8_t address_h, uint8_t address_l, short data_byte){ 00065 short read_byte; 00066 00067 LED_BUSY = _HIGH; 00068 wait_us(1000); 00069 SET_WRITE; 00070 ADRS = CONTRL; 00071 DATA = 0x80; 00072 WR = _LOW; 00073 wait_us(100); 00074 WR = _HIGH; 00075 00076 ADRS = PORT_A; 00077 DATA = address_l; 00078 WR = _LOW; 00079 wait_us(100); 00080 WR = _HIGH; 00081 00082 ADRS = PORT_B; 00083 DATA = address_h; 00084 WR = _LOW; 00085 wait_us(100); 00086 WR = _HIGH; 00087 00088 ADRS = PORT_C; 00089 DATA = data_byte; 00090 WR = _LOW; 00091 wait_us(100); 00092 WR = _HIGH; 00093 00094 CE = _LOW; 00095 wait_us(100); 00096 CE = _HIGH; 00097 00098 wait_us(10); 00099 00100 ADRS = CONTRL; 00101 DATA = 0x89; 00102 WR = _LOW; 00103 wait_us(100); 00104 WR = _HIGH; 00105 00106 ADRS = PORT_A; 00107 DATA = address_l; 00108 WR = _LOW; 00109 wait_us(100); 00110 WR = _HIGH; 00111 00112 ADRS = PORT_B; 00113 DATA = address_h; 00114 WR = _LOW; 00115 wait_us(100); 00116 WR = _HIGH; 00117 00118 SET_READ; 00119 ADRS = PORT_C; 00120 OE = _LOW; 00121 wait_us(100); 00122 RD = _LOW; 00123 wait_us(100); 00124 read_byte = DATA; 00125 wait_us(50); 00126 RD = _HIGH; 00127 OE = _HIGH; 00128 SET_WRITE; 00129 LED_BUSY = _LOW; 00130 00131 return read_byte; 00132 } 00133 00134 uint8_t ROM_read(uint8_t address_h, uint8_t address_l){ 00135 uint8_t read_byte; 00136 00137 LED_BUSY = _HIGH; 00138 SET_WRITE; 00139 ADRS = CONTRL; 00140 DATA = 0x89; 00141 WR = _LOW; 00142 wait_us(10); 00143 WR = _HIGH; 00144 00145 ADRS = PORT_A; 00146 DATA = address_l; 00147 WR = _LOW; 00148 wait_us(10); 00149 WR = _HIGH; 00150 00151 ADRS = PORT_B; 00152 DATA = address_h; 00153 WR = _LOW; 00154 wait_us(10); 00155 WR = _HIGH; 00156 00157 SET_READ; 00158 ADRS = PORT_C; 00159 CE = _LOW; 00160 wait_us(10); 00161 OE = _LOW; 00162 wait_us(10); 00163 RD = _LOW; 00164 wait_us(100); 00165 read_byte = DATA; 00166 wait_us(10); 00167 RD = _HIGH; 00168 OE = _HIGH; 00169 CE = _HIGH; 00170 00171 SET_WRITE; 00172 LED_BUSY = _LOW; 00173 return read_byte; 00174 } 00175 00176 char h2d(char h_data){ 00177 char d_data; 00178 00179 d_data = 0; 00180 if(h_data <= '9') d_data = h_data - '0'; 00181 else if(h_data >= 'A') d_data = h_data - 'A' + 10; 00182 return d_data; 00183 } 00184 00185 void Vcc_5V_Vpp_5V(){ 00186 LED_12V = _LOW; 00187 LED_5V = _HIGH; 00188 VCP_0V = _LOW; 00189 VCP_5V = _HIGH; 00190 } 00191 00192 void Vcc_6V_Vpp_12V(){ 00193 LED_5V = _LOW; 00194 LED_12V = _HIGH; 00195 VCP_0V = _LOW; 00196 VCP_5V = _LOW; 00197 } 00198 00199 void Vcc_0V_Vpp_0V(){ 00200 LED_5V = _LOW; 00201 LED_12V = _LOW; 00202 VCP_0V = _HIGH; 00203 VCP_5V = _LOW; 00204 } 00205 00206 void get_btn(){ 00207 int cnt; 00208 00209 cnt = 0; 00210 lcd.locate(0, 1); 00211 lcd.printf("Push BTN to Cont"); 00212 while(cnt < 30){ 00213 if(BTN == _HIGH) cnt++; 00214 } 00215 } 00216 00217 void blank_check(){ 00218 uint8_t read_data; 00219 00220 lcd.locate(0,0); 00221 lcd.printf("Blank Chk Mode "); 00222 get_btn(); 00223 00224 Vcc_5V_Vpp_5V(); 00225 for(a.address = 0; a.address < MAX_ADDRESS; a.address++){ 00226 read_data = ROM_read(a.hl_address[1], a.hl_address[0]); 00227 lcd.locate(0,1); 00228 lcd.printf("%04X %02X ", a.address, read_data); 00229 if( read_data != 0xFF) goto __BLNK_ERROR; 00230 } 00231 lcd.locate(0,0); 00232 lcd.printf("Success! "); 00233 return; 00234 00235 __BLNK_ERROR: 00236 lcd.locate(0,1); 00237 lcd.printf("Blnk Check Error"); 00238 return; 00239 } //blank_check() 00240 00241 void write_rom(){ 00242 int i, len, line; 00243 int sum, cs; 00244 short length, high_byte, low_byte; 00245 uint8_t write_data, read_data, rty_cnt; 00246 00247 lcd.locate(0,0); 00248 lcd.printf("HEX WRITE to ROM"); 00249 lcd.locate(0,1); 00250 lcd.printf(hex_filename); 00251 get_btn(); 00252 00253 if ( NULL == (fp = fopen( hex_filename, "r" )) ) 00254 goto __HEX_FILE_OPEN_ERROR; 00255 00256 line = 0; 00257 while(1){ 00258 for(len = 0; len < 137; len++){ 00259 u.hex_line[len] = fgetc(fp); 00260 if(feof(fp) != NULL) goto __EOF; 00261 if(u.hex_line[len] == 0x0A) goto __EXIT_FOR; 00262 } 00263 00264 __EXIT_FOR: 00265 u.hex_line[len - 1] = NULL; //Remove CRLF and terminate 00266 line++; 00267 if(u.h.marker != ':') goto __MARKER_ERROR; 00268 00269 length = 0; 00270 high_byte = h2d(u.h.length[0]) * 16; 00271 low_byte = h2d(u.h.length[1]); 00272 length = high_byte + low_byte; 00273 00274 a.hl_address[0] = (h2d(u.h.offset[2]) * 16) + h2d(u.h.offset[3]); 00275 a.hl_address[1] = (h2d(u.h.offset[0]) * 16) + h2d(u.h.offset[1]); 00276 Vcc_6V_Vpp_12V(); 00277 for ( i = 0; i < length * 2; i= i + 2){ 00278 high_byte = h2d(u.h.data[i]) * 16; 00279 low_byte = h2d(u.h.data[i + 1]); 00280 write_data = high_byte + low_byte; 00281 for(rty_cnt = 0; rty_cnt <= 25; rty_cnt++){ 00282 if(rty_cnt > 0) LED_RETRY = _HIGH; 00283 read_data = ROM_write(a.hl_address[1], a.hl_address[0], write_data); 00284 lcd.locate(0,0); 00285 lcd.printf(" %03d %04X %02X %02X", line, a.address, write_data, read_data); 00286 lcd.locate(0,1); 00287 lcd.printf(" %02D", rty_cnt); 00288 if(read_data == write_data) goto __NEXT_ADDRS; 00289 } 00290 goto __RTY_ERROR; 00291 00292 __NEXT_ADDRS: 00293 LED_RETRY = _LOW; 00294 a.address++; 00295 } 00296 Vcc_5V_Vpp_5V(); 00297 cs = 0; 00298 i--; 00299 high_byte = h2d(u.h.data[i + 1]) * 16; 00300 low_byte = h2d(u.h.data[i + 2]); 00301 cs = high_byte + low_byte; 00302 00303 //calc check sum 00304 sum = 0; 00305 for( i = 1; i < len - 3; i = i + 2){ 00306 high_byte = h2d(u.hex_line[i]); 00307 high_byte = high_byte * 16; 00308 low_byte = h2d(u.hex_line[i + 1]); 00309 sum = sum + high_byte + low_byte; 00310 } 00311 00312 if(((0x100 - (sum & 0xFF)) - cs) != 0) goto __CS_ERROR; 00313 00314 } //while(1) 00315 lcd.locate(0,0); 00316 lcd.printf("Success! "); 00317 return; 00318 00319 __HEX_FILE_OPEN_ERROR: 00320 lcd.locate(0,1); 00321 lcd.printf("HEX File Open Er"); 00322 return; 00323 00324 __MARKER_ERROR: 00325 lcd.locate(0,1); 00326 lcd.printf("Marker Error!"); 00327 return; 00328 00329 __CS_ERROR: 00330 lcd.locate(0,1); 00331 lcd.printf("Check Sum Error!"); 00332 return; 00333 00334 __EOF: 00335 lcd.locate(0,1); 00336 lcd.printf("End Of File "); 00337 return; 00338 00339 __RTY_ERROR: 00340 lcd.locate(0,1); 00341 lcd.printf("Retry Error "); 00342 return; 00343 } //write_rom() 00344 00345 void read_rom(){ 00346 uint8_t read_data; 00347 00348 lcd.locate(0,0); 00349 lcd.printf("READ from ROM "); 00350 get_btn(); 00351 00352 if ( NULL == (fp = fopen( out_filename, "w" )) ) 00353 goto __OUT_FILE_OPEN_ERROR; 00354 00355 Vcc_5V_Vpp_5V(); 00356 for(a.address = 0; a.address < MAX_ADDRESS; a.address++){ 00357 read_data = ROM_read(a.hl_address[1], a.hl_address[0]); 00358 fprintf(fp, "%02X", read_data); 00359 lcd.locate(0,1); 00360 lcd.printf("%04X %02X ", a.address, read_data); 00361 //wait(2); 00362 } 00363 lcd.locate(0,0); 00364 lcd.printf("Success! "); 00365 return; 00366 00367 __OUT_FILE_OPEN_ERROR: 00368 lcd.locate(0,1); 00369 lcd.printf("Out File Open Er"); 00370 return; 00371 00372 } //read_rom 00373 00374 void copy_rom(){ 00375 int rty_cnt; 00376 char h_data, l_data; 00377 uint8_t read_data, write_data; 00378 00379 lcd.locate(0,0); 00380 lcd.printf("COPY to ROM "); 00381 get_btn(); 00382 00383 if ( NULL == (fp = fopen( in_filename, "r" )) ) 00384 goto __IN_FILE_OPEN_ERROR; 00385 00386 Vcc_6V_Vpp_12V(); 00387 for(a.address = 0; a.address < MAX_ADDRESS; a.address++){ 00388 h_data = fgetc(fp); 00389 l_data = fgetc(fp); 00390 write_data = h2d(h_data) * 16 + h2d(l_data); 00391 for(rty_cnt = 0; rty_cnt <= 25; rty_cnt++){ 00392 if(rty_cnt > 0) LED_RETRY = _HIGH; 00393 read_data = ROM_write(a.hl_address[1], a.hl_address[0], write_data); 00394 lcd.locate(0,1); 00395 lcd.printf("%04X %02X %02X %2D", a.address, write_data, read_data, rty_cnt); 00396 if(read_data == write_data) goto __NEXT_ADDRS; 00397 } 00398 goto __RTY_ERROR; 00399 00400 __NEXT_ADDRS: 00401 } 00402 lcd.locate(0,0); 00403 lcd.printf("Success! "); 00404 return; 00405 00406 __RTY_ERROR: 00407 lcd.locate(0,1); 00408 lcd.printf("Retry Error"); 00409 return; 00410 00411 __IN_FILE_OPEN_ERROR: 00412 lcd.locate(0,1); 00413 lcd.printf("File Open Error "); 00414 return; 00415 } //copy_rom 00416 00417 void init(){ 00418 CE = _HIGH; 00419 OE = _HIGH; 00420 RD = _HIGH; 00421 WR = _HIGH; 00422 SET_WRITE; 00423 DATA = 0; 00424 ADRS = 0; 00425 00426 Vcc_0V_Vpp_0V(); 00427 00428 LED_BUSY = _LOW; 00429 LED_5V = _LOW; 00430 LED_12V = _LOW; 00431 LED_RETRY = _LOW; 00432 00433 RESET = _LOW; 00434 RESET = _HIGH; 00435 wait_us(100); 00436 RESET = _LOW; 00437 } //init() 00438 00439 int main() { 00440 00441 init(); 00442 lcd.cls(); 00443 lcd.locate(0,0); 00444 lcd.printf("EPROM Writter "); 00445 lcd.locate(0,1); 00446 lcd.printf("MAX ADRS: %5d ", MAX_ADDRESS); 00447 wait(3); 00448 while(1){ 00449 switch(SW) { 00450 case(0): 00451 blank_check(); 00452 break; 00453 case(1): 00454 write_rom(); 00455 fclose( fp ); 00456 break; 00457 case(2): 00458 read_rom(); 00459 fclose( fp ); 00460 break; 00461 case(3): 00462 copy_rom(); 00463 fclose( fp ); 00464 break; 00465 default: 00466 break; 00467 } //switch(SW) 00468 Vcc_0V_Vpp_0V(); 00469 wait(5); 00470 } //while(1) 00471 } //main()
Generated on Tue Jul 19 2022 00:31:11 by 1.7.2