?? 液晶.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 + -