Desert Leo
New Member
Hi all!
In my current project, I'm using PIC16F871 and AC-204AYA75 LCD module (20x4 without backlight) from Ampire Co.
Port D of 16F871 is connected to data lines of LCD (RD0=D0, ... RD7=D7), and the three lines of Port E are control lines (RE0=RS, RE1=R/W, RE2=Enable).
Here is my test program (just to check the LCD):
list p=16F871
#include <p16f871.inc>
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC
DELAY EQU h'20'
X_DELAY EQU h'21'
P_data EQU h'22'
Char EQU h'23'
ORG 0x000 ; RESET VECTOR
goto init
ORG 0x004 ; INTERRUPT VECTOR
init call bank1
movlw b'10001100'
movwf ADCON1
call bank0
clrf PORTD
clrf PORTE
call bank1
clrf TRISD ; All pins of Port D are outputs
clrf TRISE ; All pins of Port E are outputs
call bank0
movlw d'200' ; Delay
call x_del_150us ; of 30ms
goto main
;------------
; SUBROUTINES
;------------
bank0 bcf STATUS,RP1 ; BANK0
bcf STATUS,RP0
return
bank1 bcf STATUS,RP1 ; BANK1
bsf STATUS,RP0
return
bank2 bsf STATUS,RP1 ; BANK2
bcf STATUS,RP0
return
bank3 bsf STATUS,RP1 ; BANK3
bsf STATUS,RP0
return
; LCD INITIALIZATION
lcd_on movlw h'38'
movwf P_data
call wr_com
call del_150us
movlw h'0F'
movwf P_data
call wr_com
call del_150us
return
; SENDING COMMAND TO LCD
wr_com bsf PORTE,2 ; E=1
call del_150us
movf P_data,0
movwf PORTD
call del_150us
bcf PORTE,2 ; E=0
call del_150us
return
; SENDING DATA TO LCD
wr_dat bsf PORTE,2 ; E=1
movf P_data,0
movwf PORTD
bcf PORTE,2 ; E=0
movlw d'255'
call x_del_150us
return
; SUBROUTINES FOR DELAY
del_150us movlw d'249'
movwf DELAY
del_150_loop decfsz DELAY, 1
goto del_150_loop
return
x_del_150us movwf X_DELAY
x_del_loop call del_150us
decfsz X_DELAY, 1
goto x_del_loop
return
; MAIN PROGRAM
main call lcd_on
bsf PORTE,0 ; RS=1 - sending data
movlw h'21'
movwf Char
loop movf Char,0
movwf P_data
call wr_dat
movlw d'255'
call x_del_150us
incf Char,1
goto loop
;--------------------------------------------------------------------
end ; End of file
The program is intended for infinite display of the characters, starting with "!" (h'21').
Unfortunately, it displays the characters in very strange manner:
"!" - 21 (symbol - hexadecimal addres), "blank" - 20, "!" - 21, 20, 21, 26, 27, 28, 29, 28, 29, 28, 29, 2E, 2F. In other word, the program displays first and secong char 3 times, skipping 3,4,5,6 , after that it displays 7th and 8th, and again 3 times 9th and 10th, skipping next 4 chars.
Can someone help me?
In my current project, I'm using PIC16F871 and AC-204AYA75 LCD module (20x4 without backlight) from Ampire Co.
Port D of 16F871 is connected to data lines of LCD (RD0=D0, ... RD7=D7), and the three lines of Port E are control lines (RE0=RS, RE1=R/W, RE2=Enable).
Here is my test program (just to check the LCD):
list p=16F871
#include <p16f871.inc>
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC
DELAY EQU h'20'
X_DELAY EQU h'21'
P_data EQU h'22'
Char EQU h'23'
ORG 0x000 ; RESET VECTOR
goto init
ORG 0x004 ; INTERRUPT VECTOR
init call bank1
movlw b'10001100'
movwf ADCON1
call bank0
clrf PORTD
clrf PORTE
call bank1
clrf TRISD ; All pins of Port D are outputs
clrf TRISE ; All pins of Port E are outputs
call bank0
movlw d'200' ; Delay
call x_del_150us ; of 30ms
goto main
;------------
; SUBROUTINES
;------------
bank0 bcf STATUS,RP1 ; BANK0
bcf STATUS,RP0
return
bank1 bcf STATUS,RP1 ; BANK1
bsf STATUS,RP0
return
bank2 bsf STATUS,RP1 ; BANK2
bcf STATUS,RP0
return
bank3 bsf STATUS,RP1 ; BANK3
bsf STATUS,RP0
return
; LCD INITIALIZATION
lcd_on movlw h'38'
movwf P_data
call wr_com
call del_150us
movlw h'0F'
movwf P_data
call wr_com
call del_150us
return
; SENDING COMMAND TO LCD
wr_com bsf PORTE,2 ; E=1
call del_150us
movf P_data,0
movwf PORTD
call del_150us
bcf PORTE,2 ; E=0
call del_150us
return
; SENDING DATA TO LCD
wr_dat bsf PORTE,2 ; E=1
movf P_data,0
movwf PORTD
bcf PORTE,2 ; E=0
movlw d'255'
call x_del_150us
return
; SUBROUTINES FOR DELAY
del_150us movlw d'249'
movwf DELAY
del_150_loop decfsz DELAY, 1
goto del_150_loop
return
x_del_150us movwf X_DELAY
x_del_loop call del_150us
decfsz X_DELAY, 1
goto x_del_loop
return
; MAIN PROGRAM
main call lcd_on
bsf PORTE,0 ; RS=1 - sending data
movlw h'21'
movwf Char
loop movf Char,0
movwf P_data
call wr_dat
movlw d'255'
call x_del_150us
incf Char,1
goto loop
;--------------------------------------------------------------------
end ; End of file
The program is intended for infinite display of the characters, starting with "!" (h'21').
Unfortunately, it displays the characters in very strange manner:
"!" - 21 (symbol - hexadecimal addres), "blank" - 20, "!" - 21, 20, 21, 26, 27, 28, 29, 28, 29, 28, 29, 2E, 2F. In other word, the program displays first and secong char 3 times, skipping 3,4,5,6 , after that it displays 7th and 8th, and again 3 times 9th and 10th, skipping next 4 chars.
Can someone help me?