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.

pic 16f628 and ks0070B LCD

Status
Not open for further replies.

tracidfish

New Member
Hi
I have used nigels code example for driving an LCD in 4 bit mode (thanks nigel)

I am using an LCd that i baught from maplins (data sheet here)
https://www.electro-tech-online.com/custompdfs/2010/04/N27AZ.pdf

I have connected the LCD as nigel has explained on his website, and from what I can see the pins are identical to the LCd that I am using.


Unfortunatley all I am getting from the LCD is black squares on the top line. i have been trying for days but cannot work out what is going wrong.

Any help is appreciated,

thanks
charlie
 
Presumably adjusting the contrast alters the contrast of the squares?, from nothing at all, to all black.

This usually means the display isn't getting initialised, so check the connections are correct, and check the code is correct. Are you building it on my veroboard layouts, or in some different way?.
 
Thanks for fast respons nigel - you are a merit to the electronics world!

Yes i have full adjustment of the contrast.
i am using wire wrap and euro card for devlopment.
 
Problems I've heard of people having are things like connecting pins to the wrong points, not actually connecting one or more pins, and accidently joining two pins together.

The PIC not running at all would cause it of course as well, can you scope the pins to make sure something is happening?.
 
Some HD44780 compatible controllers require a slightly different 4-bit interface initialization procedure like the one described here; Brief overview about Hitachi HD44780 LCD controller.

The 4-bit procedure requires specific 4-bit nibble data written at specific intervals to "reset" the controller before switching the controller into 4-bit interface mode. Here's an example that includes the procedure but it's written for a 16F690 with LCD D4..D7 on RC0..RC3, LCD RS on RC4, and LCD E on RC7;

Regards, Mike

Code:
;******************************************************************
;                                                                 *
;                                                                 *
;******************************************************************

        #include        <p16f690.inc>
        radix dec


  __config  _FCMEN_OFF& _IESO_OFF& _MCLRE_OFF& _WDT_OFF& _INTOSCIO

;  _FCMEN_OFF           ; -- fail safe clock monitor enable off
;  _IESO_OFF            ; -- int/ext switch over enable off
;  _BOR_ON              ; default, brown out reset on
;  _CPD_OFF             ; default, data eeprom protection off
;  _CP_OFF              ; default, program code protection off
;  _MCLR_OFF            ; -- use MCLR pin as digital input
;  _PWRTE_OFF           ; default, power up timer off
;  _WDT_OFF             ; -- watch dog timer off
;  _INTOSCIO            ; -- internal osc, OSC1 and OSC2 I/O


;
;  variables
;
temp    equ     0x20            ; Put LCD variable
delayhi equ     0x21            ; DelayCy() subsystem variable

;
;  defines and constants
;

line1   equ     128+0           ; LCD "line 1" command
line2   equ     128+64          ; LCD "line 2" command


;******************************************************************
;  K8LH DelayCy() subsystem macro generates four instructions     *
;******************************************************************
        radix   dec
clock   equ     4               ; 4, 8, 12, 16, 20 (MHz), etc.
usecs   equ     clock/4         ; cycles/microsecond multiplier
msecs   equ     clock/4*1000    ; cycles/millisecond multiplier

DelayCy macro   delay           ; 11..327690 cycle range
        movlw   high((delay-11)/5)+1
        movwf   delayhi
        movlw   low ((delay-11)/5)
        call    uDelay-((delay-11)%5)
        endm

;******************************************************************
;  reset vector                                                   *
;******************************************************************
        org     0x000
v_reset
        clrf    STATUS          ; force bank 0 and IRP = 0        |B0
        goto    Init            ;                                 |B0

;******************************************************************
;  interrupt vector                                               *
;******************************************************************
        org     0x004
v_interrupt
        retfie                  ;

;******************************************************************
;  LCD "Put" subroutines (hardcoded for LCD D7..D4 on RC3..RC0,   *
;  LCD RS on RC4, and LCD E on RC7)                               *
;******************************************************************

