📄 液晶.asm
字号:
;*************************************************
;* LCDDEMO.ASM **
;*************************************************
;* Goldenchip ICDDEMO Workshop for MCUPIC16F877 *
;*************************************************
;* 本程序包含控制外部液晶面板的4-BIT控制模式子 *
;* 程序。这些程序是专门为 MCU201 workshop演示板 *
;* 设计的。但它也可作为其他类型的使用 KS0066U控 *
;* 制器的液晶面板的控制程序。 *
;* 程序包括: *
;* - InitLCD 初始化液晶面板子程序 *
;* - putcLCD 将字符写入 LCD的子程序 *
;* - SendCmd 将命令写入 LCD的子程序 *
;* - clrLCD 清 LCD显示 *
;* - L1homeLCD 指针指向第1行 *
;* - L2homeLCD 指针指向第2行 *
;************************************************
include <p16f877.inc>
; 定义 LCD数据& 控制I/O口
LCD_DATA equ PORTB
LCD_CNTL1 equ PORTB
LCD_CNTL2 equ PORTA
; 定义 LCD控制相应的I/O引脚
RS equ 1
E equ 5
; LCD 模块命令
DISP_ON EQU 0x00C ; 开显示
DISP_ON_C EQU 0x00E ; 开显示, 开指针
DISP_ON_B EQU 0x00F ; 开显示, 开指针,开闪烁
DISP_OFF EQU 0x008 ; 关显示
CLR_DISP EQU 0x001 ; 清显示的操作数
ENTRY_INC EQU 0x006 ; 操作数
ENTRY_INC_S EQU 0x007 ; 操作数
ENTRY_DEC EQU 0x004 ; 操作数
ENTRY_DEC_S EQU 0x005 ; 操作数
DD_RAM_ADDR EQU 0x080 ; 初始化第一行显示的操作数
DD_RAM_UL EQU 0x0c0 ; 初始化第二行显示的操作数
;
; 设置显示相关寄存器
Byte EQU 20H
Count EQU 21H
Count1 EQU 22H
Count2 EQU 23H
LCD_DATA1 EQU 24H
;**************************************
ORG 0
main call InitLCD ;初始化LCD显示
call L1homeLCD ; 显示指针在第一行
movlw 'G' ;
call putcLCD
movlw 'o'
call putcLCD
movlw 'l' ;
call putcLCD
movlw 'd' ;
call putcLCD
movlw 'e'
call putcLCD
movlw 'n' ;
call putcLCD
movlw 'C' ;
call putcLCD
movlw 'h'
call putcLCD
movlw 'i' ;
call putcLCD
movlw 'p' ; 显示‘Goldenchip’
call putcLCD
call L2homeLCD ; 显示指针转到第二行
movlw 'W'
call putcLCD
movlw 'e' ;
call putcLCD
movlw 'l'
call putcLCD
movlw 'c' ;
call putcLCD
movlw 'o' ;
call putcLCD
movlw 'm'
call putcLCD
movlw 'e'
call putcLCD
movlw '!'
call putcLCD ;显示 'Welcome!'
call LongDelay
call LongDelay
call LongDelay
call LongDelay
call clrLCD
call L1homeLCD
movlw 'W'
call putcLCD
movlw 'e' ;
call putcLCD
movlw 'l'
call putcLCD
movlw 'c' ;
call putcLCD
movlw 'o' ;
call putcLCD
movlw 'm'
call putcLCD
movlw 'e'
call putcLCD
movlw ' '
call putcLCD
movlw 'T'
call putcLCD
movlw 'o'
call putcLCD
movlw ' '
call putcLCD
movlw 'U'
call putcLCD
movlw 's'
call putcLCD
movlw 'e'
call putcLCD
movlw '-'
call putcLCD
movlw '-'
call putcLCD
call L2homeLCD
movlw 'G'
call putcLCD
movlw 'o' ;
call putcLCD
movlw 'l'
call putcLCD
movlw 'd' ;
call putcLCD
movlw 'e' ;
call putcLCD
movlw 'n'
call putcLCD
movlw 'c'
call putcLCD
movlw 'h'
call putcLCD
movlw 'i'
call putcLCD
movlw 'p'
call putcLCD
movlw "'"
call putcLCD
movlw 's'
call putcLCD
movlw ' '
call putcLCD
movlw 'D'
call putcLCD
movlw 'e'
call putcLCD
movlw 'm'
call putcLCD
call LongDelay
call LongDelay
call LongDelay
call LongDelay
call clrLCD
goto main
;*******************************************************************
;* LCD 模块子程序 *
;*******************************************************************
;InitLCD——初始化LCD模块 *
;*******************************************************************
InitLCD
bcf STATUS,RP0 ; Bank 0
bcf STATUS,RP1
clrf LCD_DATA ; 清 LCD 数据 & 控制位
bsf STATUS,RP0 ; Bank 1
movlw 0xc1 ; 设置RB1~RB5为输出
movwf LCD_DATA
bcf TRISA,5
;bsf 9fH,2 ; 设置RA5为数据口
bcf STATUS,RP0 ;
movlw 0x08 ;
movwf LCD_DATA
bsf LCD_CNTL2, E
bcf LCD_CNTL2, E
call LongDelay
call LongDelay
movlw b'00101000'
call SendCmd
movlw DISP_ON ; 开显示
call SendCmd
movlw ENTRY_INC ; 设置指针移动方式
call SendCmd
movlw DD_RAM_ADDR ; 设置起始地址
call SendCmd
InitLCDEnd ;
bcf STATUS,RP0 ;
call clrLCD
return
;*******************************************************************
;*putcLCD—— 将字符数据送入 LCD *
;* 本程序将字符数据分成了高半字节和低半字节分别输入 *
;* 先送入的是高半字节 *
;*******************************************************************
putcLCD
movwf Byte ; 存 WREG 到 Byte 寄存器
swapf Byte,W ; 写入高半字节
movwf LCD_DATA1
rlf LCD_DATA1,1
rlf LCD_DATA1,1
movlw 0x3c
andwf LCD_DATA1,1
movf LCD_DATA1,w
movwf LCD_DATA
bsf LCD_CNTL1, RS ; 设置为送数据模式
bsf LCD_CNTL2, E ; 发送数据信号
bcf LCD_CNTL2, E
movf Byte,W ; 接着送低半字节
movwf LCD_DATA1
rlf LCD_DATA1,1
rlf LCD_DATA1,1
movlw 0x3c
andwf LCD_DATA1,1
movf LCD_DATA1,w
movwf LCD_DATA
bsf LCD_CNTL1, RS ; 设置为送数据模式
bsf LCD_CNTL2, E ; 发送数据信号
bcf LCD_CNTL2, E
call Delay
return
;*******************************************************************
;* SendCmd - 送命令到 LCD *
;* 本程序将命令数据分成了高半字节和低半字节分别输入 *
;* 先送入的是高半字节 *
;*******************************************************************
SendCmd
movwf Byte ; 存 WREG 到 Byte 寄存器
swapf Byte,W ; 送入命令的高字节
movwf LCD_DATA1
rlf LCD_DATA1,1
rlf LCD_DATA1,1
movlw 0x3c
andwf LCD_DATA1,1
movf LCD_DATA1,w
movwf LCD_DATA
bcf LCD_CNTL1,RS ; 设置为送命令模式
bsf LCD_CNTL2,E ; 发送数据信号
bcf LCD_CNTL2,E
movf Byte,W ; 接着送命令的低字节
movwf LCD_DATA1
rlf LCD_DATA1,1
rlf LCD_DATA1,1
movlw 0x3c
andwf LCD_DATA1,1
movf LCD_DATA1,w
movwf LCD_DATA
bcf LCD_CNTL1,RS ; 设置为送命令模式
bsf LCD_CNTL2,E ; 发送数据信号
bcf LCD_CNTL2,E
call Delay
return
;*******************************************************************
;* clrLCD - 清除 LCD 显示 *
;*******************************************************************
clrLCD
movlw CLR_DISP ;
call SendCmd
return
;*******************************************************************
;* L1homeLCD - 将显示指针定位在第一行 *
;*******************************************************************
L1homeLCD
movlw DD_RAM_ADDR ;
call SendCmd ;
return
;*******************************************************************
;* L2homeLCD - 将显示指针定位在第二行 *
;*******************************************************************
L2homeLCD
movlw DD_RAM_UL ;
call SendCmd ;
return
;*******************************************************************
;* Delay - 延时子程序 *
;*******************************************************************
Delay ; call指令占用2个指令周期
clrf Count ; 清 Count占用1个指令周期
Dloop
decfsz Count,f ; 这两行指令将延时
goto Dloop ; (256 * 3) -1 个指令周期
return ; return占用2个指令周期
;*******************************************************************
;* LongDelay - 长延时子程序 *
;*******************************************************************
LongDelay
clrf Count
clrf Count1
movlw 0x03
movwf Count2
LDloop
decfsz Count,f
goto LDloop
decfsz Count1,f
goto LDloop
decfsz Count2,f
goto LDloop
return
;*********************************
END
;****************************************************
;Written by : Yamato Tel:0591-3375855-721 *
;****************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -