microchip8_18f2221family.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. # TOP2049 Open Source programming suite
  3. #
  4. # Microchip8 - 18f2221 family - 8bit PIC MCU
  5. #
  6. # Copyright (c) 2013 Pavel Stemberk <stemberk@gmail.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. """
  22. from libtoprammer.chips.microchip8.microchip8_18_common import *
  23. class microchip8_18f2221family(Chip_Microchip8_18_common):
  24. voltageVDD = 5
  25. voltageVPP = 11
  26. delayP2A = 0.0000008 # Serial clock low time
  27. delayP5 = 0.0000015 # Delay between 4-bit command and command operand
  28. def __init__(self,
  29. chipPackage, chipPinVCC, chipPinsVPP, chipPinGND,
  30. signature,
  31. flashPageSize, flashPages,
  32. eepromPageSize, eepromPages,
  33. fuseBytes
  34. ):
  35. Chip_Microchip8_18_common.__init__(self,
  36. chipPackage, chipPinVCC, chipPinsVPP, chipPinGND,
  37. signature,
  38. flashPageSize, flashPages,
  39. eepromPageSize, eepromPages,
  40. fuseBytes)
  41. def erase(self):
  42. self.progressMeterInit("Erasing chip", 0)
  43. self.enterPM(True)
  44. self.executeCode(self.getCodeAddrToTBLPTR(0x3C0005))
  45. self.send4bitWriteInstruction(self.CMD_TW, 0x3F3F)
  46. self.executeCode(self.getCodeAddrToTBLPTR(0x3C0004))
  47. self.send4bitWriteInstruction(self.CMD_TW, 0x8F8F)
  48. self.executeCode((0x0000,))
  49. self.sendCommand(1)
  50. self.top.hostDelay(self.delayP11 + self.delayP10)
  51. for i in range(0,4):
  52. self.sendCommand(1)
  53. self.top.flushCommands()
  54. self.progressMeterFinish()
  55. def eraseRow(self, rowAddr):
  56. self.executeCode((0x8EA6, 0x9CA6, 0x84A6))
  57. self.executeCode(self.getCodeAddrToTBLPTR(rowAddr))
  58. self.executeCode((0x88A6, 0x82A6))
  59. self.sendCommand(1, 0, 0, 0x0, 1)
  60. self.top.hostDelay(self.delayP9)
  61. self.setPins(0)
  62. self.top.hostDelay(self.delayP10)
  63. def setEEPROMAddr(self, addr):
  64. self.executeCode((0x0E00 | (addr & 0xFF), 0x6EA9, (0x0E00 | ((addr >> 8) & 0xFF)), 0x6EAA))