16F819 PIC driving LCD

Thread Starter

ham_man

Joined Jan 9, 2014
7
Hi I am relatively new to PIC programming and am just using it as a hobby.
At present I am familliar with assembly language but only in the very early stages of using C language.
I have had great fun with programming PIC for using LCD display, using 4 bit transfer and two analogue inputs, but I would now like to use Busy check on the LCD so that I don't have to worry about delays and altering osc frequency(within reasonable limits. etc.
To concentrate on getting the B/Flag going properly I have used another program and cut it down to a very simple LCD output (It just writes a name on the bottom line).
If i just use a delay in place of the B/Flag check routine--it works fine, but replacing the delay with the B/Flag routine gives 2 lines and nothing else.
I have checked everywhere I can think of on the net---unfortunately most information is in C language!
If anyone would be kind enough to help (In ASSEMBLY language if possible) I would be most grateful.
I list my B/flag routine ---called Busywait below:-

Rich (BB code):
BUSYWAIT        BSF    STATUS,5    ;GOTO BANK 1
            MOVLW    0FFH        ;PORTB ALL INPUTS
            MOVWF    TRISB
            BSF    OPTION_R,7    ;DISABLE PULLUPS
            BCF    STATUS,5    ;RETURN TO BANK 0
    STILLBUSY    BSF    PORTA,3        ;E LINE ENABLE DISPLAY--CLOCK HIGH
            BSF    PORTA,2        ;R/W LINE SET HIGH TO READ LCD DATA
            BCF    PORTA,1        ;R/D CLEAR---SET TO COMMAND
            NOP            ;SMALL DELAY TO ENSURE LCD DATA STABLE
            NOP            ;SMALL DELAY TO ENSURE LCD DATA STABLE
            BCF    PORTA,3        ;CLOCK LOW TO SET LCD DATA INTO PORTB 1ST NIBBLE
            MOVF    PORTB,W        ;MOVE PORTB DATA INTO W REG
            MOVWF    TEMP1        ;MOVE LCD DATA 1ST NIBBLE INTO TEMP1 FILE
            BSF    PORTA,3        ;CLOCK HIGH ENABLE 2ND NIBBLE FROM LCD
            NOP            ;SMALL DELAY TO ENSURE LCD DATA STABLE
            NOP            ;SMALL DELAY TO ENSURE LCD DATA STABLE
            BCF    PORTA,3        ;CLOCK LOW TO READ 2ND NIBBLE (NOT NEEDED FOR B/F CHECK??)
            BTFSC    TEMP1,7        ;TEST 1ST NIBBLE (MSB) BUSY FLAG  TEMP1,7 
            GOTO    STILLBUSY    ;LOOP IF B/F STILL SET
            BCF    PORTA,2        ;BACK TO WRITE TO LCD MODE
            BSF    STATUS,5    ;GO TO BANK1
            MOVLW    00H        ;SET ALL PORTB O/P 
            MOVWF    TRISB
            BCF    OPTION_R,7    ;RE-ENABLE PORTB PULLUPS
            BCF    STATUS,5    ;RETURN TO BANK 0
            RETLW    0        ;RETURN W REG CLEARED
Any help will be appreciated --many thanks
 
Last edited by a moderator:

Thread Starter

ham_man

Joined Jan 9, 2014
7
Hi many thanks for the quick reply I will certainly check that out, this problem has been a big slow down for me so far, like about 3 days messing about with the software and searching the net--I hope the tutorials use assembly ---thanks again best wishes
 

Thread Starter

ham_man

Joined Jan 9, 2014
7
Hi again MaxHeadRoom, I have found the Busy Flag read routine in the tutorials --it looks surprisingly similar to my effort, just a couple of lines different, doing the same function, but that may make all the difference! I'll try it out with my hardware.
Many thanks again for all your interest.
 

Thread Starter

ham_man

Joined Jan 9, 2014
7
Hi bertus, many thanks for editing (sorting out) my posted code using code tags. I'm a newby and will use tags in future thanks again
 

t06afre

Joined May 11, 2009
5,934
You also must have in mind that the buzzy flag on the LCD. Do not function in the early stages of the configuration procedure. I do not remember exact then it become active. But should be noted in the datasheet
 

Thread Starter

ham_man

Joined Jan 9, 2014
7
Hi Thanks--yes you are correct the B Flag cannot be polled until initation has completed ----after about 3 inputs of (say) 0x30, with long delays 4/5 msecs between each one. Then after that you can change to 4 bit tansfer (or whatever) and poll the B Flag.
With help from several members I now have the routine working well--it saves messing about with delays in the program.
So many thanks all round. :)
 

takao21203

Joined Apr 28, 2012
3,702
I have used assembler for some years on the 16f.

The problem when you write the bitnumber like that is you can not reuse it, without making a lot of changes.

And for larger programs you also need to do the banking.

Why not let the C compiler generate the assembler for you?

using .h include files, #defines and automatic banking as well FSR handling at the end of the day let you write 10x much as code.

It is OK to use assembler for a while but it is important to make the transition some day.

If you want to use USB, it is not worth it by the assembler way.

People mostly use C for good reasons, such as exchangeability and portability, and to make it easy for others to read code.

2 As for the busy flag, yes it can be tested, but you need to change the tristate each time.

There are other ways than a delay, you can program flags together with a timer interrupt, and a small LCD command parser.

I have done this in assembler some while ago. Learning memory addressing in C is not all that easy, but it can be done. It is absolutely worth it.

Still have all my assembler sources on the harddrive, but they are embarassing to show off. And lengthy, even if just for LCD. For instance reading from internal EE tables, and even alternatively from external I2C EE.
 

THE_RB

Joined Feb 11, 2008
5,438
...
With help from several members I now have the routine working well--it saves messing about with delays in the program.
...
Most of the LCD commands only need a handful of uS "delay" which is often used up by code execution time without even needing a deliberate delay.

It saves messing about with tristating pins and the busy flag. ;)
 
Top