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
+510
View File
@@ -0,0 +1,510 @@
; -------------------------------------------------
; Uart test
; -------------------------------------------------
reset: jmp init
org 0x001
jmp isr
; -------------------------------------------------
; Constants
; -------------------------------------------------
ram_start: equ 0x00 ; R/W
txt_start: equ 0x80 ; RO
txt_end: equ 0x8B ; RO
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
lcd_read: equ 0x20
lcd_data: equ 0x40
lcd_enable: equ 0x80
DIV10: equ 0x0A
CR: equ 0x0D
LF: equ 0x0A
count0: equ 0x00
count1: equ 0x01
count2: equ 0x02
count3: equ 0x03
cntDigit0: equ 0x04
cntDigit1: equ 0x05
cntDigit2: equ 0x06
cntDigit3: equ 0x07
cntDigit4: equ 0x08
cntDigit5: equ 0x09
cntDigit6: equ 0x0A
cntDigit7: equ 0x0B
LCD_CMD_Z1: equ 0x80
LCD_CMD_Z2: equ 0xC0
count_stat: equ 0x0C
; Chip register
cpu_revision: equ 0x00 ; RO
cpu_control: equ 0x01 ; R/W
cpu_status: equ 0x02 ; RO
cpu_int_ctrl: equ 0x03 ; R/W
; -------------------------------------------------
; Main
; -------------------------------------------------
org 010
init: mov R1, 0x55
movx (led_port), R1
; jmp init
call CounterInit
call LCD_init
mov R0, 0x00
movc (count_stat), R0
mov R1, 0x04
movx R0, (btn_port)
and R0, 0x01
jz not_pressed
mov R1, 0x00
not_pressed: movx (led_port), R1
mov R0, ctrl_reg
; Enable timer
movx (R0), 0x02
; Enable interrupt
movx (R0), 0x03
; Enable CPU interrupt
cin R0, (cpu_int_ctrl)
or R0, 0x01
cout (cpu_int_ctrl), R0
start: halt
call Cnt32
call UpdateDigits
mov R15, cntDigit7
movc R0, (count_stat)
tst R0
jz start
mov R0, 0x00
movc (count_stat), R0
loop: call subprog
movc R0, (R15)
call sout
cmp R15, cntDigit0
jeq sendCRLF
dec R15
jmp loop
sendCRLF: mov R0, CR
call sout
mov R0, LF
call sout
jmp start
; -------------------------------------------------
CounterInit: mov R0, 0x00
movc (count0), R0
movc (count1), R0
movc (count2), R0
movc (count3), R0
ret
Cnt32: mov R0, count0
cloop: movc R1, (R0)
inc R1
movc (R0), R1
; ----------------
mov R7, R1
mov R14, R7
mov R7, 0x55
mov R7, 0xAA
xor R7, R7
xor R14, 0x99
; ----------------
jnc CountRdy
cmp R0, count3
jeq CountRdy
inc R0
jmp cloop
CountRdy: ret
UpdateDigits: mov R2, cntDigit0
mov R0, count0
dualLoop: movc R1, (R0)
and R1, 0x0F
cmp R1, 0x0A
jlt isNum1
add R1, 0x07
isNum1: add R1, 0x30
movc (R2), R1
inc R2
movc R1, (R0)
shr R1
shr R1
shr R1
shr R1
and R1, 0x0F
cmp R1, 0x0A
jlt isNum2
add R1, 0x07
isNum2: add R1, 0x30
movc (R2), R1
cmp R0, count3
jeq UpdRdy
inc R0
inc R2
jmp dualLoop
UpdRdy: ret
; -------------------------------------------------
; subprog
; -------------------------------------------------
subprog: push R0
push R1
push R2
push R3
push R4
push R5
push R6
push R7
push R8
push R9
push R10
push R11
push R12
push R13
push R14
push R15
pop R15
pop R14
pop R13
pop R12
pop R11
pop R10
pop R9
pop R8
pop R7
pop R6
pop R5
pop R4
pop R3
pop R2
pop R1
pop R0
ret
; -------------------------------------------------
; 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
; -------------------------------------------------
; ISR
; -------------------------------------------------
isr: push R0
push R1
movx R0, (led_port)
xor R0, 0x02
movx (led_port), R0
call LCD_clear
mov R0, LCD_CMD_Z1
call LCD_writecmd
mov R1, txt_start
read_rom: movx R0, (R1)
call LCD_writechar
inc R1
cmp R1, txt_end
jlt read_rom
mov R0, LCD_CMD_Z2
call LCD_writecmd
mov R1, cntDigit1
movc R0, (R1)
mov R1, cntDigit7
cmp R0, 0x30
jne print_num
mov R0, 0x01
movc (count_stat), R0
print_num: movc R0, (R1)
call LCD_writechar
cmp R1, cntDigit0
jeq ex_isr
dec R1
jmp print_num
ex_isr: call delay1ms
pop R1
pop R0
reti
; -------------------------------------------------
; 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