Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Forums > General Electronics Chat


General Electronics Chat This forum is for general chat about electronics, eg: Dont know what a part does? Dont know how to read a circuit? Want to get an opinion?

Reply
 
Tools
Old 13th August 2009, 01:03 AM   #1
Default PIC16F84A LCD Programming Help

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.

Quote:
Code intentionally removed. Please see below for working code...
__________________
"The people who cast the votes don't decide an election, the people who count the votes do."
-Joseph Stalin

Last edited by Frosty_47; 13th August 2009 at 11:14 PM.
Frosty_47 is offline  
Old 13th August 2009, 05:31 AM   #2
Default

I was wondering if dead/faulty XTAL oscilator can cause this problem...
I mean what are the chance of XTAL failing ?
__________________
"The people who cast the votes don't decide an election, the people who count the votes do."
-Joseph Stalin
Frosty_47 is offline  
Old 13th August 2009, 09:11 AM   #3
Default

Quote:
Originally Posted by Frosty_47 View Post
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.
Attached Thumbnails
PIC16F84A LCD Programming Help-aaesp02.gif   PIC16F84A LCD Programming Help-aaesp03.gif  
__________________
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 13th August 2009 at 01:41 PM.
ericgibbs is offline  
Old 13th August 2009, 03:11 PM   #4
Default

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.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 13th August 2009, 03:13 PM   #5
Default

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:
Code intentionally removedPlease see below for working code... 
__________________
"The people who cast the votes don't decide an election, the people who count the votes do."
-Joseph Stalin

Last edited by Frosty_47; 13th August 2009 at 11:15 PM.
Frosty_47 is offline  
Old 13th August 2009, 03:16 PM   #6
Default

Learn to use the debugger. Makes troubleshooting much easier.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com/
blueroomelectronics is offline  
Old 13th August 2009, 03:46 PM   #7
Default

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.
Attached Files
File Type: zip frosty2zip.zip (415.2 KB, 10 views)
__________________
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 13th August 2009, 08:04 PM   #8
Default

Quote:
Originally Posted by ericgibbs View Post
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...
__________________
"The people who cast the votes don't decide an election, the people who count the votes do."
-Joseph Stalin
Frosty_47 is offline  
Old 13th August 2009, 11:19 PM   #9
Default 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 Code:
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 Code:
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 oncursor blinking
CALL    COMNWRT
CALL    DELAY

MOVLW    0x85                
;cursor at line 1position 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 2position 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 for command
        bcf        PORTA
,1        ;R/for write
        bsf        PORTA
,2        ;for high pulse
        CALL    SDELAY        
;make a wide en pulse
        bcf        PORTA
,2        ;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 for command
        BCF        PORTA
,1        ;R/for write
        BSF        PORTA
,2        ;for high pulse
        CALL    SDELAY        
;make a wide en pulse
        BCF        PORTA
,2        ;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...
__________________
"The people who cast the votes don't decide an election, the people who count the votes do."
-Joseph Stalin

Last edited by Frosty_47; 13th August 2009 at 11:29 PM.
Frosty_47 is offline  
Old 14th August 2009, 08:54 AM   #10
Default

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.
__________________
Eric " Good enough is Perfect "
I will NOT answer PM's requesting technical help, please use the Forum
PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Reply

Tags
lcd, pic16f84a, programming

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Pic16f84a mycalbs Micro Controllers 1 24th February 2009 03:01 PM
PIC16F84A need help kac121 Micro Controllers 15 21st June 2006 11:31 PM
Problem Programming PIC16F84A shoie01 Micro Controllers 1 9th March 2005 09:12 AM
Program verify error when programming pic16f84a chip xpembedded Micro Controllers 2 31st May 2004 10:07 AM
problem of programming pic16f84a Byron Yau Micro Controllers 15 19th April 2003 06:10 PM



All times are GMT. The time now is 05:03 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker