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.

LCD using a Lookup Table

Status
Not open for further replies.
That's some beautiful neat well commented assembler code Jake;
Jake's assembler code.htm :)

If I could make a suggestion, put a zero as the last character in your text lookup table, then it can automatically detect when it is finished writing the text string to the LCD.

That costs an extra byte per text string, but it's good because it makes it much easier to call the strings for display, and you will no longer need to pass a starting address AND a finishing address every time you want to display a string.
 
Last edited:
That's some beautiful neat well commented assembler code Jake;
Jake's assembler code.htm :)

If I could make a suggestion, put a zero as the last character in your text lookup table, then it can automatically detect when it is finished writing the text string to the LCD.

My tutorials do just that, but it's only one solution (the C way) - another is the Pascal way, where the first databyte of the string is the length of the string.
 
Thanks for the tip.
I have taken this on board and changed my program.

The link in Mr.RB's post is still valid but is the new version.

another is the Pascal way, where the first databyte of the string is the length of the string.
Nigel, would this Pascal way take roughly the same amount of instructions as the 'return 0' way?
 
Hi Jake (and gang),

Another very old method for 16F' devices which might seem more intuitive to some people as the string tables are stored "in-line" with your code (below). Macro "overhead" is 6 words per string. String tables can be longer than 256 bytes (not really necessary for LCD strings) and can straddle 256 byte boundaries;

Regards, Mike

Code:
;
;  example usage
;
        movlw   line1+0         ;
        call    LcdCmd          ; line 1, htab 0
        PutStr  "Hello"         ;
        movlw   line2+0         ;
        call    LcdCmd          ; line 2, htab 0
        PutStr  "your name here"
Code:
;******************************************************************
;
;  PutStr macro - print a string to the LCD
;
PutStr  macro   str             ;
        local   String, Print
        movlw   low String      ;
        movwf   PTRL            ;
        movlw   high String     ;
        movwf   PTRH            ;
        goto    Print           ;
String  dt      str,0
Print   call    PutString       ; print string
        endm
;
Code:
;******************************************************************
;
;  PutString - setup PTRL and PTRH to string address before entry
;            - string must be terminated with a 0 byte
;
PutString
        call    GetTable        ; get a table character           |B0
        andlw   b'11111111'     ;                                 |B0
        btfsc   STATUS,Z        ; a 00 byte, last character?      |B0
        return                  ; yes, return                     |B0
        call    LcdDat          ; output char                     |B0
        incfsz  PTRL,F          ; increment pointer               |B0
        goto    PutString       ;                                 |B0
        incf    PTRH,F          ;                                 |B0
        goto    PutString       ;                                 |B0
;
GetTable
        movf    PTRH,W          ;                                 |B0
        movwf   PCLATH          ;                                 |B0
        movf    PTRL,W          ;                                 |B0
        movwf   PCL             ;                                 |B0
;
;******************************************************************
 
Last edited:
I'm not sure there would be much difference in the assembler speed Nigel? Maybe one extra PIC instruction if it hasn't already done a movf.

With a stored 0 byte;
(get byte here)
(movf,f here if it hasn't already been done)
btfsc status,z
goto get_next_char

With a predefined string length;
(get byte here)
decfsz len,f
goto get_next_char

The big advantage of the 0 terminator is the user never has to count how long a string is and type in a number.
 
I'm not sure there would be much difference in the assembler speed Nigel? Maybe one extra PIC instruction if it hasn't already done a movf.

An extra one every time through the loop - although for driving an LCD a uS or two here or there makes no difference whatsoever :D

With a predefined string length;
(get byte here)
decfsz len,f
goto get_next_char

The big advantage of the 0 terminator is the user never has to count how long a string is and type in a number.

Pascal type strings make string functions easier, although it doesn't really apply here - personally I've always used zero terminated strings in PIC assembler, but I thought it was worth mentioning it's not the only way.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top