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

📄 lcd128.a30

📁 瑞萨(Renesas)M16C系列芯片的函数库
💻 A30
📖 第 1 页 / 共 2 页
字号:

        .include        sfr62p.inc      ; for M16C/60 series
                                        ; SFR definition file
;==============================================================================
;       Symbol definition
;==============================================================================
LCD_RS         .btequ  p10_4            ; RS port (Bit 6 of Port P10)
                                        ; 0:command-reg, 1:data-reg
LCD_RW         .btequ  p10_5            ; RW port (Bit 5 of Port P10)
                                        ; 0:Write, 1:Read
LCD_E          .btequ  p10_6            ; E port (Bit 4 of Port P10)
                                        ; 1:strobe, down edge:RW

DIR_READ        .equ    01110000B       ; the value to be set for reading from LCD module to M16C
                                        ; only input (lower 4 bits)
                                        ; the highest bit is not used
DIR_WRITE       .equ    01111111B       ; the value to be set for write from M16C to LCD module
                                        ; (output, the highest bit is not used)
DEF_P4_DATA     .equ    00000000B       ; P4 register is set as below when not controlling LCD 
                                        ; 0x000000
                                        ; ||||++++---- B3-0   = 0
                                        ; |||+-------- B4(E)  = L
                                        ; ||+--------- B5(RW) = L(WRITE)
                                        ; |+---------- B6(RS) = L(COMMAND)
                                        ; +----------- B7     = L(because of OPEN)

;""SUBR COMMENT""**************************************************************
; ID              	: ---
; Subroutine	  	: void _lcd12864__initial(void)
; Function	      	: Initialize LCD control port
; Input	            : none
; Output            : none
; Subroutine used	: none
; Stack		        : 0
; Notice	        : only initialize the port, LCD can not display anything
; History       	: ---
;""SUBR COMMENT END""**********************************************************
        .section        program         ; the same section as the C program section
        .glb            __lcd12864__initial ; global declaration
__lcd12864__initial:
		bclr:g  LCD_E
        mov.b   #00H, 	pd0          ; set as reading from LCD module
        rts


;""SUBR COMMENT""**************************************************************
; ID              	: ---
; Subroutine	  	: void _lcd12864__wait(unsigned int t)
; Function	        : wait for t*100us
; Input	            : unsigned int t: wait time (t * 100us)
; Output            : none
; Subroutine used	: none
; Stack		        : 0
; Notice	        : parameter t (times of 100us) is sent to R1 register according to the parameter transfer rule.
;                 	: loop of wait_loop_10 is the software wait for 100us
;                 	: t * 100us can be got from loop of wait_loop
;                 	: to calculate easily, the time is a little longer.
;                 	: 
;                 	: meanings of 240 (1 cycle = 41.7ns@24MHz)
;                 	:     100000ns 佮 41.7 * (1 + 240 * (3 + 7) - 4)
;                	:                         |          |   |    |
;                 	:                         |          |   |    +---when not jumping
;                 	:                         |          |   +------ADJNZ
;                 	:                         |          +--------NOP亊3
;                 	:                         +----------------MOV
; History         	: ---
;""SUBR COMMENT END""**********************************************************
        .section        program         ; the same section as the C program section
        .glb            $_lcd12864__wait    ; global declaration
$_lcd12864__wait:

wait_loop:
        mov.b:s #240, R0L               ; 41.7ns*1
wait_loop_10:
        nop                             ; 41.7ns*1
        nop                             ; 41.7ns*1
        nop                             ; 41.7ns*1
        adjnz.b #-1, R0L, wait_loop_10  ; 41.7ns*7(-4 when not jumping)
        adjnz.w #-1, R1, wait_loop      ; 41.7ns*7(-4 when not jumping)
        rts                             ; 41.7ns*6


;""SUBR COMMENT""**************************************************************
; ID              	: ---
; Subroutine	  	: void _lcd12864__wr_creg(int command)
; Function          : write command to the command register of LCD
; Input            	: int command: data to be written 
; Output            : none
; Subroutine used	: none
; Stack		        : 0
; Notice	        : parameter command (command to be written to LCD module)
;                 	: is sent to R1 register according to the parameter transfer rule
;                 	: 
;                 	: timing control is as below. please note the request of time.
;                 	:     --------------------------+--+--+--+-------+----+-----
;                 	:                 TIME           RS RW E  I/O-DIR LCD  M16C
;                 	:     --------------------------+--+--+--+-------+----+-----
;                 	:                           def= x  0  0  RD     | IN   IN
;                 	:     BCLR:G  RS 41.7*3=125.1   0  .  .  .       | .    .
;                 	:     MOV.B:S #W 41.7*2=83.4   .  .  .    WR     | .    OUT
;                 	:     BSET:G  E  41.7*3=125.1   .  .   1  .      | .    .
;                 	:     MOV.B:G    41.7*2=83.4   .  .  .  .        | .    .
;                 	:     MOVLL      41.7*=208.5   .  .  .  .        |(WR Command)
;                	:     BCLR:G  E  41.7*3=125.1   .  .   0  .      | .    .
;                 	:     MOV.B:S #R 41.7*2=83.4   .  .  .    RD     | IN
; History         	: ---
;""SUBR COMMENT END""**********************************************************
        .section        program         ; the same section as the C program section
        .glb            $_lcd12864__wr_creg  
                                        ; global declaration
$_lcd12864__wr_creg:
        ;---- select command ----
        bclr:g  LCD_RS                 ; select command
                                        ; (set RS port of LCD module as "L")

        ;---- set as writing to LCD ----
        bclr:g  LCD_RW                ; set LCD module as input
        ;                               ; (set RW of LCD as "L" to WRITE)
        mov.b:s #0ffH, pd0         ; set CPU as output
                                        ; (set P0_0 to P0_7 as output)

        ;---- write 8bit ----
        nop
		bset:g  LCD_E                  ; set E port of LCD module as "H"
		nop
        mov.b:g R1L, R0L                ; write parameter (R1) to LCD
        mov.b   R0L, p0                 ; transfer lower 8bit (P0 = R1L)
		nop
        bclr:g  LCD_E
		nop
		nop                  ; set E port of LCD module as "L"

        ;---- set port as initial status ----
        mov.b:s #00H, pd0          ; set P0_0 to P0_7 as input
        rts


;""SUBR COMMENT""**************************************************************
; ID              	: ---
; Subroutine  		: void _lcd12864__wr_dreg(int data)
; Function          : write data to the data register of LCD
; Input           	: int data: data to be written 
; Output            : none
; Subroutine used	: none
; Stack		        : 0
; Notice	        : parameter data (data to be written to LCD module)
;                 	: is sent to R1 register according to the parameter transfer rule
;                 	: 

⌨️ 快捷键说明

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