• 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.

PIC16F84A LCD Programming Help

Status
Not open for further replies.

Frosty_47

New Member
I successfully programmed DMC 16249 LCD in 8-bit parallel mode using PIC16F84A. Now my instructor wants me to program that same LCD in serial mode using 74LS164 shift register. I moded my code but all I get is a line and a half of blocks at the output. I already changed LCD, Shift Register, PIC16F84A and even tried it with PIC16F877 with no luck. My code has been reviewed by 3 people already with no one finding anything wrong with it. I don't know what I am doing wrong please help. My code below for reference:

Note: I use MPLAB v8.30, the code compiles with no errors. Also, I use Pickit 3 to program the PIC16F84A and PIC16F877.

Code intentionally removed. Please see below for working code...
 
Last edited:

Frosty_47

New Member
I was wondering if dead/faulty XTAL oscilator can cause this problem...
I mean what are the chance of XTAL failing ?
 

ericgibbs

Well-Known Member
Most Helpful Member
I was wondering if dead/faulty XTAL oscilator can cause this problem...
I mean what are the chance of XTAL failing ?
hi,
Ran in your program in the OS sim,OK, using a modified external S/R module. Note this ext module clocks on the low to high edge.

Look at these two images.
The S/R shows the 0x38 LCD setup code byte, have you wired the LCD so that D7 of the S/R is the LSB [D0] of the LCD.???

Also the clocking pulse in the program is going high to low,, the LS164 datasheet states a low to high clock pulse edge.???

Also are you resetting the LS164 at power up.??

Please post your circuit diagram.

EDIT:
The LCD setup sequence needs reworking.
Send at least 2 or 3, 0x38's remove all but one of the 0x06's and check the remainder.

Checked thru all the LCD init and data transfer, it checks OK in simulation.
 

Attachments

Last edited:

blueroomelectronics

Well-Known Member
Use the PK3 debug mode on the 16F877. If the crystal isn't running it won't enter debug.

PS if you're using a solderless breadboard crystals may not work properly. Also don't forget 0.1uF decoupling caps on VDD &VSS they're not optional.
 

Frosty_47

New Member
Thank you for taking time to help me.

I moded the code. However still get nothing at output. Oh and I don't see why the D7 of S/R be connected to LSB when I am shifting right... I tried that anyway with no luck :(
My moded code below for reference:

PHP:
Code intentionally removed. Please see below for working code...
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
hi Frosty,

Unzip this zip into an avi and play on your Windows Media.

I have modified an Oshonsoft module to work as a 74LS164.
 

Attachments

Frosty_47

New Member
hi Frosty,

Unzip this zip into an avi and play on your Windows Media.

I have modified an Oshonsoft module to work as a 74LS164.
WOW! Anymore and I gonna have to start paying you ;)

Yeah, I changed the code to rotate LEFT, that way no need to reconnect the LCD. Still no luck... I get a blank display...
 

Frosty_47

New Member
Finaly !

I GOT IT TO WORK! I found one eror in DATAWRT section:

Eror found: BCF PORTA,0 ;RS = 1 for command

Correct Code: BSF PORTA,0 ;RS = 1 for command

Also I had to add:

PHP:
MOVLW	0x07				
CALL	COMNWRT
CALL	LDELAY

MOVLW	0x06				
CALL	COMNWRT
CALL	LDELAY
Without above addition, the characters would not be in their right specified positions...


Here is the Working Code:

PHP:
list p=16F84A
#include <p16F84A.inc>

;***********************Setup constants***********************

BLA		equ		0x20
BLA2	equ		0x21
BLA3	equ		0x22
BLA4	equ		0x23
BLA5	equ		0x24

REG_1	equ		0x30
REG_2	equ		0x31
LOOP	equ		0x32
LOOP2	equ		0x33

;***********************Setup the PORT************************

org 0x00
goto main
org 0x10

main


bsf 	STATUS,5			;switch to Bank 1
MOVLW	0x00
MOVWF	TRISA				;set all PORTA pins as outputs
MOVWF	TRISB				;set all PORTB pins as outputs
bcf		STATUS,5			;switch back to Bank0

Start

bcf		PORTA,2
CALL	LDELAY

MOVLW	0x38				;initialize LCD 5x7 Matrix
CALL	COMNWRT
CALL	LDELAY

MOVLW	0x38				;initialize LCD 5x7 Matrix
CALL	COMNWRT
CALL	LDELAY

MOVLW	0x07				
CALL	COMNWRT
CALL	LDELAY

MOVLW	0x06				
CALL	COMNWRT
CALL	LDELAY

MOVLW	0x0F				;Display on, cursor blinking
CALL	COMNWRT
CALL	DELAY

MOVLW	0x85				;cursor at line 1, position 5
CALL	COMNWRT
CALL	DELAY

MOVLW	0x41				;Display letter 'A'
CALL	DATAWRT
CALL	DELAY

