Subversion Repositories ht46f47_simulator

Rev

Blame | Last modification | View Log | RSS feed

  1. #!/usr/bin/python3
  2.  
  3. # HT46F47 TPS micro controller programmer in Python
  4. # by Daniel Marschall
  5. # Revision 23 May 2020
  6. # Licensed under the terms of the Apache 2.0 license
  7.  
  8. # This script helps you programming the HT46F47 TPS micro controller
  9. # The PINs Reset, S1 and S2 are connected to the collectors of transistors,
  10. # where the emitter is connected to ground and the base is connected to a GPIO pin.
  11. # Therefore, the Raspberry Pi can control the reset, S1 and S2 functionalities
  12. # to automatically program the micro controller.
  13.  
  14. # Note: If the programming fails, you could try increasing the sleep times.
  15. # The following values did work for me, but for larger programs, there could be
  16. # an asynchronity during the programming.
  17.  
  18. import RPi.GPIO as GPIO
  19. import time
  20.  
  21. GPIO_S1  = 13
  22. GPIO_S2  = 19
  23. GPIO_RES = 26
  24.  
  25. GPIO.setwarnings(False)
  26. GPIO.setmode(GPIO.BCM)
  27. GPIO.setup(GPIO_S1,  GPIO.OUT)
  28. GPIO.setup(GPIO_S2,  GPIO.OUT)
  29. GPIO.setup(GPIO_RES, GPIO.OUT)
  30.  
  31. def do_exit():
  32.         GPIO.output(GPIO_S1,  GPIO.LOW)
  33.         GPIO.output(GPIO_S2,  GPIO.LOW)
  34.         GPIO.output(GPIO_RES, GPIO.LOW)
  35.  
  36. def signal_handler(signal, frame):
  37.         do_exit()
  38.         sys.exit(0)
  39.  
  40. def pressButton(pin):
  41.         # 0.025 ist zu gering... da kommt der controller nicht hinterher
  42.         # 0.050 funktioniert
  43.         GPIO.output(pin, GPIO.HIGH)
  44.         time.sleep(0.050)
  45.         GPIO.output(pin, GPIO.LOW)
  46.         time.sleep(0.050)
  47.  
  48. def writeCommandDataPair(befehl, daten):
  49.         #time.sleep(0.050) # Sicherheits-Puffer
  50.         time.sleep(0.300)  # Adresse (untere vier Bit) anzeigen, 300ms
  51.         time.sleep(0.300)  # Anzeige aus, 300ms
  52.         #time.sleep(0.050) # Befehl anzeigen (Sicherheits-Puffer)
  53.         pressButton(GPIO_S1)    # Programmiermodus starten
  54.         for dummy in range(0, befehl):
  55.                 pressButton(GPIO_S1) # Befehl eingeben
  56.         pressButton(GPIO_S2)    # Weiter zu den Daten
  57.         #time.sleep(0.050) # Daten anzeigen (Sicherheits-Puffer)
  58.         pressButton(GPIO_S1)    # Programmiermodus starten
  59.         for dummy in range(0, daten):
  60.                 pressButton(GPIO_S1) # Daten eingeben
  61.         pressButton(GPIO_S2)    # Fortfahren
  62.         time.sleep(0.600)  # Byte einprogrammieren, 600ms
  63.         #time.sleep(0.050) # Sicherheits-Puffer
  64.  
  65. def writeByte(byte):
  66.         befehl = byte >> 4
  67.         daten = byte & 0xF
  68.         writeCommandDataPair(befehl, daten)
  69.  
  70. def startProgrammingMode():
  71.         #time.sleep(0.050)  # Sicherheits-Puffer
  72.         GPIO.output(GPIO_S2, GPIO.HIGH);
  73.         pressButton(GPIO_RES)
  74.         time.sleep(0.500)   # "etwa eine halbe Sekunde" (Handbuch Seite 19)
  75.         #time.sleep(0.050)  # Sicherheits-Puffer
  76.         GPIO.output(GPIO_S2, GPIO.LOW);
  77.         #time.sleep(0.050)  # Sicherheits-Puffer
  78.  
  79. def resetController():
  80.         pressButton(GPIO_RES)
  81.  
  82. # --------------------------------------------------------------------
  83.  
  84. startProgrammingMode()
  85.  
  86. writeByte(0x80) # 00     PAGE 0
  87. writeByte(0x42) # 01(@1) SET A=2                ; "2" means blink 3 times
  88. writeByte(0x52) # 02     SET C=A
  89. writeByte(0x1F) # 03(@2) LED 1111
  90. writeByte(0x26) # 04     WAIT 100ms
  91. writeByte(0x27) # 05     WAIT 200ms
  92. writeByte(0x10) # 06     LED 0000
  93. writeByte(0x26) # 07     WAIT 100ms
  94. writeByte(0x27) # 08     WAIT 200ms
  95. writeByte(0xA3) # 09     CTIMES <PAGE>3(@2)
  96. writeByte(0x42) # 0A     SET A=2                ; "2" means wander 3 times
  97. writeByte(0x52) # 0B     SET C=A
  98. writeByte(0x18) # 0C(@3) LED 1000
  99. writeByte(0x27) # 0D     WAIT 200ms
  100. writeByte(0x14) # 0E     LED 0100
  101. writeByte(0x27) # 0F     WAIT 200ms
  102. writeByte(0x12) # 10     LED 0010
  103. writeByte(0x27) # 11     WAIT 200ms
  104. writeByte(0x11) # 12     LED 0001
  105. writeByte(0x27) # 13     WAIT 200ms
  106. writeByte(0x12) # 14     LED 0010
  107. writeByte(0x27) # 15     WAIT 200ms
  108. writeByte(0x14) # 16     LED 0100
  109. writeByte(0x27) # 17     WAIT 200ms
  110. writeByte(0xAC) # 18     CTIMES <PAGE>C(@3)
  111. writeByte(0x18) # 19     LED 1000
  112. writeByte(0x27) # 1A     WAIT 200ms
  113. writeByte(0x10) # 1B     LED 0000
  114. writeByte(0x27) # 1C     WAIT 200ms
  115. writeByte(0x91) # 1D     JUMP <PAGE>1(@1)
  116.  
  117. resetController() # Reset controller to run program
  118.  
  119. do_exit()
  120.