PutCMD                          ; entry point for "cmd" data
        clrc                    ; RS = 0 (command)                |B0
        skpnc                   ;                                 |B0
PutDAT                          ; entry point for "dat" data
        setc                    ; RS = 1 (data)                   |B0
        movwf   temp            ; save WREG data byte             |B0
        swapf   temp,W          ; hi nybble in b3..b0             |B0
        call    PutNyb          ; send left nybble                |B0
        movf    temp,W          ; lo nybble in b3..b0             |B0
        call    PutNyb          ; send right nybble               |B0
        DelayCy(60*usecs)       ; 60 usec delay                   |B0
        return                  ;                                 |B0
PutNyb
        andlw   0x0F            ; mask off left nybble            |B0
        skpnc                   ; C=0 (RS=0)? yes, skip, else     |B0
        iorlw   b'00010000'     ; set lcd RS bit (RC4)            |B0
        movwf   PORTC           ; assert D7..D4 & RS pins         |B0
        iorlw   b'10000000'     ; set lcd E bit (RC7)             |B0
        movwf   PORTC           ; E = 1 (strobe)                  |B0
        xorlw   b'10000000'     ; clr lcd E bit (RC7)             |B0
        movwf   PORTC           ; E = 0                           |B0
        return                  ;                                 |B0

;******************************************************************
;  K8LH DelayCy() subsystem 16-bit uDelay(11..327690 cycle) sub'  *
;******************************************************************
        nop                     ; entry for (delay-11)%5 == 4     |B0
        nop                     ; entry for (delay-11)%5 == 3     |B0
        nop                     ; entry for (delay-11)%5 == 2     |B0
        nop                     ; entry for (delay-11)%5 == 1     |B0
uDelay  addlw   -1              ; subtract 5 cycle loop time      |B0
        skpc                    ; borrow? no, skip, else          |B0
        decfsz  delayhi,F       ; done?  yes, skip, else          |B0
        goto    uDelay          ; do another loop                 |B0
        return                  ;                                 |B0

;******************************************************************
;  main init                                                      *
;******************************************************************
Init
        bsf     STATUS,RP1      ; bank 2                          |B2
        clrf    ANSEL           ; turn off analog pin functions   |B2
        clrf    ANSELH          ;                                 |B2
        bcf     STATUS,RP1      ; bank 0                          |B0
        bsf     STATUS,RP0      ; bank 1                          |B1

;       movlw   b'01110000'     ; setup INTOSC for 8-MHz          |B1
;       movwf   OSCCON          ;                                 |B1
;       btfss   OSCCON,HTS      ; osc stable? yes, skip, else     |B1
;       goto    $-1             ; test again                      |B1

        clrf    TRISC           ; RC7..RC0 all outputs            |B1
        movlw   b'00001000'     ; RA3 input, all others outputs   |B1
        movwf   TRISA           ;                                 |B1
        bcf     STATUS,RP0      ; bank 0                          |B0
        clrf    PORTA           ;                                 |B0
        clrf    PORTC           ;                                 |B0
[COLOR=Blue];
;  HD44780 LCD 4-bit interface initialization procedure
;
        DelayCy(30*msecs)       ; delay 30-msecs after power up   |B0
        movlw   0x03            ; step 1, "function set" 8-bit    |B0
        call    PutNyb          ; write 4-bits only               |B0
        DelayCy(5*msecs)        ; required 5-msec delay           |B0
        movlw   0x03            ; step 2, "function set" 8-bit    |B0
        call    PutNyb          ; write 4-bits only               |B0
        DelayCy(160*usecs)      ; required 160-usec delay         |B0
        movlw   0x03            ; step 3, "function set" 8-bit    |B0
        call    PutNyb          ; write 4-bits only               |B0
        DelayCy(160*usecs)      ; required 160-usec delay         |B0
        movlw   0x02            ; step 4, "function set" 4-bit    |B0
        call    PutNyb          ; write 4-bits only               |B0
        DelayCy(160*usecs)      ; required 160-usec delay         |B0
