📄 lcd1.a30
字号:
.include sfr62p.inc ; for M16C/60 series
; SFR definition file
;==============================================================================
; Symbol definition
;==============================================================================
p4_6_RS .btequ p4_6 ; RS port (Bit 6 of Port P4)
; 0:command-reg, 1:data-reg
p4_5_RW .btequ p4_5 ; RW port (Bit 5 of Port P4)
; 0:Write, 1:Read
p4_4_E .btequ p4_4 ; E port (Bit 4 of Port P4)
; 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(OPEN側偺偱)
; * RS is initialized as L (COMMAND)
; after reset, the value is not steady
;""SUBR COMMENT""**************************************************************
; ID : ---
; Subroutine : void _lcd1__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 __lcd1__initial ; global declaration
__lcd1__initial:
mov.b #DEF_P4_DATA, p4 ; set data base as not used
mov.b #DIR_READ, pd4 ; set as reading from LCD module
; (set P4_0 to P4_3 as input)
; (set P4_4 to P4_6 as output)
rts
;""SUBR COMMENT""**************************************************************
; ID : ---
; Subroutine : void _lcd1__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 $_lcd1__wait ; global declaration
$_lcd1__wait:
wait_loop:
mov.b:s #160, 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 _lcd1__wr_nibble_creg(int command)
; Function : write command to the command register of LCD
; Input : int command: data to be written (only lower 4 bits valid)
; 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 $_lcd1__wr_nibble_creg
; global declaration
$_lcd1__wr_nibble_creg:
;---- select command ----
bclr:g p4_6_RS ; select command
; (set RS port of LCD module as "L")
;---- set as writing to LCD ----
;bclr:g p4_5_RW ; set LCD module as input
; ; (set RW of LCD as "L" to WRITE)
mov.b:s #DIR_WRITE, pd4 ; set CPU as output
; (set P4_0 to P4_3 as output)
;---- write 4bit ----
bset:g p4_4_E ; set E port of LCD module as "H"
mov.b:g R1L, R0L ; write parameter (R1) to LCD
movll R0L, p4 ; transfer lower 4bit (P4 = R1L)
bclr:g p4_4_E ; set E port of LCD module as "L"
;---- set port as initial status ----
mov.b:s #DIR_READ, pd4 ; set P4_0 to P4_3 as input
rts
;""SUBR COMMENT""**************************************************************
; ID : ---
; Subroutine : void _lcd1__wr_nibble_dreg(int data)
; Function : write data to the data register of LCD
; Input : int data: data to be written (only lower 4 bits valid)
; 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 + -