📄 lcd.asm
字号:
mov A,[X+BG_ROW] ; Row in A
mov X,[X+BG_COL] ; Col in X
call LCD_Position ; Set cursor position
pop X
LCD_BG_LOOP1:
cmp [X+BG_LENGTH],00h ; Check for past end of BG
jnz LCD_CHECK1
mov A,00h ; Load empty character
jmp LCD_BG_DOIT ;
LCD_CHECK1:
cmp [X+BG_LENGTH],06h ; Check if BG pointer is at this character
jnc LCD_CHECK2 ; Note yet, use full character
mov A,[X+BG_LENGTH]
sub [X+BG_LENGTH],A
jmp LCD_BG_DOIT
LCD_CHECK2: ; Put index to full character
mov A, 06h
sub [X+BG_LENGTH],05h ; Subtract another 5 positions
LCD_BG_DOIT:
call LCD_WriteData ; Display BG character
dec [X+BG_CHAR_LEN] ; Dec Char count
jnz LCD_BG_LOOP1 ; Do it all over again
RAM_EPILOGUE RAM_USE_CLASS_2
ret
.ENDSECTION
IF SYSTEM_SMALL_MEMORY_MODEL
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: LCD_DrawVBG
;
; DESCRIPTION:
; This legacy fastcall version are provided only to support existing small
; memory model assembly language code---it does not work in the large memory
; model.
;
; ** This legacy fastcall version is provided on a temporary basis to
; ** ease the transition to the 4.2 release of PSoC Designer. Its use is
; ** deprecated and its status is "No Further Maintenance". If you call this
; ** function in assembly you should convert to _LCD_DrawVBG
; ** (with a leading underscore) and the fastcall16 interface
;
; Draw a vertical bargraph on the LCD with the given parameters. This
; is a legacy function that is intended to support existing Assembly
; language programs that call this function. This should not be used for
; new code or with Large Memory Model programs.
;-----------------------------------------------------------------------------
;
; LEGACY FASTCALL ARGUMENTS:
; A => Starting row for bargraph 0 to 3
; [X] => Starting Column for bargraph 0 to 40+
; [x-1] => Height of bargraph in chars 1 - 4
; [X-2] => Position of pointer in segments 8 times height
; RETURNS:
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; If LCD_Init is not called before this function, the
; bargraph will not be drawn properly.
;
; Stack offset constants
VBG_COLX: equ 0
VBG_CHAR_HEIGHTX: equ -1
VBG_SEG_HEIGHTX: equ -2
LCD_DrawVBG:
and A,03h ; Make sure only rows 0 - 3 are valid
VBG_LOOPX:
push A
index LCD_ROW_OFFSET ; Get row offset
add A,[X+VBG_COLX] ; Add column offset to position
call LCD_Control ; Position Cursor
cmp [X+VBG_SEG_HEIGHTX],00h ; Check for zero segs
jnz VBG_NZ_SEGX
mov A,' ' ; Load space character
jmp VBG_WRITE_CHARX
VBG_NZ_SEGX:
cmp [X+VBG_SEG_HEIGHTX],09h ; Check for full segment
jnc VBG_FULL_SEGX
; Partial segment between 1 and 8
mov A,[X+VBG_SEG_HEIGHTX]
dec A
mov [X+VBG_SEG_HEIGHTX],00h ; Zero segment height
jmp VBG_WRITE_CHARX
VBG_FULL_SEGX: ; Bargaph
sub [X+VBG_SEG_HEIGHTX],08h ; Subtract full segment
mov A,07h ; Load full segment
VBG_WRITE_CHARX: ; Write character to display
call LCD_WriteData ; Write value
pop A
dec A
dec [X+VBG_CHAR_HEIGHTX]
jnz VBG_LOOPX
ret
.ENDSECTION
ENDIF ; SYSTEM_SMALL_MEMORY_MODEL
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: LCD_DrawVBG
;
; DESCRIPTION:
; Draw a vertical bargraph on the LCD with the given parameters.
;
;
;-----------------------------------------------------------------------------
;
; FASTCALL16 ARGUMENTS:
;
; [SP-3] => Starting row for bargraph 0 to 3
; [SP-4] => Starting Column for bargraph 0 to 40+
; [SP-5] => Height of bargraph in chars 1 - 4
; [SP-6] => Position of pointer in segments 8 times height
; RETURNS:
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
; If LCD_Init is not called before this function, the
; bargraph will not be drawn properly.
;
; Stack offset constants
VBG_ROW: equ -3
VBG_COL: equ -4
VBG_CHAR_HEIGHT: equ -5
VBG_SEG_HEIGHT: equ -6
_LCD_DrawVBG:
RAM_PROLOGUE RAM_USE_CLASS_2
mov X, SP
mov A, [X+VBG_ROW]
and A,03h ; Make sure only rows 0 - 3 are valid
VBG_LOOP:
push A
index LCD_ROW_OFFSET ; Get row offset
add A,[X+VBG_COL] ; Add column offset to position
call LCD_Control ; Position Cursor
cmp [X+VBG_SEG_HEIGHT],00h ; Check for zero segs
jnz VBG_NZ_SEG
mov A,' ' ; Load space character
jmp VBG_WRITE_CHAR
VBG_NZ_SEG:
cmp [X+VBG_SEG_HEIGHT],09h ; Check for full segment
jnc VBG_FULL_SEG
; Partial segment between 1 and 8
mov A,[X+VBG_SEG_HEIGHT]
dec A
mov [X+VBG_SEG_HEIGHT],00h ; Zero segment height
jmp VBG_WRITE_CHAR
VBG_FULL_SEG: ; Bargaph
sub [X+VBG_SEG_HEIGHT],08h ; Subtract full segment
mov A,07h ; Load full segment
VBG_WRITE_CHAR: ; Write character to display
call LCD_WriteData ; Write value
pop A
dec A
dec [X+VBG_CHAR_HEIGHT]
jnz VBG_LOOP
RAM_EPILOGUE RAM_USE_CLASS_2
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: LCD_InitVBG
;
; DESCRIPTION:
; Initialize the vertical bargraph characters.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: none
;
; RETURNS: none
;
; SIDE EFFECTS:
; REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
; Only one type of bargraph (horizontal or vertical) may be used
; at a time since they each require their own set of characters.
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
; Stack offset constants
VBGDATA_CTR: equ 00h ; Char data count stack offset
VBG_BYTES: equ 01h ; Byte counter stack offset
LCD_InitVBG:
_LCD_InitVBG:
RAM_PROLOGUE RAM_USE_CLASS_2
mov X,SP ; Get location of stack
push A ; Create 2 locations
push A
mov A,CG_RAM_OFFSET ; Setup pointer
call LCD_Control ; Position the CG pointer
mov [X+VBGDATA_CTR],01h ; Reset data counter
VBG_Loop1: ; loop once for each 8 characters
mov [X+VBG_BYTES],08h ; Load cycle pointer
VBG_Loop2: ; Loop once for each line in character (8 times)
mov A,[X+VBGDATA_CTR]
cmp A,[X+VBG_BYTES]
jnc VBG_SOLID
mov A,00h ; Empty line
jmp VBG_Load ; Jump to load the bargraph
VBG_SOLID:
mov A,FFh ; Load solid line
VBG_Load:
call LCD_WriteData ; character data
dec [X+VBG_BYTES] ; Dec byte counter
jnz VBG_Loop2 ; End Loop 2
inc [X+VBGDATA_CTR]
cmp [X+VBGDATA_CTR],09h
jnz VBG_Loop1 ; End Loop1
pop A
pop A
mov A,DISP_ON ; Turn on display, don't really
call LCD_Control ; need this.
RAM_EPILOGUE RAM_USE_CLASS_2
ret
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: LCD_InitBG
;
; DESCRIPTION:
; Initialize horizontal bargraph characters
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A = type 0 = full |||||||||........
; 1 = single vertical line ..........|......
;
; RETURNS:
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
; Currently only the page pointer registers listed below are modified:
; CUR_PP
;
; Only one type of bargraph (horizontal or vertical) may be used
; at a time since they each require their own set of characters.
;
; THEORY of OPERATION or PROCEDURE:
; This function writes to the LCD character RAM to generate 8 custom
; characters used to generated one of two horizontal bargraphs.
;
.LITERAL
BG_TYPE1:: ; ....., |...., ||..., |||.., ||||., |||||, |||||
DB 00h, 10h, 18h, 1Ch, 1Eh, 1Fh, 1Fh
BG_TYPE2:: ; ....., |...., .|..., ..|.., ...|., ....|, .....
DB 00h, 10h, 08h, 04h, 02h, 01h, 00h
.ENDLITERAL
.SECTION
; Stack offset constants
BGDATA_PTR: equ 00h ; Stack offsets
BGCHARS: equ 01h
BGTYPE: equ 02h
LCD_InitBG:
_LCD_InitBG:
RAM_PROLOGUE RAM_USE_CLASS_2
mov X,SP ; Get location of stack
add SP,3
mov [X+BGTYPE],A ; Store the bargraph type
mov A,CG_RAM_OFFSET ; Setup pointer
call LCD_Control ; Position the CG pointer
mov [X+BGDATA_PTR],00h ; Reset pointer to BG data
BG_Loop1:
mov [X+BGCHARS],08h ; Load cycle pointer
BG_Loop2:
mov A,[X+BGDATA_PTR]
cmp [X+BGTYPE],00h ; Check which bargraph
jnz BG_OTHER
index BG_TYPE1
jmp BG_Load
BG_OTHER:
index BG_TYPE2
BG_Load:
call LCD_WriteData
dec [X+BGCHARS] ; Character builder counter
jnz BG_Loop2
inc [X+BGDATA_PTR] ; Advance to next character
cmp [X+BGDATA_PTR],07h
jnz BG_Loop1
add SP,-3
mov A,DISP_ON
call LCD_Control
RAM_EPILOGUE RAM_USE_CLASS_2
ret
.ENDSECTION
ENDIF
; End of File LCD.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -