git-svn-id: http://moon:8086/svn/vhdl/trunk@1414 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
2021-03-21 10:47:01 +00:00
parent 32440f7db9
commit ea60299d26
80 changed files with 37322 additions and 0 deletions
+379
View File
@@ -0,0 +1,379 @@
; -------------------------------------------------
; Constants
; -------------------------------------------------
lcd_read: equ 0x20
lcd_data: equ 0x40
lcd_enable: equ 0x80
DIV10: equ 0x0A
CR: equ 0x0D
LF: equ 0x0A
LCD_CMD_Z1: equ 0x80
LCD_CMD_Z2: equ 0xC0
; I/O
btn_port: equ 0xC0 ; RO
led_port: equ 0xC1 ; Write
uart_data: equ 0xC2 ; Write
lcd_port: equ 0xC3 ; R/W
ctrl_reg: equ 0xC4 ; R/W
dip_port: equ 0xC5 ; RO
uart_status: equ 0xC6 ; Read
; -------------------------------------------------
; Program
; -------------------------------------------------
reset: jmp init
org 0x001
reti
; -------------------------------------------------
; Main
; -------------------------------------------------
init: call LCD_init
; Print Hello world
call LCD_clear
; J
mov R0, 0x4A
call LCD_writechar
call sout
; -
mov R0, 0x2D
call LCD_writechar
call sout
; C
mov R0, 0x43
call LCD_writechar
call sout
; P
mov R0, 0x50
call LCD_writechar
call sout
; U
mov R0, 0x55
call LCD_writechar
call sout
;
mov R0, 0x20
call LCD_writechar
call sout
; V
mov R0, 0x56
call LCD_writechar
call sout
; 1
mov R0, 0x31
call LCD_writechar
call sout
; .
mov R0, 0x2E
call LCD_writechar
call sout
; 0
mov R0, 0x30
call LCD_writechar
call sout
; CRLF
mov R0, LCD_CMD_Z2
call LCD_writecmd
mov R0, CR
call sout
mov R0, LF
call sout
; R
mov R0, 0x52
call LCD_writechar
call sout
; E
mov R0, 0x65
call LCD_writechar
call sout
; A
mov R0, 0x61
call LCD_writechar
call sout
; D
mov R0, 0x64
call LCD_writechar
call sout
; Y
mov R0, 0x79
call LCD_writechar
call sout
; CRLF
mov R0, CR
call sout
mov R0, LF
call sout
jjj: jmp jjj
; -------------------------------------------------
; sout
; -------------------------------------------------
; R0 = input
sout: push R1
sout1: movx R1, (uart_status)
and R1, 0x02
jnz sout1
movx (uart_data), R0
pop R1
ret
; -------------------------------------------------
; sin
; -------------------------------------------------
; R0 = output
sin: push R1
sin1: movx R1, (uart_status)
and R1, 0x10
jnz sin1
movx R0, (uart_data)
pop R1
ret
; -------------------------------------------------
; Init LCD
; -------------------------------------------------
LCD_init: mov R1, lcd_port
movx (R1), lcd_read
call delay10ms
; 0.
mov R2, 0x00
mov R0, 0x03
call LCD_write_
call delay10ms
mov R2, 0x00
mov R0, 0x03
call LCD_write_
call delay10ms
mov R2, 0x00
mov R0, 0x02
call LCD_write_
call delay1ms
; 1.
mov R0, 0x28
call LCD_writecmd
; 2.
mov R0, 0x0E
call LCD_writecmd
; 3.
mov R0, 0x06
call LCD_writecmd
; 3.
mov R0, 0x01
call LCD_writecmd
ret
; -------------------------------------------------
; LCD_Clear
; -------------------------------------------------
LCD_clear: push R0
mov R0, 0x01
call LCD_writecmd
pop R0
ret
; -------------------------------------------------
; LCD_writecmd
; -------------------------------------------------
; R0 = cmd
LCD_writecmd: call LCD_waitbsy
push R2
push R0
push R0
mov R2, 0x00
shr R0
shr R0
shr R0
shr R0
call LCD_write_
pop R0
and R0, 0x0F
call LCD_write_
pop R0
pop R2
ret
; -------------------------------------------------
; LCD_writechar
; -------------------------------------------------
; R0 = char
LCD_writechar: call LCD_waitbsy
push R2
push R0
push R0
mov R2, lcd_data
shr R0
shr R0
shr R0
shr R0
call LCD_write_
pop R0
and R0, 0x0F
call LCD_write_
pop R0
pop R2
ret
; -------------------------------------------------
; LCD_write_
; -------------------------------------------------
; R0 = input
LCD_write_: push R1
mov R1, R0
or R1, R2
movx (lcd_port), R1
call delay1us
mov R1, R0
or R1, R2
or R1, lcd_enable
movx (lcd_port), R1
call delay1us
mov R1, R0
or R1, R2
movx (lcd_port), R1
call delay1us
pop R1
ret
; -------------------------------------------------
; LCD_read_
; -------------------------------------------------
; R0 = output
LCD_read_: push R1
mov R1, lcd_read
or R1, R2
movx (lcd_port), R1
call delay1us
mov R1, lcd_read
or R1, R2
or R1, lcd_enable
movx (lcd_port), R1
call delay1us
movx R0, (lcd_port)
mov R1, lcd_read
or R1, R2
movx (lcd_port), R1
call delay1us
pop R1
ret
; -------------------------------------------------
; LCD_readstat
; -------------------------------------------------
; R0 = status
LCD_readstat: push R2
mov R2, 0x00
call LCD_read_
shl R0
shl R0
shl R0
shl R0
push R0
call LCD_read_
and R0, 0x0F
pop R2
or R0, R2
pop R2
ret
; -------------------------------------------------
; LCD_waitbsy
; -------------------------------------------------
LCD_waitbsy: push R0
bsy_loop: call LCD_readstat
and R0, 0x80
jz ex_bsy
call delay1us
jmp bsy_loop
ex_bsy: pop R0
ret
; -------------------------------------------------
; Delays
; -------------------------------------------------
delay1s: push R15
mov R15, DIV10
loop1s: call delay100ms
dec R15
jnz loop1s
pop R15
ret
delay100ms: push R15
mov R15, DIV10
loop100ms: call delay10ms
dec R15
jnz loop100ms
pop R15
ret
delay10ms: push R15
mov R15, DIV10
loop10ms: call delay1ms
dec R15
jnz loop10ms
pop R15
ret
delay1ms: push R15
mov R15, DIV10
loop1ms: call delay100us
dec R15
jnz loop1ms
pop R15
ret
delay100us: push R15
mov R15, DIV10
loop100us: call delay10us
dec R15
jnz loop100us
pop R15
ret
delay10us: push R15
mov R15, DIV10
loop10us: call delay1us
dec R15
jnz loop10us
pop R15
ret
delay1us: push R15
mov R15, DIV10
loop1us: call delay100ns
dec R15
jnz loop1us
pop R15
ret
delay100ns: nop
nop
nop
nop
ret