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

📄 lcd.asm

📁 利用psoc进行usb及capsense的程序编写
💻 ASM
📖 第 1 页 / 共 4 页
字号:
_LCD_Init:
    RAM_PROLOGUE RAM_USE_CLASS_4
    RAM_SETPAGE_CUR >Port_4_Data_SHADE          ; Set CUR_PP to LCD variable address

    and   [Port_4_DriveMode_0_SHADE],~LCD_PORT_MASK             ; Mask off LCD bits
    or    [Port_4_DriveMode_0_SHADE],LCD_PORT_WRITE             ; Set LCD port for writing
    and   [Port_4_DriveMode_1_SHADE],~LCD_PORT_MASK             ; Mask off LCD bits

    mov   A,[Port_4_DriveMode_0_SHADE]
    M8C_SetBank1
    mov   reg[LCD_PortMode0],A                                  ; Setup LCD Port for writing
    mov   A,[Port_4_DriveMode_1_SHADE]
    mov   reg[LCD_PortMode1],A
    M8C_SetBank0

    mov   A,250                             ; Delay for 12.5 mSec (250 * 50uSec)
    call  LCD_Delay50uTimes
    mov   A,250                             ; Delay for 12.5 mSec (250 * 50uSec)
    call  LCD_Delay50uTimes

    mov   A,03h
    call  LCD_WCNTL_Nibble

    mov   A,82                              ; Delay for 4.1 mSec (82 * 50uSec)
    call  LCD_Delay50uTimes

    mov   A,03h
    call  LCD_WCNTL_Nibble

    call  LCD_Delay50u
    call  LCD_Delay50u
    call  LCD_Delay50u

    mov   A,03h
    call  LCD_WCNTL_Nibble

    mov   A,90                              ; Delay for 4.5 mSec (90 * 50uSec)
    call  LCD_Delay50uTimes

    mov   A,02h
    call  LCD_WCNTL_Nibble

    mov   A,90                              ; Delay for 4.5 mSec (90 * 50uSec)
    call  LCD_Delay50uTimes

    mov   A,08h
    call  LCD_Control
    mov   A,90                              ; Delay for 4.5 mSec (90 * 50uSec)
    call  LCD_Delay50uTimes

    mov   A,01h
    call  LCD_Control
    mov   A,90                              ; Delay for 4.5 mSec (90 * 50uSec)
    call  LCD_Delay50uTimes

    mov   A,06h
    call  LCD_Control

    mov   A,0Eh
    call  LCD_Control

    mov   A,LCD_4BIT_2LINE                  ; Setup for 4 bit interface, 2 line
    call  LCD_Control

    mov   A,DISP_OFF
    call  LCD_Control

    mov   A,DISP_ON
    call  LCD_Control

    mov   A,DISP_INC
    call  LCD_Control

    mov   A,90                              ; Delay for 4.5 mSec (90 * 50uSec)
    call  LCD_Delay50uTimes
    RAM_EPILOGUE RAM_USE_CLASS_4
    ret
.ENDSECTION

;-----------------------------------------------------------------------------
;  FUNCTION NAME: LCD_Position
;
;  DESCRIPTION:
;     Position Cursor at Row and Col location
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     A => Row  0 to 3
;     X => Col  0 to 39+
;
;  RETURNS:  none
;
;  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.
;
.LITERAL
LCD_ROW_OFFSET::
     DB    LCD_ROW1_OFFSET, LCD_ROW2_OFFSET, LCD_ROW3_OFFSET, LCD_ROW4_OFFSET
.ENDLITERAL

.SECTION
 LCD_Position:
_LCD_Position:
    RAM_PROLOGUE RAM_USE_CLASS_2
    and   A,03h                        ; Mask off 2 bits for row address 0 to 3
    push  X                            ; Store COL
    index LCD_ROW_OFFSET               ; Get ROW memory offset from table
    mov   X,SP                         ; Get Stack pointer
    add   A,[X+(-1)]                   ; Add the COL to the display pointer
    pop   X

LCD_POS_IT:
    call  LCD_Control                  ; Write control byte
    RAM_EPILOGUE RAM_USE_CLASS_2
    ret
.ENDSECTION

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: LCD_Delay50uTimes
;
;  DESCRIPTION:
;     Delay increments of 50uSeconds
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;     A contains the delay multiplier
;
;  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.
;
;
 LCD_Delay50uTimes:
