[問題] 4行LCD設定?
請問一下
我的程式碼在APP01上的一行LCD上可以顯示,但最近換了一個四行的LCD,加了程式碼卻
只能顯示2行,不知道是哪裡的設定有問題?可以麻煩幫我看一下嗎?
附加檔案在文章底部(LCD Datasheet & 程式碼)
http://0rz.tw/NReDT
-----------------------------------------
list p=18f4585
#include <p18f4585.inc>
EXTERN
InitLCD,putcLCD,Send_Cmd,L1homeLCD,L2homeLCD,L3homeLCD,L4homeLCD,clrLCD,
PutHexLCD
PUT_Address macro STR
movlw UPPER STR
movwf TBLPTRU
movlw HIGH STR
movwf TBLPTRH
movlw LOW STR
movwf TBLPTRL
call Put_String
endm
start code
org 0x00
bra start
prog code
start
call InitLCD
call clrLCD
call L1homeLCD
PUT_Address String_1
call L2homeLCD
PUT_Address String_2
call L3homeLCD
PUT_Address String_3
call L4homeLCD
PUT_Address String_4
bra $
Put_String
TBLRD*+
movlw 0x00
cpfseq TABLAT,0
bra Send_String
return
Send_String
movf TABLAT,w,0
call putcLCD
bra Put_String
String_1 db "First ",0x00
String_2 db "Second",0x00
String_3 db "Third",0x00
String_4 db "Fourth",0x00
end
end
--------------------------------------LCD設定
list p=18f4585
#include <p18f4585.inc>
global InitLCD
global putcLCD
global clrLCD
global L1homeLCD
global L2homeLCD
global L3homeLCD
global L4homeLCD
global Send_Cmd
global PutHexLCD
global Hex2ASCII
global Delay_xMS
global Delay_1ms
LCD_CTRL equ TRISD
LCD_DATA equ LATD
#define LCD_E_DIR TRISA,2 ;pin RA2=LCD_E
#define LCD_RW_DIR TRISD,5
#define LCD_RS_DIR TRISD,4
#define LCD_E LATA,2
#define LCD_RW LATD,5
#define LCD_RS LATD,4
CLR_DISP equ b'00000001'
Cursor_Home equ b'00000010'
ENTRY_DEC equ b'00000100'
ENTRY_DEC_S equ b'00000101'
ENTRY_INC equ b'00000110'
ENTRY_INC_S equ b'00000111'
DISP_OFF equ b'00001000'
DISP_ON equ b'00001100'
DISP_ON_C equ b'00001110'
DISP_ON_B equ b'00001111'
FUNC_SET equ b'00101000'
CG_RAM_ADDR equ b'01000000'
DD_RAM_ADDR equ b'10000000'
;DD_RAM_UL equ 0x080 ; Upper Left coner of the Display
UDATA
LCD_Byte RES 1
LCD_Temp RES 1
Count_100us RES 1
Count_1ms RES 1
Count_ms RES 1
W_BUFR RES 1
Hex_Bfr RES 1
LCD_CODE CODE
InitLCD
banksel TRISD
clrf TRISD
clrf LATD
clrf TRISA
clrf LATA
banksel LCD_DATA
bcf LCD_E
bcf LCD_RW
bcf LCD_RS
bcf LCD_E_DIR
bcf LCD_RW_DIR
bcf LCD_RS_DIR
banksel LCD_DATA
clrf LCD_DATA
banksel ADCON1
movlw b'00001101'
movwf ADCON1
banksel ADCON2
movlw b'00001011'
movwf ADCON2
banksel LCD_CTRL
movf LCD_CTRL,w
andlw 0xF0
movwf LCD_CTRL
movlw .10 ;power on delay 10ms
rcall Delay_xMS
movlw b'00000011'
rcall Send_Low_4bit
movlw .10
rcall Delay_xMS
movlw b'00000011'
rcall Send_Low_4bit
rcall Delay_1ms
movlw b'00000011'
rcall Send_Low_4bit
rcall Delay_1ms
movlw b'00000010'
rcall Send_Low_4bit
rcall Delay_1ms
movlw FUNC_SET
rcall Send_Cmd
rcall Delay_1ms
movlw DISP_ON
rcall Send_Cmd
rcall Delay_1ms
banksel CLR_DISP
movlw CLR_DISP
rcall Send_Cmd
movlw .5
rcall Delay_xMS
banksel ENTRY_INC
movlw ENTRY_INC
rcall Send_Cmd
rcall Delay_1ms
banksel DD_RAM_ADDR
movlw DD_RAM_ADDR
rcall Send_Cmd
rcall .5
rcall Delay_xMS
banksel ENTRY_INC
movlw ENTRY_INC
rcall Send_Cmd
rcall Delay_1ms
banksel DD_RAM_ADDR
movlw DD_RAM_ADDR
rcall Send_Cmd
rcall Delay_1ms
return
putcLCD
banksel LCD_Byte
movwf LCD_Byte
rcall Send_High_LCD
banksel LCD_Byte
movf LCD_Byte,W
rcall Send_Low_LCD
rcall Delay_100us
return
Send_High_LCD
swapf WREG,W
Send_Low_LCD
banksel LATD
bcf LCD_RW
andlw 0x0F
banksel LCD_Temp
movwf LCD_Temp
banksel LCD_DATA
movf LCD_DATA,W
andlw 0xF0;0x0F
banksel LCD_Temp
iorwf LCD_Temp,W
banksel LCD_DATA
movwf LCD_DATA
;DB[4:7]
banksel LATD
bsf LCD_RS
bcf LCD_RW
nop
banksel LATA
bsf LCD_E
nop
;movlw .10
;bra Delay_xMS
bcf LCD_E
return
PutHexLCD
banksel W_BUFR
movwf W_BUFR
swapf W_BUFR,W
rcall Hex2ASCII
rcall putcLCD
banksel W_BUFR
movf W_BUFR,W
rcall Hex2ASCII
rcall putcLCD
return
Hex2ASCII
andlw 0xF0
banksel Hex_Bfr
movwf Hex_Bfr
sublw .09
banksel STATUS
btfsc STATUS,C
bra _Add_W_30
_Add_W_37
movlw 0x37
bra _Hex_cont
_Add_W_30
movlw 0x30
_Hex_cont
banksel Hex_Bfr
addwf Hex_Bfr,W
return
Send_Cmd
banksel LCD_Byte
movwf LCD_Byte
rcall Send_High_4bit
banksel LCD_Byte
movf LCD_Byte,W
rcall Send_Low_4bit
rcall Delay_100us
return
Send_High_4bit
swapf WREG,W
Send_Low_4bit
;bcf LCD_RW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
andlw 0x0F
banksel LCD_Temp
movwf LCD_Temp
banksel LCD_DATA
movf LCD_DATA,W
andlw 0xF0
banksel LCD_Temp
iorwf LCD_Temp,W
banksel LCD_DATA
movwf LCD_DATA
;DB[4:7]
banksel LATD
bcf LCD_RS
bcf LCD_RW
nop
banksel LATA
bsf LCD_E
nop
;movlw .10
;bra Delay_xMS
bcf LCD_E
return
clrLCD
banksel CLR_DISP
movlw CLR_DISP
rcall Send_Cmd
movlw .5
bra Delay_xMS
L1homeLCD
banksel DD_RAM_ADDR
movlw DD_RAM_ADDR|0x00
rcall Send_Cmd
bra Delay_100us
L2homeLCD
banksel DD_RAM_ADDR
movlw DD_RAM_ADDR|0x14
rcall Send_Cmd
bra Delay_100us
L3homeLCD
banksel DD_RAM_ADDR
movlw DD_RAM_ADDR|0x40
rcall Send_Cmd
bra Delay_100us
L4homeLCD
banksel DD_RAM_ADDR
movlw DD_RAM_ADDR|0x54
rcall Send_Cmd
bra Delay_100us
Delay_xMS
banksel Count_ms
movwf Count_ms
_D_ms
call Delay_1ms
banksel Count_ms
decfsz Count_ms,F
goto _D_ms
return
Delay_1ms
movlw .10
banksel Count_1ms
movwf Count_1ms
_D_1ms
call Delay_100us
banksel Count_1ms
decfsz Count_1ms,f
bra _D_1ms
return
Delay_100us
movlw .50
banksel Count_100us
movwf Count_100us
_D_2us
nop
nop
banksel Count_100us
decfsz Count_100us,f
bra _D_2us
return
end
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.44.2
ASM 近期熱門文章
PTT數位生活區 即時熱門文章