Einfachers Programmiergerät für 93c66

#2329024
Lesenswert?
• ▲
▼
Hier haste die EEPROM-Routinen die ich einsetze, sollten für den 93C56 
und 93C66 im Word-Mode (16bit) funktionieren. Sind 
quick'n'dirty-Varianten, Hauptsache funktioniert und ohne Optimierungen 
- für die paar Byte schnell genug.

Der µC ist bei mir ein Atmega644 - was kleineres mit ausreichender 
Anzahl Pins war nicht da. (Das Ding beinhaltet ja ein Tastenfeld und ein 
LCD-Display, damit es ohne PC auskommt.)

Die Delays kannste Dir auch selber bauen, das Flag EWENExecuted 
brauchste nicht wenn Du nicht viel schreibst.

Portbelegung: PB0: CS
              PB1: SK
              PB2: DI
              PB3: DO

EEPROM_EraseCommand: ;sends the ERASE Command to the EEPROM
  rcall  SendEWEN
  push  r16
  sbi  PortB,0  ;CS on
  ldi  r16,1
  rcall  SendBit
  ldi  r16,0
  rcall  SendBit
  rcall  SendBit
  ldi  r16,1
  rcall  SendBit
  ldi  r16,0
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  cbi  PortB,0 ;CS off
  rcall  delay100ms ;wait for the EEPROM to become ready again
  rcall  delay100ms
  pop  r16
  ret

Write_EEPROM_Block:  ;write 16 bit (2 byte) into EEPROM
                    ;R20: block number
  push  r16  ;R16: first data byte
  push  r17  ;R17: second data byte
  push  r18
  push  r20
  rcall  SendEWEN
  sbi  PortB,0 ;CS on
  push  r16
         ldi  r16,1
  rcall  SendBit
  ldi  r16,0
  rcall  SendBit
  ldi  r16,1
  rcall  SendBit  ;OpCode sent
  ldi  r18,8  ;send adress
WEB_a1:  rol  r20
  brcs  WEB_a2
  ldi  r16,0
  rjmp  WEB_a3
WEB_a2:  ldi  r16,1
WEB_a3:  rcall  SendBit
  dec  r18
  brne  WEB_a1
  pop  r16
  ldi  r18,8  ;send data byte 1
  mov  r20,r16
WEB_b11:  rol  r20
  brcs  WEB_b12
  ldi  r16,0
  rjmp  WEB_b13
WEB_b12:  ldi  r16,1
WEB_b13:  rcall  SendBit
  dec  r18
  brne  WEB_b11
  ldi  r18,8  ;send data byte 2
WEB_b21:  rol  r17
  brcs  WEB_b22
  ldi  r16,0
  rjmp  WEB_b23
WEB_b22:  ldi  r16,1
WEB_b23:  rcall  SendBit
  dec  r18
  brne  WEB_b21
  cbi  PortB,0  ;CS off
  rcall  delay20ms; wait for the EEPROM become ready after write
  pop  r20
  pop  r18
  pop  r17
  pop  r16
  ret

Read_EEPROM_Block:    ;read 16 bit (2 byte) from EEPROM
                    ;block number contained in R20
  push  r20  ;Output in R16 and R17
  push  r18  ;(0xR16R17h)
  sbi  PortB,0 ;CS on
  ldi  r16,1
  rcall  SendBit
  rcall  SendBit
  ldi  r16,0
  rcall  SendBit
  ldi  r17,8
REBSend1:  rol  r20
  brcs  REBSendB1
  ldi  r16,0
  rjmp  REBSendBx
REBSendB1:ldi  r16,1
REBSendBx:rcall  SendBit
  dec  r17
  brne  REBSend1
  rcall  shortdelay ;command sent, get result
  ldi  r17,0
  ldi  r18,8
REBGetB1:  rcall  ReadBit
  ror  r16
  rol  r17
  dec  r18
  brne  REBGetB1
  push  r17
  ldi  r17,0
  ldi  r18,8
REBGetB2:  rcall  ReadBit
  ror  r16
  rol  r17
  dec  r18
  brne  REBGetB2
  cbi  PortB,0 ;CS off
  rcall  shortdelay
  pop  r16
  pop  r18
  pop  r20
  ret

SendBit:  cpi  r16,0  ;Send a Bit, 0 when R16 is 0
  breq  SendBit0
SendBit1:  sbi  PortB,2 ;DI on
  rjmp  SendBitX
SendBit0:  cbi  PortB,2 ;DI off
SendBitX:  rcall  shortdelay
  sbi  PortB,1 ;SK on
  rcall  shortdelay
  cbi  PortB,1 ;SK off
  cbi  PortB,2 ;DI off
  ret

ReadBit: sbi  PortB,1 ;SK on    ;Read Bit, result in R16
  rcall  shortdelay
  in  r16,PinB
  cbi  PortB,1 ;SK off
  rcall  shortdelay
  andi  r16,0b00001000
  cpi  r16,0
  breq     ReadBit0
  ldi  r16,1
ReadBit0:  ret

SendEWEN:  push  r16      ;Send EWEN to the EEPROM
  lds  r16,EWENExecuted
  cpi  r16,1
  breq  SendEWENx
  sbi  PortB,0 ;CS on
  ldi  r16,1
  rcall  SendBit
  ldi  r16,0
  rcall  SendBit
  rcall  SendBit
  ldi  r16,1
  rcall  SendBit
  rcall  SendBit
  ldi  r16,0
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  rcall  SendBit
  cbi  PortB,0 ;CS off
  rcall  shortdelay
  ldi  r16,1
  sts  EWENExecuted,r16
SendEWENx:pop  r16
  ret

(Forensoftware crasht leider die Formatierung... Sorry.)

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.