forked from mtirado1/at89s8252-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readusersgn3.py
64 lines (58 loc) · 1.73 KB
/
readusersgn3.py
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
import serial
import time
from intelhex import IntelHex
from config import *
# Path to hex file
f = user_sgn_dumpFile
print(f)
# Serial port name
p = serialPort
print(p)
# Read hex file
ih = IntelHex()
#ih.fromfile(f, format='hex')
with serial.Serial(p, 9600) as ser:
time.sleep(2)
print(ser.readline().decode('utf-8'))
ser.write(b'\x60') # Enable programming
print(ser.readline().decode('utf-8'))
# ih.dump()
# print('Programming...')
# for i in range(0, len(ih.addresses())):
# addr = ih.addresses()[i]
# ser.write(b'\x51')
# ser.write(bytes([addr//256])) # high address byte
# ser.write(bytes([addr%256])) # low address byte
# ser.write(bytes([ih[addr]])) # data byte
# time.sleep(0.05)
# ser.readline()
#a = input('Programming done. Do you wish to verify? y/n: ')
#if a == 'Y' or a == 'y':
print('Reading...')
#err = False
conta = 0
for i in range(0x0, at89s8253_max_user_sgn):
#addr = ih.addresses()[i]
if conta == 255:
print(hex(i))
if conta == 256:
conta = 0
conta += 1
ser.write(b'\x70')
#ser.write(bytes([i//256])) # high address byte
ser.write(bytes([i%256])) # low address byte
k = int(ser.readline().decode('utf-8'), 16)
ih[i] = k
#print(k);
# if k != ih[addr]:
# print('Error at address' + hex(addr))
# print('Got %d, was %d' % (k, ih[addr]))
# err = True
# if not err:
# print('Verification complete.')
#
ser.write(b'\x40') # End programming
print(ser.readline().decode('utf-8'))
ih.dump()
ih.write_hex_file(f)
print('Done.')