⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.asm

📁 6502bios,关于6502的sbc,有lcd,time,irq,模块
💻 ASM
字号:
; Functions for HD44780 compatible character LCD displays
; Chris Ward, 26/11/1999
; Some functions assume 40x1 display

_LCD	;remember start address

; Registers
	ORG LCD
LCD0	.ds 1
LCD1	.ds 1

	ORG _LCD
; *** LCD initialisation
; Y preserved
LINIT	LDX #$04		;do function set 4 times
LINIT0	LDA #$38		;function set: 8 bit, 2 lines, 5x7
	STA LCD0
	JSR LCDBUSY	;wait for busy flag to clear
	DEX
	BNE LINIT0
	LDA #$06		;entry mode set: increment, no shift
	STA LCD0
	JSR LCDBUSY
	LDA #$0E		;display on, cursor on, blink off
	STA LCD0
	JSR LCDBUSY
	LDA #$01		;clear display
	STA LCD0
	JSR LCDBUSY
	LDA #$80		;DDRAM address set: $00
	STA LCD0
	RTS
LINITMSG	fcs "LCD init done. "
	.byte $00

; *** Wait for LCD busy bit to clear
; A,X,Y preserved
LCDBUSY	PHA
LCDBUSY0	LDA LCD0		;read from LCD register 0
	BMI LCDBUSY0	;check bit 7 (busy)
	PLA
	RTS

; *** Clear LCD display and return cursor to home
; A,X,Y preserved
LCDCLR	PHA
	JSR LCDBUSY
	LDA #$01
	STA LCD0
	JSR LCDBUSY
	LDA #$80
	STA LCD0
	PLA
	RTS

; *** Print character on LCD
; input: A = ASCII char
; A,X,Y preserved
LCDCHAR	JSR LCDBUSY	;check not busy
	STA LCD1		;send char to LCD
	PHA
	JSR LCDBUSY	;wait for operation to complete
	LDA LCD0		;get current DDRAM address
	AND #$7F
	CMP #$14		;wrap from pos $13 (line 1 char 20)...
	BNE LCDPRIN0
	LDA #$C0		;...to $40 (line 2 char 1)
	STA LCD0
	JMP LCDPRIN1
LCDPRIN0	CMP #$54		;and from pos $53 (line 2 char 20)...
	BNE LCDPRIN1
	LDA #$80		;...to $00 (line 1 char 1)
	STA LCD0
LCDPRIN1	PLA
	RTS

; *** LCDGETXY: Get cursor position
; output: X = X position
;         Y = Y position
; A preserved
LCDGETXY	JSR LCDBUSY	;check not busy
	PHA
	LDA LCD0
	CMP #$40
	BMI LCDGETX0
	SEC
	SBC #$40
LCDGETX0	TAX
	LDY #$00		;Y must be 0 for our 1-line display
	PLA
	RTS

; *** LCDSETXY: Set cursor position
; input: X = X position
;        Y = Y position
; A preserved
LCDSETXY	JSR LCDBUSY	;check not busy
	PHA
	TXA
	CMP #$14
	BMI LCDSETX0
	CLC
	ADC #$40
LCDSETX0	ORA #$80
	STA LCD0
	PLA
	RTS

; *** Print 2 digit hex number on LCD
; (or call LCDHEX1 to print single digit (upper 4 bits ignored))
; input: A = number to print
; A,X,Y preserved
LCDHEX	PHA
	LSR A		;shift high nybble into low nybble
	LSR A
	LSR A
	LSR A
	ORA #$30
	CMP #$3A
	BMI LCDHEX0
	CLC
	ADC #$07
LCDHEX0	JSR LCDCHAR	;print value on the LCD
	PLA		;restore original value
LCDHEX1	PHA
	AND #$0F		;select low nybble
	ORA #$30
	CMP #$3A
	BMI LCDHEX2
	CLC
	ADC #$07
LCDHEX2	JSR LCDCHAR	;print value on the LCD
	PLA
	RTS
	
; *** Print string on LCD (null terminated)
; input: MSGBASE = pointer to start of string
; X,Y preserved
LCDSTR	TYA		;save Y to stack
	PHA
	LDY #$00
LCDSTR0	LDA (MSGBASE),Y
	BEQ LCDSTR1
	JSR LCDCHAR
	INY
	BNE LCDSTR0
LCDSTR1	PLA		;restore Y
	TAY
	RTS

; *** Print string on LCD (number of characters specified)
; input: MSGBASE = pointer to start of string
;        X = no. of chars to print
; Y preserved
LCDSTRN	CPX #$00
	BEQ LCDSTRN2
	TYA
	PHA
	LDY #$00
LCDSTRN0	LDA (MSGBASE),Y
	JSR LCDCHAR
	INY
	DEX
	BNE LCDSTRN0
LCDSTRN1	PLA
	TAY
LCDSTRN2	RTS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -