Ðề tài: Lcd
View Single Post
Old 12-07-2009, 11:19 AM   #5
vanhung0103
Nhập môn đệ tử
 
Tham gia ngày: Apr 2009
Bài gửi: 2
:
code LCD 4 bit loai 2 line.

TITLE " HIEN THI CHU RA LCD.ASM"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;
PROCESSOR 16F877
; Clock = XT 4MHz, standard fuse settings
__CONFIG 0x3731
; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INCLUDE "P16F877.INC"
Timer1 EQU 20
TimerX EQU 21
Point EQU 22
Select EQU 23
OutCod EQU 24
RS EQU 1
E EQU 2
BGIAY EQU 25
; PROGRAM BEGINS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ORG 0
NOP
BANKSEL TRISD
CLRF TRISD
BANKSEL PORTD
CLRF PORTD
GOTO Start
; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Start
CALL Init
CALL OutMes1
MOVLW D'10'
MOVFW BGIAY
LAP1
MOVLW D'250'
CALL Xms
DECFSZ BGIAY
GOTO LAP1

CALL Init
CALL OutMes2
MOVLW D'10'
MOVFW BGIAY
LAP2
MOVLW D'250'
CALL Xms
DECFSZ BGIAY
GOTO LAP2

CALL Init
CALL OutMes3
MOVLW D'10'
MOVFW BGIAY
LAP3
MOVLW D'250'
CALL Xms
DECFSZ BGIAY
GOTO LAP3
GOTO Start
; 1ms delay with 1us cycle time (1000 cycles)-------------------
Onems
MOVLW D'249'
MOVWF Timer1
Loop1
NOP
DECFSZ Timer1
GOTO Loop1
RETURN
; Delay Xms, X received in W -----------------------------------
Xms
MOVWF TimerX
LoopX
CALL Onems
DECFSZ TimerX
GOTO LoopX
RETURN
; Generate data/command clock siganl E -------------------------
PulseE
BSF PORTD,E
CALL Onems
BCF PORTD,E
CALL Onems
RETURN
; Send a command byte in two nibbles from RB4 - RB7 ------------
Send
MOVWF OutCod
ANDLW 0F0
MOVWF PORTD
BTFSC Select,RS
BSF PORTD,RS
CALL PulseE
CALL Onems
SWAPF OutCod
MOVF OutCod,W
ANDLW 0F0
MOVWF PORTD
BTFSC Select,RS
BSF PORTD,RS
CALL PulseE
CALL Onems
RETURN
;Table of fixed characters to send ----------------------------
Line1
ADDWF PCL,1
DT "PHONG THI NGHIEM"

;------------------------------------------
Line12
ADDWF PCL,1
DT " TRUONG DH CNSG "
;==========================================
Line21
ADDWF PCL,1
DT "DO AN TOT NGHIEP"

;------------------------------------------
Line22
ADDWF PCL,1
DT "KIT THUC TAP PIC"
;=================================================

Line31
ADDWF PCL,1
DT " VUONG VAN HUNG "

;------------------------------------------
Line32
ADDWF PCL,1
DT " MSSV: 33070086 "
; Initialise the display ----------------------------------------
Init
MOVLW D'100'
CALL Xms
MOVLW 0F0
MOVWF Select
MOVLW 0x30
MOVWF PORTD
CALL PulseE
MOVLW D'5'
CALL Xms
CALL PulseE
CALL Onems
CALL PulseE
BCF PORTD,4
CALL PulseE
MOVLW 0x28
CALL Send
MOVLW 0x08
CALL Send
MOVLW 0x01
CALL Send
MOVLW 0x06
CALL Send
MOVLW 0x80
CALL Send
MOVLW 0x0C
CALL Send
; MOVLW 0x0E
; CALL Send
RETURN
; Send the fixed message to the display ------------------------
OutMes1
CLRF Point
BSF Select,RS

;=======================================
Mess11
MOVF Point,W
CALL Line1
CALL Send
INCF Point
MOVF Point,W
SUBLW D'16'
BTFSS STATUS,Z
GOTO Mess11
MOVLW 0xC0
BCF Select,RS
CALL Send
CLRF Point
;=====================================
Mess12
MOVF Point,W
CALL Line12
BSF Select,RS
CALL Send
INCF Point
MOVF Point,W
SUBLW D'16'
BTFSS STATUS,Z
GOTO Mess12
RETURN
;==========================================
OutMes2
CLRF Point
BSF Select,RS

Mess21
MOVF Point,W
CALL Line21
CALL Send
INCF Point
MOVF Point,W
SUBLW D'16'
BTFSS STATUS,Z
GOTO Mess21
MOVLW 0xC0
BCF Select,RS
CALL Send
CLRF Point
;=====================================
Mess22
MOVF Point,W
CALL Line22
BSF Select,RS
CALL Send
INCF Point
MOVF Point,W
SUBLW D'16'
BTFSS STATUS,Z
GOTO Mess22
RETURN
;===========================================
OutMes3
CLRF Point
BSF Select,RS

Mess31
MOVF Point,W
CALL Line31
CALL Send
INCF Point
MOVF Point,W
SUBLW D'16'
BTFSS STATUS,Z
GOTO Mess31
MOVLW 0xC0
BCF Select,RS
CALL Send
CLRF Point
;=====================================
Mess32
MOVF Point,W
CALL Line32
BSF Select,RS
CALL Send
INCF Point
MOVF Point,W
SUBLW D'16'
BTFSS STATUS,Z
GOTO Mess32
RETURN
;===========================================

END
vanhung0103 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn