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.

[Moved] Interfacing PIC 16F84A with JHD 162a LCD?

Status
Not open for further replies.

onkar1111

Junior Member level 1
Joined
Apr 5, 2012
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
pune
Activity points
1,452
hi, i am doing a project on cryptography using pic 16F84a. i hv used JHD 162a LCD. on interfacing lcd with pic developmant board a get 16 dark boxes on it. my backlight is working fine...bt am nt able to get de required output...i hv compiled my lcd program on mplab and its working fine. even i hv simulated it on virtual LCD n its showing required o/p. bt am unable to get it on LCD...plz help...
 

Re: Interfacing PIC 16F84A with JHD 162a LCD?

This is a common problem and this forum already contains a lot of previous discussions on this topic....
You problem may be improper initialization of LCD or improper fuse bits of PIC or some hardware connection problem...
Simulations may work even if the initialization is not perfect....

https://www.edaboard.com/threads/221472/
 
Last edited:

Re: Interfacing PIC 16F84A with JHD 162a LCD?

okk...the initialization routine shown in "I can write into the lcd." is for atmega16...as i am using PIC16F84A which has no serial port...how should i out the characters on lcd. pic has no RS and RW pins...the picture shown in above given link is just the same what am getting ..16 black boxes..and i have done coding in assembly..
i am applying 9v to my development board, whether that is the problem? as many have suggested that 2.5 to 5v is sufficient for jhd 162a lcd.
i can show you my code if needed. i have initialised ports as well as lcd..
 

Hi,

You can use his tutorial which should easily adapt to the 84A chip.
http://www.winpicprog.co.uk/pic_tutorial3.htm

You do not give details of your dev board, but most dev boards have a 5v regulator on board, so 9v input should be ok.
If you do not have a regulator onboard then the 9V will probably have blown the lcd and pic by now .

Post your assembler code and circuit diagram so we can see whats happening, together with any details of your dev board, even a photo.
 
here's my assembler code ...


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
;processor:         PIC 16F84             
;assembler:         MPASM.EXE by MicrochiP
;modules used:      pp-bus, pp-ctr, pp-key, pp-lcd
;----------------------------------------------------------------------------
          processor 16f84               ;Processor type...
 
          org       2007                ;fuse settings:     
          de        b'11001'            ;CP=off, PWRTE=enable; WDT=disable.
                                        ;bit1,0:     11 =RC-Oscillator
                                        ;            01 =XT-Oscillator
;----------------------------------------------------------------------------
w         equ       00                  ;Working-Register address 
f         equ       01                  ;File-Register address 
Z         equ       02                  ;Zero-Bit
porta     equ       05                  ;RB port
portb     equ       06                  ;RB port
trisa     equ       85                  ;TRISA Register
trisb     equ       86                  ;TRISB Register
status    equ       03                  ;Status Register
RP0       equ       05                  ;Status Reg. Bit 5
pcl       equ       02                  ;Program Counter Low
_switch1  equ       00                  ;switch1, input RA0
_switch2  equ       01                  ;switch2, input RA1
_LCD_E    equ      02                   ;LCD-Enable, RA2 
_LCD_RS   equ      03                   ;LCD register select, RA3 
_time0_1  equ       0c                  ;Register for time loop 0,1ms
_time4ms  equ       0d                  ;Register for time loop 4ms
_nrchrs  equ       0e                   ;character counter
;----------------------------------------------------------------------------         
          org       00                  ;Reset vector
          goto      _main               ;Program Start address
 
;------------------------ Initialise ports-------------------------
 
_portinit clrf      porta               ;porta = 0
          clrf      portb               ;portb = 0
          bsf       status,RP0          ;select Bank 1
          movlw     b'00011'            ;write b'00000010' to W-Register
          movwf     trisa               ;RA0/1 are inputs
          clrf      trisb               ;trisb = 0000 0000 (output)
          bcf       status,RP0          ;select Bank 0
          return                        ;end subroutine
 
;-------------------- Initialise LC-Display -----------------------
 
_lcdinit  bcf       porta,_LCD_RS       ;RS-Bit low
          movlw     b'00110000'         ;LCD Initialise 
          call      _w2lcd              ;
          call      _4ms                ;wait _4ms
          movlw     b'00110000'         ;LCD Initialise
          call      _w2lcd              ;
          movlw     b'00110000'         ;LCD Initialise
          call      _w2lcd              ;jump to UP _w2lcd
          movlw     b'00111000'         ;Function Set
                                        ;db4=1 > 8 bit data
                                        ;db3=1 > Display 2 lines
                                        ;db2=0 > 5*8dots
          call      _w2lcd              ;
          movlw     b'00001110'         ;Display Control
                                        ;db2=1 > display on
                                        ;db1=1 > cursor on
                                        ;db0=0 > cursor doesn't blink
          call      _w2lcd              ;
          movlw     b'00000001'         ;clear display
          call      _w2lcd              ;
          return                        ;end subroutine
 
;---------------- write content of w to lcd ------------------
 
_w2lcd    movwf     portb               ;copy W-Reg. to portb
          bsf       porta,_LCD_E        ;toggle enable
          bcf       porta,_LCD_E        ;toggle enable
          clrf      portb               ;portb = 0
 
; Time loop, approx. 100 mys (delay for LCD)
 
_100mys   movlw     d'25'               ;d'25' in W-Register
          movwf     _time0_1            ;copy W to register _time0_1
__m1      decf      _time0_1,f          ;decrement Reg. _time0_1
          btfss     status,Z            ;if Zero Bit in Status Register = 1
                                        ;skip next instruction
          goto      __m1                ;jump to __m1
          return                        ;end subroutine
 
; Time loop approx. 4 ms (delay for LCD) --
 
_4ms      movlw     d'40'               ;d'40' in W-Register
          movwf     _time4ms            ;copy W to _time4ms
__m2      call      _100mys             ; delay 100mys
          decf      _time4ms,f          ;decrement _time4ms
          btfss     status,Z            ;if Zero Bit in Status Register = 1
                                        ;skip next instruction
          goto      __m2                ;jump to __m2
          return                        ;end subroutine
 
;------------- move LCD-Cursor to first line, leftmost position --------------
  
_lcdline1 movlw     b'10000000'         ;b'10000000' in W-Register
          movwf     portb               ;copy W-Reg. to portb
          call      _w2lcd              ;jump to _w2lcd      
          return                        ;end subroutine
          
;------------- move LCD-Cursor to second line, leftmost position --------------
_lcdline2 movlw     b'11000000'         ;b'11000000' in W-Register
          movwf     portb               ;copy W to portb
          call      _w2lcd              ;write to LCD
          return                        ;end subroutine
 
 
;-------------- output text to LCD ----------------
  
_txt2lcd  bsf       porta,_LCD_RS       ;switch to LCD Data Mode
__m3      movf      _nrchrs,w           ;copy _nrchrs to W-Register
          call      _text               ;write last character
          iorlw     0                   ;
          btfsc     status,Z            ;if Zero Bit in Status Register = 0
                                        ;skip next instruction
          goto      __m4                ;jump to __m4
          call      _w2lcd              ;jump to _w2lcd
          incf      _nrchrs,f           ;increment _nrchrs  
          goto      __m3                ;jump to __m3
__m4      bcf       porta,_LCD_RS       ;reset RS-Bit
          return                        ;end subroutine
 
;------------------ reads next character into W-Register ------------------
 
_text     addwf     pcl,f               ;Add Prog.Counter Low to W-Reg. den 
                                        ;result in f
          dt        "Hello           ",0      ;Text1 (define table)
          dt        "World...........",0      ;Text2 (Assembler directive)
 
;**************************** Main program  *********************************
 
_main     call      _portinit           ;initialise ports
          call      _lcdinit            ;lcd init
__m5      btfss     porta,_switch2      ;if switch2 porta = 1
                                        ;skip next instruction
          goto      __m5                ;jump to __m5
          clrf      _nrchrs            ;clear File_Register _counter
                                        ;(=start Text1)
          call      _txt2lcd            ;send text to LCD
__m6      btfsc     porta,_switch2      ;if switch2 porta = 0
                                        ;skip next instruction                                        
          goto      __m6                ;jump to __m6
          call      _lcdline2           ;get second line
          movlw     d'17'               ;d'17' in W-Register
          movwf     _nrchrs            ;W to Register _nrchrs (=start Text2)
          call      _txt2lcd            ;write second line
__m7      btfss     porta,_switch1      ;if switch1 porta = 1
                                        ;skip next instruction
          goto      __m7                ;jump to __m7
          movlw     b'00000001'         ;clear display
          call      _w2lcd              ;
          goto      __m5                ;_
                                        
          end                           ;end program
;********************************** END ************************************

 
Last edited by a moderator:

Hi,

When you post your code enclose it within the ' # ' CODE tags, the moderators will tell you off, like they did me !!

You really need to enclose a circuit diagram of your hardware.

Some points that are important.

This code is very old, the 16F84 chip is obselete, you can use the 84A instead without any changes.

You do not specify what oscillator should be used with the program code - have simulated it with a 4 mhz crystal.

How have you got your lcd wired up, the RW pin on the lcd needs to be tied to ground for this 2 control line version.
It also needs all 8 lines of port B connecting to the lcd data line d0-d7

The code is basically sound, but just these 3 lines of code as shown below

Code:
[B]REMOVE THIS CODE[/B]
 [I]   ;  processor: PIC 16F84
    ;assembler: MPASM.EXE by MicrochiP
    ;modules used: pp-bus, pp-ctr, pp-key, pp-lcd
    ;----------------------------------------------------------------------------