MOVLW	0x4E				;Display letter 'N'
CALL	DATAWRT
CALL	DELAY

MOVLW	0x44				;Display letter 'D'
CALL	DATAWRT
CALL	DELAY

MOVLW	0x52				;Display letter 'R'
CALL	DATAWRT
CALL	DELAY

MOVLW	0x45				;Display letter 'E'
CALL	DATAWRT
CALL	DELAY

MOVLW	0x49				;Display letter 'I'
CALL	DATAWRT
CALL	DELAY

MOVLW	0xC5				;cursor at line 2, position 4
CALL	COMNWRT
CALL	DELAY

MOVLW	0x4D				;Display letter 'M'
CALL	DATAWRT
CALL	DELAY

MOVLW	0x4F				;Display letter 'O'
CALL	DATAWRT
CALL	DELAY

MOVLW	0x52				;Display letter 'R'
CALL	DATAWRT	
CALL	DELAY

MOVLW	0x4F				;Display letter 'O'
CALL	DATAWRT
CALL	DELAY

MOVLW	0x5A				;Display letter 'Z'
CALL	DATAWRT
CALL	DELAY

THERE	Goto	THERE		;stay here (I mean there).

COMNWRT						;send command to LCD
		MOVWF	REG_1		;coppy W to reg_1
		MOVLW	0x08		;Load 8 to W
		MOVWF	LOOP		;Load 8 to Loop
HERE	RLF		REG_1,1		;rotate right
		BTFSS	STATUS,0	;check carry
		bcf		PORTB,1		;clear RB1 if carry = 0
		BTFSC	STATUS,0	;check carry
		bsf		PORTB,1		;set RB1 if carry = 1
		bcf		PORTB,0		;clear clock
		bsf		PORTB,0		;L-to-H clock pule
		bcf		PORTB,0		;clear clock
		DECFSZ	LOOP,1		;repeat 8 times
		GOTO	HERE	
		
		bcf		PORTA,0		;RS = 0 for command
		bcf		PORTA,1		;R/W = 0 for write
		bsf		PORTA,2		;E = 1 for high pulse
		CALL	SDELAY		;make a wide en pulse
		bcf		PORTA,2		;E = 0 for H-to-L pulse
		RETURN



DATAWRT						;write data to LCD
							;copy W to LCD Data Pin
		MOVWF	REG_2		;coppy W to reg_2
		MOVLW	0x08		;Load 8 to W
		MOVWF	LOOP2		;Load 8 to Loop2
HERE2	RLF		REG_2,1		;rotate right
		BTFSS	STATUS,0	;check carry
		bcf		PORTB,1		;clear RB1 if carry = 0
		BTFSC	STATUS,0	;check carry
		bsf		PORTB,1		;set RB1 if carry = 1
		bcf		PORTB,0		;clear clock
		bsf		PORTB,0		;L-to-H clock pule
		bcf		PORTB,0		;clear clock
		DECFSZ	LOOP2,1		;repeat 8 times
		GOTO	HERE2	

		BSF		PORTA,0		;RS = 1 for command
		BCF		PORTA,1		;R/W = 0 for write
		BSF		PORTA,2		;E = 1 for high pulse
		CALL	SDELAY		;make a wide en pulse
		BCF		PORTA,2		;E = 0 for H-to-L pulse
		RETURN


DELAY						;15.3mS LCD Write Delay
			MOVLW	0x44
			MOVWF	BLA
			MOVLW	0x19
			MOVWF	BLA2
			
BACK		DECFSZ	BLA,1
			GOTO	BACK
BACK2		DECFSZ	BLA2,1
			GOTO	BACK2
			RETURN


LDELAY						;4.5 second power-up delay
			MOVLW 	0xFA
			MOVWF	BLA3
			MOVWF	BLA4
			MOVLW	0x02
			MOVWF	BLA5

BACK3		DECFSZ	BLA3,1
			GOTO	BACK3
BACK4		DECFSZ	BLA4,1
			GOTO	BACK4
BACK5		DECFSZ	BLA5,1
			GOTO	BACK5
			RETURN


SDELAY						;3uS En pulse delay
			NOP
			RETURN

			END
Thank you Ericgibbs for all your help and efforts!
I found your video to be very helpful in reminding me of shift register operation...
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
hi,

Just a small point about your listing.

Code:
MOVLW "A";   0x41                ;Display letter 'A'
CALL    DATAWRT
CALL    DELAY

MOVLW   "N"; 0x4E                ;Display letter 'N'
CALL    DATAWRT
CALL    DELAY

MOVLW   "D"; 0x44                ;Display letter 'D'
CALL    DATAWRT
CALL    DELAY

MOVLW   "R" ;0x52                ;Display letter 'R'
CALL    DATAWRT
CALL    DELAY

MOVLW    "E";0x45                ;Display letter 'E'
CALL    DATAWRT
CALL    DELAY
You can use double quotes for the ASCII characters.:)
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top