Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Michael Cartwright
Published

RS232: using a Rockwell R6551AP ACIA with a 6502 computer

Following along with Ben Eater's 6502 series but you have a Rockwell 6551 rather than a WSC one? Here's how to make it work.

IntermediateProtip1 hour465
RS232: using a Rockwell R6551AP ACIA with a 6502 computer

Things used in this project

Hardware components

R6551AP
×1

Software apps and online services

PuTTY

Story

Read more

Schematics

R6551AP ACIA for 6502 schematic

Code

Minimal but complete code for the 6551 ACIA interface

Assembly x86
The commented out LCD APIs give were used by me to echo the characters on the 6502 computer to the 20x4 LCD. They are useful for testing but not required to demonstrate that the RS232 is working.
; yes, these are port addresses : mine are on the zero page
ACIADATA    = $EC ; 00
ACIASTATUS  = $ED ; 01
ACIACOMMAND = $EE ; 10
ACIACONTROL = $EF ; 11

  .org $8000

start:

  sei              ; disable interrupts
  cld              ; clear decimal arithmetic mode.
  
  ldx #$ff         ; reset stack pointer
  txs
  
  ; initialise 6551 ACIA
  lda #$00       ; soft reset (value not important)
  sta ACIASTATUS 
  
  lda #%00011110         ; 8-N-1, 9600 baud
  ;lda #%00011111        ; 8-N-1, 19200 baud
  sta ACIACONTROL
  
  lda #%00001011  ; set specific modes and functions
                  ; no parity, no echo, no Tx interrupt
                  ; no Rx interrupt, enable Tx/Rx
  sta ACIACOMMAND ; save to command register
  
  
  cli            ; enable interrupts
  
  ;jsr LCDString
  ;.byte "ACIA Testing:"
  ;.byte 0
  ;jsr LCDNewLine
  
loopkey:
  lda ACIASTATUS
  and #%00001000 ; key available? (Receiver Data Register Full (Bit 3))
  beq loopkey    ; loop if buffer is empty
  
  lda ACIADATA
  
  cmp #$0D; enter?
  bne notEnter
  ;jsr LCDNewLine
  bra echo

notEnter:
  cmp #$08; backspace?
  bne notBackspace
  ;jsr LCDBackspace
  bra echo

notBackspace:
  cmp #$1B; escape?
  bne notEscape
  ;jsr LCDClear
  bra echo
  
notEscape:
  cmp #$20; space
  bcc notPrintable
  ;jsr LCDCharacter
  bra echo
  
  
notPrintable:
  ;jsr LCDHexCharacters
  ;lda #" "
  ;jsr LCDCharacter
  bra echo

echo:

  ; delay to deal with the Transmitter Data Register Empty bug
  ldx #104 ; 19200 bps : 1 bit every 52 clock cycles x 10 bits 
           ; per character = 520 clock cycles (as per Ben's description)
txDelay:
  dex          ; 2x104 = 208
  bne txDelay  ; 3x104 = 312
               ;         ---
               ;         520 clock cycles

  sta ACIADATA

  bra loopkey

irq:
  rti
  
nmi:
  rti

; Reset/IRQ vectors
  .org $fffa
  .word nmi
  .word start
  .word irq    

Credits

Michael Cartwright
21 projects • 16 followers
Contact

Comments

Please log in or sign up to comment.