;    processor 16f84 ;Processor type...

;    org 2007 ;fuse settings:
;   de b'11001' ;CP=off, PWRTE=enable; WDT=disable.
;   bit1,0: 11 =RC-Oscillator
;   01 =XT-Oscillator[/I]

[B][I]ADD THIS CODE[/I][/B]

[B]	list      p=16F84             ; list directive to define processor
	#include <p16F84.inc>         ; processor specific variable definitions

	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
[/B]
    ;----------------------------------------------------------------------------
 
hi,

Sir, your replies are helping me a lot and are adding to my pratical knowledge.
as you said i checked all de port B connections to LCD's D0-D7 pins, they are working fine. In between while checking our LCD, we got some sort of text displaying as "c c c c c c" and another time we got a cursor blinking. But after that its the same problem again, we are getting black boxes.
After that we changed our LCD to verify whether there's problem with LCD, but in vain.

For your help i have attached a pdf of PIC 16F84A development board which we used for developing are kit. Its the same as shown in pdf. you can refer it for circuit diagram. whole kit is working fine except the LCD. please go through it and guide me accordingly.
 

Attachments

  • Elektor-d875878f-d49e-4e45-930f-6ab92b3ee057.pdf
    900.2 KB · Views: 154

Hi,

Looking at the diagram there are 2 things that might cause your problems.

First the Switches:- I would use this configuration until you prove everything works
Switch 8, left Open when you want to operate the lcd.
Switch 9, should be closed.
Switch 4, left open, a very unusual way to power the back light. You do not need the b/l to test the lcd


Second, your board is running at top speed with a 20mhz crystal.

However when I tried your code it seems to simulate ok at 4mhz, if you run the lcd program 5 times faster with the 20mhz crystal it will almost certainly fail.

Was that program code written to match that dev board ?

Do you you have a 4mhz crystal you can plug in and try the program with that ?

You might also be able to use the RC oscillator, but I am not sure what frequencies the produces.


Let me know what happens and if you can try a 4mhz crystal
 
It should also be noted, LCD routines typically fall into two categories, those that monitor the "Busy" flag and those that use a delay routine between successive writes to the LCD.

The schematic of your development board indicates the R/W line of the LCD has been tied to GND, therefore you can only write to the LCD, not read the "Busy" flag.

When writing or selecting LCD routines for your development board you'll need to ensure they use a delay routine, rather than monitor the "Busy" flag between successive writes to the LCD.

The LCD routines posted in reply #5 do use software delay routines. However, be aware that software delay routines were written for a particular system clock frequency, change that frequency, you've also changed the delay often with unintended results.


WP100 alluded to this in the following statement:

However when I tried your code it seems to simulate ok at 4mhz, if you run the lcd program 5 times faster with the 20mhz crystal it will almost certainly fail.


BigDog
 

As you told i have'nt closed s8 and s9...
and the switch s2 in the kit is given for selecting two frequencies from 4 mhz/20mhz. i tried on both but to no result.

And 1 more thing is, when i reset my whole circuit...the 8 led's shown in above segment blink in a specific pattern after resetting the kit. and shows D0 to D7 as 1000 0010....what its all about am not getting...i think its showing the initialisation of LCD on led's...????
 

Hi,

Set your board to the 20meg crystal and run this code revised for 20meg -it works ok in simulation.

let us know if it works ..
 

Attachments

  • lcd20meg.rar
    27 KB · Views: 97
Thanks a lot sir..it worked this time...actually, it has to..

Sir as you have modified the code for lcd initialisation and its delay routine corresponding to 20mhz crystal...can't it be driven on 4 mhz itself. the code which i gave you was written for 4mhz only, then why it didnt work for 4 mhz? it was simulated, and displayed the required result on simulation, then why not on h/w?
 

Thanks a lot sir..it worked this time...actually, it has to..

Sir as you have modified the code for lcd initialisation and its delay routine corresponding to 20mhz crystal...can't it be driven on 4 mhz itself. the code which i gave you was written for 4mhz only, then why it didnt work for 4 mhz? it was simulated, and displayed the required result on simulation, then why not on h/w?

Hi,

Glad to hear it has worked ok at last.

The orginal code does seem to be at 4mhz and if you ran that first modified code I sent you with a 4 mhz crystal it should work; I only ran it in simulation the same as the 20mhz version.

However did you try using it with the switch selecting the R/C or by fitting a 4 mhz crystal in place of the 20 mhz ?

If you did use the R/C you need to change the Config Line to RC_OSC.

Also your R/C parts are adjustable so how accurate is it - perhaps not enough for the timings of the lcd .

It might be worth getting it to run on a 4 mhz crystal as lots of program code on the web is based on this frequency.

Let us know how you get on...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top