_LCD_Delay50uTimes:
    RAM_PROLOGUE RAM_USE_CLASS_1
    call  LCD_Delay50u
    dec   A
    jnz   LCD_Delay50uTimes
    RAM_EPILOGUE RAM_USE_CLASS_1
    ret

.ENDSECTION

;-----------------------------------------------------------------------------
;  FUNCTION NAME: LCD_Delay50u
;
;  DESCRIPTION:
;     Delay 50uSec for any clock frequency from 1.5MHz to 24MHz
;     Slower clock frequencies the delay will be;
;           1.5
;        -------------- * 50uSec
;        clock_freq(MHz)
;
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS: none
;
;  RETURNS: none
;
;  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.
;
;  THEORY of OPERATION or PROCEDURE:
;
.LITERAL
 Delay50u_Table::
     DB    08h,  19h,   3Ah,   7Ch,   01h,    01h,    01h,   01h
;         3MHz, 6MHz, 12MHz, 24MHz, 1.5MHz, 750kHz, 188kHz, 94kHz
.ENDLITERAL
.SECTION

  LCD_Delay50u:
 _LCD_Delay50u:                        ; [11]  Call
    RAM_PROLOGUE RAM_USE_CLASS_1
    push  A
    M8C_SetBank1                       ; [4]
    mov   A, reg[OSC_CR0]              ; [6] Get delay value
    M8C_SetBank0                       ; [4]
    and   A,07h                        ; [4] Mask off only the clock bits
    cmp   A,05h
    jnc   Delay50u_End
    index Delay50u_Table               ; [13] Get delay value
Delay50u_Loop:                         ;
    dec   A                            ; [4]
    jnz   Delay50u_Loop                ; [5]
Delay50u_End:
    pop   A
    RAM_EPILOGUE RAM_USE_CLASS_1
    ret
.ENDSECTION


;-----------------------------------------------------------------------------
;      If bargraph is not enabled, the following functions are not required.
;-----------------------------------------------------------------------------

IF (LCD_BARGRAPH_ENABLE)

IF SYSTEM_SMALL_MEMORY_MODEL
.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: LCD_DrawBG
;
;  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 horizontal 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 39+
;   [x-1] => Length of bargraph in chars 1 to 40+
;   [X-2] => Position of pointer in segments 5 times Length
;
;
;  RETURNS:  none
;
;  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
BG_COLX:       equ  0                   ; Stack position of Column
BG_CHAR_LENX:  equ -1                   ; Stack position of Length
BG_LENGTHX:    equ -2                   ; Stack postion of bargraph pointer position


LCD_DrawBG:
    push  X
    mov   X,[X+BG_COLX]                 ; Row in A, Col in X
    call  LCD_Position                 ; Set cursor position
    pop   X                            ; Restore pointer

LCD_BG_LOOP1X:
    cmp   [X+BG_LENGTHX],00h            ; Check for past end of BG
    jnz   LCD_CHECK1X
    mov   A,00h                        ; Load empty character
    jmp   LCD_BG_DOITX                  ;

LCD_CHECK1X:
    cmp   [X+BG_LENGTHX],06h            ; Check if BG pointer is at this character
    jnc   LCD_CHECK2X                   ; Note yet, use full character
    mov   A,[X+BG_LENGTHX]
    sub   [X+BG_LENGTHX],A
    jmp   LCD_BG_DOITX

LCD_CHECK2X:                            ; Put index to full character
    mov   A, 06h
    sub   [X+BG_LENGTHX],05h            ; Subtract another 5 positions

LCD_BG_DOITX:
    call  LCD_WriteData                ; Display BG character

    dec   [X+BG_CHAR_LENX]              ; Dec Char count
    jnz   LCD_BG_LOOP1X                 ; Do it all over again
    ret
.ENDSECTION
ENDIF ; SYSTEM_SMALL_MEMORY_MODEL

.SECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: LCD_DrawBG
;
;  DESCRIPTION:
;     Draw a horizontal 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 39+
;   [SP-5] => Length of bargraph in chars 1 to 40+
;   [SP-6] => Position of pointer in segments 5 times Length
;
;
;  RETURNS:  none
;
;  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
BG_ROW:       equ -3
BG_COL:       equ -4                   ; Stack position of Column
BG_CHAR_LEN:  equ -5                   ; Stack position of Length
BG_LENGTH:    equ -6                   ; Stack postion of bargraph pointer position


_LCD_DrawBG:
    RAM_PROLOGUE RAM_USE_CLASS_2
    mov   X, SP
    push  X

⌨️ 快捷键说明

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