Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD and PIC16F871 problem

Status
Not open for further replies.

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?
 
I can't be bothered to work it out and find the exact reason, but it looks likely that you have a hardware fault - probably two of the datalines shorted together, or one of them shorted to either 0V or 5V.

If you write out the binary values of the digits you get, and the digits you wanted, above each other, it should become obvious which bit is giving the problem.

It makes it a LOT easier to work out as you're using 8 bit mode - 4 bit mode complicates it a little more 8)
 
Nigel Goodwin said:
I can't be bothered to work it out and find the exact reason, but it looks likely that you have a hardware fault - probably two of the datalines shorted together

I can :eek: , and it looks like you are exactly right. Notice how bit 1 and bit 2 only come on for the display when both of them are hi in the expected hex code? You have them connected together and they are shorting.

Code:
             	76543210
00100001	21	00100001
00100010	20	00100000
00100011	21	00100001
00100100	20	00100000
00100101	21	00100001
00100110	26	00100110
00100111	27	00100111
00101000	28	00101000
00101001	29	00101001
00101010	28	00101000
00101011	29	00101001
00101100	28	00101000
00101101	29	00101001
00101110	2E	00101110
00101111	2F	00101111
 
Thank you so much!
That was the problem - short connection between D1 and D2.
Many thanks to Nigel Goodwin and bonxer.

Now everything is O.K.
 
Desert Leo said:
Thank you so much!
That was the problem - short connection between D1 and D2.
Many thanks to Nigel Goodwin and bonxer.

Now everything is O.K.

I've had similar questions about my PIC tutorials :lol: so I was fairly confident what your problem was - but I thought doing the actual checking would be good for you 8)
 
but I thought doing the actual checking would be good for you

Yes Nigel! It was very useful.
In fact, I check and repair it and after that I log in the forum and saw bonxer's post. Independently of that, I'm very grateful to both of you.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top