Re: 6502 PCB Power On Issues
Posted: Thu Jul 01, 2021 1:40 am
Thanks, I will definitely have a good read through
Code: Select all
PORTB = $6000
PORTA = $6001
DDRB = $6002
DDRA = $6003
E = %10000000
RW = %01000000
RS = %00100000
.org $8000
reset:
ldx #$ff
txs
lda #%11111111 ; Set all pins on port B to output
sta DDRB
lda #%11100000 ; Set top 3 pins on port A to output
sta DDRA
lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
jsr lcd_instruction
lda 50
jsr _delay_ms
lda #%00001110 ; Display on; cursor on; blink off
jsr lcd_instruction
lda 50
jsr _delay_ms
lda #%00000110 ; Increment and shift cursor; don't shift display
jsr lcd_instruction
lda 50
jsr _delay_ms
lda #$00000001 ; Clear display
jsr lcd_instruction
lda 50
jsr _delay_ms
ldx #0
print:
lda message,x
beq loop
jsr print_char
inx
jmp print
loop:
jmp loop
message: .asciiz "Hello, world!"
lcd_wait:
pha
lda #%00000000 ; Port B is input
sta DDRB
lcdbusy:
lda #RW
sta PORTA
lda #(RW | E)
sta PORTA
lda PORTB
and #%10000000
bne lcdbusy
lda #RW
sta PORTA
lda #%11111111 ; Port B is output
sta DDRB
pla
rts
lcd_instruction:
jsr lcd_wait
sta PORTB
lda #0 ; Clear RS/RW/E bits
sta PORTA
lda #E ; Set E bit to send instruction
sta PORTA
lda #0 ; Clear RS/RW/E bits
sta PORTA
rts
print_char:
jsr lcd_wait
sta PORTB
lda #RS ; Set RS; Clear RW/E bits
sta PORTA
lda #(RS | E) ; Set E bit to send instruction
sta PORTA
lda #RS ; Clear E bits
sta PORTA
rts
_delay_ms:
sta tmp1 ; 3
txa ; 2
pha ; 3
tya ; 2
pha ; 3
ldx tmp1 ; 3
ldy #190 ; 2
@loop1:
dey ; 190 * 2
bne @loop1 ; 190 * 3 - 1
@loop2:
dex ; 2
beq @return ; (x - 1) * 2 + 3
nop ; 2
ldy #198 ; 2
@loop3:
dey ; 198 * 2
bne @loop3 ; 198 * 3 - 1
jmp @loop2 ; 3
@return:
pla ; 4
tay ; 2
pla ; 4
tax ; 2
lda tmp1 ; 3
rts ; 6 (+ 6 for JSR)
.org $fffc
.word reset
.word $0000Code: Select all
0xa9, 0xff, # lda #$1f
0x8d, 0x02, 0x60, # sta $6003
0xa9, 0x55, # lda #$1f
0x8d, 0x00, 0x60, # sta $6001
0xa9, 0xaa, # lda #$00
0x8d, 0x00, 0x60, # sta $6001
0x4c, 0x05, 0x80, # jmp $8005