;
;  now we're in 4-bit mode and can handle 8-bit transactions
;
        movlw   b'00101000'     ; 4-bit, 2-lines, 5x7 font        |B0
        call    PutCMD          ; send "function set" command     |B0
        movlw   b'00001000'     ; display, cursor, blink all off  |B0
        call    PutCMD          ; send "display on/off" command   |B0
        movlw   b'00000001'     ; clear display (1.53-msecs)      |B0
        call    PutCMD          ; send "entry mode set" command   |B0
        DelayCy(1500*usecs)     ; required 1.53-msec delay        |B0
        movlw   b'00000110'     ; cursor inc, shift off           |B0
        call    PutCMD          ; send "entry mode set" command   |B0
        movlw   b'00001100'     ; display on, leave cursor off    |B0
        call    PutCMD          ; send "display on/off" command   |B0
[/COLOR] 
;******************************************************************
;  main loop                                                      *
;******************************************************************
Loop
        movlw   line1+0         ; line 1, tab 0                   |B0
        call    PutCMD          ;                                 |B0
        movlw   'H'             ; send "Hello World" to LCD       |B0
        call    PutDAT          ;                                 |B0
        movlw   'e'             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   'l'             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   'l'             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   'o'             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   ' '             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   'W'             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   'o'             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   'r'             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   'l'             ;                                 |B0
        call    PutDAT          ;                                 |B0
        movlw   'd'             ;                                 |B0
        call    PutDAT          ;                                 |B0
;
        goto    $               ; loop forever                    |B0
;******************************************************************
        end
 

Attachments

  • K8LH LCD Photo 1..JPG
    K8LH LCD Photo 1..JPG
    36.5 KB · Views: 457
Last edited:
Hi Thanks for the reply's.

I can confirm that the LCD is definatley correctly connected.

I do not have access to a scope to see the data trnsmission, i preesume this will happen too fast for a logic probe to monitor.

Nigel, what LCD did you use, or what LCD's has any one else used for this code?

Mike, thanks for your reply but I am only using a 2 port pic, it looks a mamoth job to change your code to work on 2 port pic.

Is there any merit in getting a different type of LCD to see if it works?

Thanks
 
Mike, thanks for your reply but I am only using a 2 port pic, it looks a mamoth job to change your code to work on 2 port pic.

I suspect it might seem like a lot of work to a newcomer but it's not that bad. If I can find some spare time over the next few days I will make the program changes for a 16F628A. I assume you're using Nigel's connections -- LCD D4..D7 on RA0..RA3, LCD RS on RA4, and LCD E on RA7? If so, then you'll just need to ground the LCD RW pin because my program doesn't use the LCD "busy flag".

Kind regards, Mike
 
Last edited:
Hi Mike

Thaks for your help. Yes I am using nigels schematic connection

I think I am better utlisisng my time trying to get nigels circuit and software working, as I am on a bit of a tight schedule, but if you are able to modify this then it would be much appreciated.

Thanks
charlie
 
Hi Charlie,

Nigel's hardware is fine, except that I don't use the LCD "busy flag" and so I don't need to use the LCD RW pin and I tie it ground.

Instead of modifying Nigel's software, I was just going to create a new project for 16F628A and then copy my 16F690 demo' program into that project. The changes are relatively simple. In fact, it would probably take less time to do it then it would to explain it so if you hang on for an hour or so I will just post the 16F628A version of the program.

Regards, Mike
 
Last edited:
Charlie,

Here's an "untested" version of the demo' for 16F628A. Again, you need to disconnect the LCD RW pin from the PIC and ground it for this software. Sorry!

Good luck on your project.

Regards, Mike
 

Attachments

  • 628A+LCD..asm
    9 KB · Views: 231
Last edited:
Mike
i cannot tell you how appreciated this is.

Once I get home from work I will test it and let you know the outcome

- thanks very much.
 
Well I've never heard of any such changes required, nor seen any datasheets which specify that - including the datasheet for the module in question linked above. But I hope it works.
 
Charlie,

