Mirror of CollapseOS
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

140 строки
2.7KB

  1. ; Use this as a debug companion to at28wr. This simply dumps, TTY-escaped, the
  2. ; contents of the AT28.
  3. ;
  4. ; TODO: not always, but sometimes, the output starts with a spurious 0xFF. But
  5. ; otherwise, the rest of the contents is good, albeit offset by 1 (that is, the
  6. ; byte after the spurious 0xFF is the contents at addr 0). Weird, to fix.
  7. .include "m328Pdef.inc"
  8. ; *** Pins ***
  9. .equ SRCP = PORTB2
  10. .equ SRDS = PORTB1
  11. .equ FLWE = PORTB3
  12. .equ FLOE = PORTB4
  13. .equ FLCE = PORTB5 ; WARNING: same as LED
  14. ; *** Consts ***
  15. .equ BAUD_PRESCALE = 103 ; 9600 bauds at 16mhz
  16. rjmp main
  17. ; *** Code ***
  18. ; Sends char in r20 to UART
  19. ; Perform TTY-escape transparently.
  20. uartwr:
  21. lds r16, UCSR0A
  22. sbrs r16, UDRE0 ; wait until send buffer is empty
  23. rjmp uartwr
  24. ; should we escape?
  25. cpi r20, 0x21
  26. brsh uartwr_0 ; r20 >= 0x21, skip
  27. ; escape
  28. ori r20, 0x80
  29. ldi r16, 0x20
  30. sts UDR0, r16
  31. rjmp uartwr
  32. uartwr_0:
  33. sts UDR0, r20
  34. ret
  35. ; send r23 to addr shift register.
  36. ; We send highest bits first so that Q7 is the MSB and Q0 is the LSB
  37. sendaddr:
  38. ldi r16, 8 ; we will loop 8 times
  39. cbi PORTB, SRDS
  40. sbrc r23, 7 ; if latest bit isn't cleared, set SER_DP high
  41. sbi PORTB, SRDS
  42. ; toggle SRCP, not waiting between pulses. The CD74AC164 at 5V has a
  43. ; 5.9ns CP min pulse width. We can't match that at 16mhz. No need to
  44. ; wait.
  45. cbi PORTB, SRCP
  46. sbi PORTB, SRCP
  47. lsl r23 ; shift our data left
  48. dec r16
  49. brne sendaddr+1 ; not zero yet? loop! (+1 to avoid reset)
  50. ret
  51. ; push r20 to the rom and increase the memory counter
  52. nextaddr:
  53. ; first, set up addr
  54. mov r23, r21
  55. rcall sendaddr
  56. mov r23, r22
  57. rcall sendaddr
  58. inc r22
  59. brne nextaddr_0 ; no overflow? skip
  60. inc r21
  61. nextaddr_0:
  62. ret
  63. ; read EEPROM's I/O7:0 through PD7:2 and PB1:0 into r20
  64. readdata:
  65. cbi PORTB, FLCE
  66. cbi PORTB, FLOE
  67. nop ; 70ns max delay on at28
  68. nop
  69. nop
  70. nop
  71. ; read bits 7:2
  72. in r20, PIND
  73. andi r20, 0xfc
  74. ; read bits 1:0
  75. in r16, PINB
  76. andi r16, 0x03
  77. or r20, r16
  78. sbi PORTB, FLOE
  79. sbi PORTB, FLCE
  80. ret
  81. ; Set PD7:2 and PB1:0 to output
  82. ioout:
  83. ldi r16, 0xfc ; PD7:2
  84. out DDRD, r16
  85. ldi r16, 0x3f ; PB5:0 (CP, WE, OE and CE too)
  86. out DDRB, r16
  87. ret
  88. ; Set PD7:2 and PB1:0 to input
  89. ioin:
  90. ldi r16, 0x03 ; PD7:2
  91. out DDRD, r16
  92. ldi r16, 0x3c ; PB1:0
  93. out DDRB, r16
  94. ret
  95. main:
  96. ldi r16, low(RAMEND)
  97. out SPL, r16
  98. ldi r16, high(RAMEND)
  99. out SPH, r16
  100. ; We begin with WE and OE disabled (high), but CE stays enabled (low)
  101. ; the whole time.
  102. sbi PORTB, FLWE
  103. sbi PORTB, FLOE
  104. sbi PORTB, FLCE
  105. ; Clear counters and flags
  106. clr r21
  107. clr r22
  108. ; Setup UART
  109. ldi R16, low(BAUD_PRESCALE)
  110. sts UBRR0L, r16
  111. ldi r16, high(BAUD_PRESCALE)
  112. sts UBRR0H, r16
  113. ldi r16, (1<<TXEN0)
  114. sts UCSR0B, r16
  115. loop:
  116. rcall ioout
  117. rcall nextaddr
  118. rcall ioin
  119. rcall readdata
  120. rcall uartwr
  121. rjmp loop