Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Pic16f877a driving 16X04(Samsung KS0066)-Assembly-

Status
Not open for further replies.

kgavionics

Full Member level 3
Joined
Jun 12, 2012
Messages
167
Helped
7
Reputation
14
Reaction score
11
Trophy points
1,298
Location
Alberta.Canada
Activity points
2,479
hi
i'm trying to hook up an LCD display based on the samsung KS0066 chip which is compliant with the hitachi4780. I uploaded my code into the chip in proteus sim and everything seems to work fine,but my problem is with the actual chip
on my breadboard nothing is not working exept the Lcd backlight lol.

here's my code (copied from a the book Embeded systems with pic by Charles Kim)


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
;LCD-P.asm
;
;This program is to display an 20x4 LCD module
;by Truly (HD44780 compatible)
;
;8-bit interfacing
;
;Pin Connection from LCD to 16F877
;LCD (pin#) 16F877 (pin#)
;DB7 (14) -----RB7(40)
;DB6 (13) ----RB6(39)
;DB5 (12) ----RB5(38)
;DB4 (11) ----RB4(37)
;DB3 (10) ----RB3(36)
;DB2 (9)---- RB2(35)
;DB1 (8) ----RB1(34)
;DB0 (7) ----RB0(33)
;E (6) ------RD5(28)
;RW (5) -----RD6(29)
;RS (4) -----RD4(27)
;Vo (3) -----+5V
;Vdd (2) ----+5V
;Vss (1) -----GND
;
;Example code to display:
; PIC
; AND
; LCD
; DISPLAY
;
list P = 16F877
STATUS EQU 0x03
PORTB EQU 0x06
TRISB EQU 0x86
PORTD EQU 0x08
TRISD EQU 0x88
RS EQU 0x04 ;RD4
E EQU 0x05 ;RD5
RW EQU 0x06 ;RW
;RAM arEA
CBLOCK 0x20
Kount120us ;Delay count (number of instr cycles for delay)
Kount100us
Kount1ms
Kount10ms
Kount1s
Kount10s
Kount1m
ENDC
;
;The Next 5 lines must be here
;because of bootloader arrangement
;Bootloader first execute the first 4 addresses
;then jump to the address what the execution directs
;=========================================================
        org 0x0000 ;line 1
        goto START ;line 2 ($0000)
        org 0x05
delay120us
        banksel Kount120us
        movlw H'C5' ;D'197'
        movwf Kount120us
        
        R120us
        decfsz Kount120us
        goto R120us
        return
        ;
delay100us
        banksel Kount100us
        movlw H'A4'
        movwf Kount100us
        R100us
        decfsz Kount100us
        goto R100us
        return
        ;
        ;1ms delay
delay1ms
        banksel Kount1ms
        movlw 0x0A ;10
        movwf Kount1ms
        R1ms call delay100us
        decfsz Kount1ms
        goto R1ms
        return
        ;
        ;10ms delay
        ; call 100 times of 100 us delay (with some time discrepancy)
delay10ms
        banksel Kount10ms
        movlw H'64' ;100
        movwf Kount10ms
        R10ms call delay100us
        decfsz Kount10ms
        goto R10ms
        return
        ;
        ;1 sec delay
        ;call 100 times of 10ms delay
delay1s
        banksel Kount1s
        movlw H'64'
        movwf Kount1s
        R1s call delay10ms
        decfsz Kount1s
        goto R1s
        return
        ;
        ;10 s delay
        ;call 10 tiems of 1 s delay
delay10s
        banksel Kount10s
        movlw H'0A' ;10
        movwf Kount10s
        R10s call delay1s
        decfsz Kount10s
        goto R10s
        return
        ;
        ;1 min delay
        ;call 60 times of 1 sec delay
delay1m
        banksel Kount1m
        
        movlw H'3C' ;60
        movwf Kount1m
        R1m call delay1s
        decfsz Kount1m
        goto R1m
        return
        
        
        
        START
        BANKSEL TRISD
        ; 1 for input, 0 for output
        movlw 0x00
        movwf TRISD
        movwf TRISB ;RB<7:0> are all outputs
        banksel PORTB
        clrf PORTB
        
        clrf PORTD ;Here RW is pulled down to ground
        ;LCD routine starts
        call delay10ms
        ;give LCD module to reset automatically
        ;Fundtion for 8-bit, 2-line display, and 5x8 dot matrix
        movlw 0x38
        call instw
        ;Display On, CUrsor On, No blinking
        movlw 0x0E ;0F would blink
        call instw
        ;DDRAM address increment by one & cursor shift to right
        movlw 0x06
        call instw
        ;DISPLAY CLEAR
        movlw 0x01
        call instw
        ;Set DDRAM ADDRES
        movlw 0x80 ;00
        call instw
        ;WRITE DATA in the 1st position of line 1
        movlw 0x50 ;P
        call dataw
        movlw 0x49 ;I
        call dataw
        movlw 0x43 ;C
        call dataw
        ;Set DDRAM address for the 1st position of line 2 (40h)
        movlw 0xC0 ;B'11000000'
        call instw ;RS=0
        ;Write A, N, D
        movlw 0x41 ;A
        call dataw
        movlw 0x4E
        call dataw ;N
        movlw 0x44
        call dataw ;D
        ;Set DDRAM address for the next 3 characters (L, C, and D) in line #3. (14h)
        ;The DDRAM address starts from 14h for the line #3.
        movlw 0x94 ;B'10010000'
        call instw ;RS=0
        ;Write the three characters, 'L', 'C', and 'D' to DDRAM.
        ;They are displayed at the line #3 from position 1.
        movlw 0x4C ;L
        call dataw
        movlw 0x43
        call dataw ;C
        movlw 0x44
        call dataw ;
        
        movlw 0xD4
        call instw ;RS=0
        ;Write the seven characters, 'D', 'I', 'S', 'P', 'L', 'A', and 'Y' to DDRAM.
        ;They are displayed at the line #4 from position 1.
        movlw 0x44 ;D
        call dataw
        movlw 0x49 ;I
        call dataw
        movlw 0x53 ;S
        call dataw ;
        movlw 0x50 ;P
        call dataw
        movlw 0x4C ;L
        call dataw
        movlw 0x41 ;A
        call dataw
        movlw 0x59 ;Y
        call dataw
        ;Now let's move the cursor to the home position (position 1 of line #1)
        ;and set the DDRAM address to 0. This is done by the "return home"
        instruction.
        movlw 0x02
        call instw
        IDLE nop
        goto IDLE
        ;====SUBROUTINES =====
        ;subroutine instw (instruction write)
        ;instruction to be written is stored in W before the call
        instw movwf PORTB
        call delay1ms ;delay may not be needed
        bcf PORTD, RS
        call delay1ms
        bsf PORTD, E
        call delay1ms
        bcf PORTD,E
        call delay10ms
        return
        ;subroutine dataw (data write)
        dataw movwf PORTB
        call delay1ms ;delay may not be needed
        bsf PORTD, RS
        call delay1ms
        bsf PORTD, E
        call delay1ms
        bcf PORTD, E ;Transitional E signal
        call delay10ms
        return
;
;==========================================================
;DELAY SUBROUTINES
 
;========
END



can someone help me what's going wrong?

thank you in advance
 

Hi,

Yes, that code simulates fine, but you have not given any details of the pic circuit you are using or the crystal ? 4 meg assumed.

Pin 1, Mlcre should be tied to +5v, and the crystal and 2 x 22pf caps should be on pins 13 and 14
Have you got both sets of power rails connected pin 11.12 and 31,32
 

Hi,

Yes, that code simulates fine, but you have not given any details of the pic circuit you are using or the crystal ? 4 meg assumed.

Pin 1, Mlcre should be tied to +5v, and the crystal and 2 x 22pf caps should be on pins 13 and 14
Have you got both sets of power rails connected pin 11.12 and 31,32
hi
the microcontroller is hooked up correctly.This problem is getting me crazy.The Lcd is not showing anay character only backlight.it's pretty strange.
Is there any way to test the Lcd module if it's faulty or no?
 

hi
the microcontroller is hooked up correctly.This problem is getting me crazy.The Lcd is not showing anay character only backlight.it's pretty strange.
Is there any way to test the Lcd module if it's faulty or no?


Hi,

Don't know of your set up etc, so many point unknown .. some key ones ..

Have you proven the 877a / breadboard with a simple flashing led program ?

Have you got the lcd pin VEE connected via a 10k trimmer ? - again a circuit diagram or picture might help.

Again no idea what programmer/ software you are using / have you proven the program is loaded ok by reading it back ?
 

Here's a little video :



the flashing led is just a test that made.My problem that my display is 16X04 and you can see that only two line are activated, may be my problem is here and i need to activate the other lines.??????
 
Last edited:

Hi,

On the hardware side , you could try these things.
Put a 100nf across the pic pins 11/12 and 31/32 to stop any power line interference.

The crystal and caps have very thin leads which can give poor contact on a bread board, so that could cause irratiic timings that the lcd does not like.
Solder those three parts on to some board and then THREE thicker, short wires to plug into the breadboard.

Not sure what those pos and neg rails going to pin 4 and 5 ? are for ?

What you could try is this code and wiring your lcd in 4 bit mode, it may not display on the correct lines but should show something.
 

Attachments

  • lcd4bit.7z
    131.5 KB · Views: 107

thank you wp100 for helping me.you are right the pin 4 et 5 were tied to power rails and i didn't pay attention for that, because the breadboard was used for another circuit.
i will remove these two pins from power rails and i'll try what you recommend in a few minutes.

thank you wp100
 

Hi,

On the hardware side , you could try these things.
Put a 100nf across the pic pins 11/12 and 31/32 to stop any power line interference.

The crystal and caps have very thin leads which can give poor contact on a bread board, so that could cause irratiic timings that the lcd does not like.
Solder those three parts on to some board and then THREE thicker, short wires to plug into the breadboard.

Not sure what those pos and neg rails going to pin 4 and 5 ? are for ?

What you could try is this code and wiring your lcd in 4 bit mode, it may not display on the correct lines but should show something.

i did what you suggested to me,but unfortunately i have the same problem.i used two different power supply.two chips, but all i have is an lcd with two lines.this problem is getting me crazy.

- - - Updated - - -

Obviously, i'm not the only one that have problem with this kind of Lcd


https://www.edaboard.com/threads/245748/

What's wrong with the ks0066?
 
Last edited:

i did what you suggested to me,but unfortunately i have the same problem.i used two different power supply.two chips, but all i have is an lcd with two lines.this problem is getting me crazy.

- - - Updated - - -

Obviously, i'm not the only one that have problem with this kind of Lcd


https://www.edaboard.com/threads/245748/

What's wrong with the ks0066?


Hi,

I do have a JHD204A which is ks0066 based and it works ok, however thats connected /soldered up to an Arduino and a serial converter so little relevance to the pic assembler.

Have you tried using that code I sent ?

It might just be down to the delay times you used which may be too fast ? perhaps try doubling all you delays partic in the Init stages
 

Hi,

I do have a JHD204A which is ks0066 based and it works ok, however thats connected /soldered up to an Arduino and a serial converter so little relevance to the pic assembler.

Have you tried using that code I sent ?

It might just be down to the delay times you used which may be too fast ? perhaps try doubling all you delays partic in the Init stages

ok i'll try doubling the delay time.thx

- - - Updated - - -

Finally, it works with my code wp100
First, i replaced the crystal by 1Mhz one, but didn't work.I replaced the chip by another 16f777 and suddenly, it worked fine.for now i don't know the reason why,but i'll try to find out what's going on.
here's a little video

now i'm gonna verify why it's not working on the pic16f877a
 

Hi,

To be honest it does sound like poor connections on the breadboard which can easily happen, partic with the crystal and cap leads as I mentioned earlier.

As its such a big board, you could rebuild it in different section and see if that is the problem

Also shorting wires on the lcd soldered connections are another common problem, partic if stranded wire has been used and one strand breaks and shorts onto the next pin.
 
hi
now i'm trying to do my own simple code and i can confirm it's working pretty well on the 16f777.The problem remains on the pic16f877a ( even with another brand new chip).when i remove the working chip and replace it by the 16f877a compile the program and burn it, the Lcd stops from working.the only thing i did it differently, is the header file on .asm file, i don't think that the problem might come from the hardware itself.It's pretty weird...for tonight i'm gonna take a rest,because i'm very tired, tomorrow will continue the troubleshooting.
 

hi
now i'm trying to do my own simple code and i can confirm it's working pretty well on the 16f777.The problem remains on the pic16f877a ( even with another brand new chip).when i remove the working chip and replace it by the 16f877a compile the program and burn it, the Lcd stops from working.the only thing i did it differently, is the header file on .asm file, i don't think that the problem might come from the hardware itself.It's pretty weird...for tonight i'm gonna take a rest,because i'm very tired, tomorrow will continue the troubleshooting.



Hi,

Well when I saw your first mention of a 777 chip last night I thought it was just a typo error. but now seems thats not so and you do have both types of chip.

Again, it implies to me where the problem my be; the key difference between the chips is that the 777 has an internal oscillator, which I think,if like other chips, defauts to a 1mhz internal oscillator.

So its likey one or two things are causing your problems.

First, the code you posted does not contain any CONFIG line of code - are you using any ?

Second the 877A must have the external crystal so if there is any problem with the crystal or caps or their connections it will not run properly.
You are using caps around 22pf ? ( 15 to 33pf ok)

Here are typical config lines you should be using.

For the 877A with a 1 to 4 mhz crystal

Code:
	list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF


For the 777 usingits internal 1mhz oscillator
With some program code change you can make it run up to 8 mhz



Code:
	list		p=16f777				; list directive to define processor
	#include	<P16F777.inc>		; processor specific variable definitions
	
	__CONFIG    _CONFIG1,  _CP_OFF & _CCP2_RC1 & _DEBUG_OFF & _VBOR_2_0 & _BOREN_0 & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _INTRC_IO
	__CONFIG    _CONFIG2,  _BORSEN_0 & _IESO_OFF & _FCMEN_OFF




To make it use the external crystal
Code:
	list		p=16f777				; list directive to define processor
	#include	<P16F777.inc>		; processor specific variable definitions
	
	__CONFIG    _CONFIG1,  _CP_OFF & _CCP2_RC1 & _DEBUG_OFF & _VBOR_2_0 & _BOREN_0 & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _XT_OSC  
	__CONFIG    _CONFIG2,  _BORSEN_0 & _IESO_OFF & _FCMEN_OFF
 
Thank you wp100
replaced my header file by yours and it's working fine.Before, i used to use the folowing header, which seems correct and it's working for other programs, expect for LCD

Code:
List P = PIC16F877a 
#include <P16f877a.INC>
__config  _XT_OSC & _PWRTE_OFF & _WDT_OFF & _CP_OFF

thank you so much wp100

- - - Updated - - -

hi again
i have a question.Why the program is looping like this


even thought, my following code doesn't have the goto main.
Code:
;=================================================  ===========
; File name:
; Date:
; Author:
; Processor:
; Reference circuit:
;=================================================  ===========
; Copyright notice:
;=================================================  ===========
; Program Description:
;
;===========================
; configuration switches
;===========================
list		p=16f877A	; list directive to define processor
	#include	<p16f877A.inc>	; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF


;=================================================  ====
; constant definitions
;=================================================  ====
;=================================================  ====
; PIC register equates
pcl  EQU 2
;=================================================  ====
;=================================================  ====
; variables in PIC RAM
;=================================================  ====
cblock 0x20
counter1 :  1 
counter2  : 1

endc
;=================================================  ===========
; program
;=================================================  ===========
org 0X00 ; start at address
goto main
; Space for interrupt handlers
org 0x08


delay
	movlw	0x1a
	movwf	counter2
loop1
	movlw	0xff
	movwf	counter1
loop2
 	nop
	decfsz counter1
	goto loop2
	decfsz counter2
	goto loop1
return

instw  
	movwf	PORTB
	call delay
	bcf	PORTD,4
	call delay
	bsf	PORTD,5
	call delay
	bcf	PORTD,5
	call	delay
return
dataw 
	movwf PORTB
	call delay
	bsf PORTD, 4
	call delay
	bsf PORTD, 5
	call delay
	bcf PORTD, 5 ;Transitional E signal
	call delay
return

main:
	bsf STATUS,RP0
	movlw	0x00
	movwf	TRISB
	movwf	TRISD
	bcf STATUS,RP0
	clrf	PORTD
	clrf	PORTB
call delay
call delay

clrf PORTD ;Here RW is pulled down to ground
;LCD routine starts
call delay
;give LCD module to reset automatically
;Fundtion for 8-bit, 2-line display, and 5x8 dot matrix


movlw 0x38
	call instw
	call delay
	movlw 0x0E
	call instw
	call delay
	movlw 0x01
	call instw
	call delay
	movlw 0x45
	call dataw
	movlw 0x44
	call dataw 
	movlw 0x41
	call dataw
	movlw 0x42
	call dataw
	movlw 0x4f
	call dataw
	movlw 0x41
	call dataw 
	movlw 0x52
	call dataw 
	movlw 0x44
	call dataw
	movlw 0x20
	call dataw	
;=================================================  ===========
end ; END OF PROGRAM
;=================================================  ===========
 

Hi,

The "end" is not a piece of program code, it is a "directive " to the Assembler that the previous instruction is the end of the whole program code.
Not necessarily the place where the progam loop ends, though in your case it does.

Cannot remember the exact sequence, but when in a situation like that, think it gets thrown back to either main or the beginning 0x00

If you want to visually stop the program from running at that point you simply put it into a tight loop.
stoploop goto stoploop just after your last line of your program loop.

With lcds its much more common to use the 4 bit method instead of all 8 - though not a problem while you are just testing on large chips.

There is several ways to output your data, as think you can see your way is rather code intensive.

Have a look around these sites for some good lcd code and info.

http://www.epemag.wimborne.co.uk/resources.htm

http://www.winpicprog.co.uk/pic_tutorial3.htm
 
the only way i found to exit the program is the sleep instruction.
i'm wondering why the program is working all right on proteus.
 

Hi,

Isis is not 100% identical to the real thing, can at times mislead you.

Have you tried that example of mine I sent.

Don't forget the pic and lcd only do what you tell it to ..

If you have a Pickit / ICD 2 or 3 programmer you can use the Debugger function and run/step though the code so you can then 'see' what happens when it get to the last line of your code.
 

Good idea guys
I've never used the debug function of my pickit( i have both 2 and 3),but now it's the time to use it wp100
@jayanth i will post my code.thank you my friend
 

Hi,

You will have to reassign your lcd ports as Debugger must have total control of Mclre, RB6 and RB7 pins.

Use a Breakpoint just before the end of your code, so you can Run to the Breakpoint then single step over the last few instruction and see what happens after the last one. ( the same idea applies when you wan to 'run' over delay routines)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top