I apologize for not looking at your LCD Data Sheet before Nigel mentioned it. It seems your LCD does not require the special 4-bit initialization & reset procedure that I described, though that procedure would properly initialize your LCD and almost every other HD44780 compatible LCD.

When you get home from work can you try Nigel's software again but with the following minor changes and let us know if it works?

Regards, Mike

Code:
;Initialise LCD
LCD_Init
         [COLOR=Red]movlw   0x02            ; Set 4 bit mode
         call    LCD_Nyb         ; <---[/COLOR]
         movlw   0x28            ;Set display shift
         call    LCD_Cmd
         movlw   0x06            ;Set display character mode
         call    LCD_Cmd
         movlw   0x0d            ;Set display on/off and cursor command
         call    LCD_Cmd
         call    LCD_Clr         ;clear display
         retlw   0x00

; command set routine
LCD_Cmd
         movwf   templcd
         swapf   templcd,w       ;send upper nibble
         andlw   0x0f            ;clear upper 4 bits of W
         movwf   LCD_PORT
         bcf     LCD_PORT,LCD_RS ;RS line to 0
         call    Pulse_e         ;Pulse the E line high
         movf    templcd,w       ;send lower nibble
[COLOR=Red]LCD_Nyb[/COLOR]
         andlw   0x0f            ;clear upper 4 bits of W
         movwf   LCD_PORT
         bcf     LCD_PORT,LCD_RS ;RS line to 0
         call    Pulse_e         ;Pulse the E line high
         call    Delay5
         retlw   0x00
 
Last edited:
Well I've never heard of any such changes required, nor seen any datasheets which specify that - including the datasheet for the module in question linked above. But I hope it works.

hi Nigel,
I have found that if the power supply does not meet the rise times expected for the LCD it will not internally reset.
So in many cases where the OP gets this 'failure to auto reset' it could be related to the way he is powering the PIC/LCD.

If the users power supply has 'large value ' capacitors on the output of a regulator this can also cause slower +5v rise times which cause a reset fail.

My advice to users who get LCD initialising problems, would be to state in their posts how the PIC/LCD is being powered.

Attached are some clips from the Hitachi manual.

PwrReset1..png
 
Hi all
Thanks very much for your help

It appears that this may be a common problem erienced by others using nigels software, i have seen others on forums and this forum experiencing similar issues.

I am using a lm7805ct with a 33uf capaitor on incomming side and a 1uf cap on out site, unfortunatley i cannot attach anything for some reason at the moment but here is a link to the data sheet,


https://www.electro-tech-online.com/custompdfs/2010/04/0900766b80d25b92.pdf

(Figure 7)

Perhaps someone could show a way of using or modifying nigels software showing or explaining how an initilisation is carried out in the software.

Thanks for all your help.
 
Charlie,

Were you able to get your LCD running with my program or with Nigel's program with the changes I suggested?
 
Perhaps someone could show a way of using or modifying nigels software showing or explaining how an initilisation is carried out in the software.

Thanks for all your help.

hi,
Please post a commented listing of your full program and I will add the LCD init subr.
 
Hi
here is the code that I am using to try and drive the LCD, it should be inserted as a .txt file
This is taken from nigels website. thanks nigel. Here is the link provided for other who may be interested in his tutorials).


Mike - Thanks for your help - i tried to assemble the code you suggested in mplab. When it assembled it kept getting to something along the lines of clean intermidiate files, and never managed to get past that point.


Once again thanks for you help, hugely appreciated.

Charlie
 

Attachments

  • lcd.txt
    5.1 KB · Views: 224
Last edited:
It appears that this may be a common problem erienced by others using nigels software, i have seen others on forums and this forum experiencing similar issues.

Not as far as I'm aware of?, and there are large numbers of people all over the world using my LCD code - the few I've helped with problems all had construction errors.

As I said, I've never heard of any different initialisation sequences, which would render the code incompatible with the Hitachi standands (although it wouldn't cause any problems, as the extra bit is just ignored). Is it perhaps something new added to some particularly modern devices? - I don't think I have any more modern than about three years?.
 
Status
Not open for further replies.

Latest threads

Back
Top