Banner PIC

Multiple Text Messages

This PIC assembler software example shows how to create a set of text messages that can be sent to an output (e.g. serial port or display), by referencing the message with a single literal byte value: –

start           movlw   0x00          ; write message 1
                call    do_message
                ...
                movlw   0x01          ; write message 2
                call    do_message
                ...
                movlw   0x02          ; write message 3
                call    do_message
                ...

The message data table should be stored at the beginning of a memory page and structured in the following manner: –

                org     0x0200

message_tab     addwf   PCL, f
                retlw   message01 - message01
                retlw   message02 - message01
                retlw   message03 - message01

message_read    addwf   PCL, f

message01       dt      "PIC uController", 0x00
message02       dt      "Message 2 Display Test", 0x00
message03       dt      "This is Message 3", 0x00

The ‘message_tab’ routine/table returns the location of the message text. Each message can be of variable length and should be terminated by a 00H value.

The following routine retrieves the message location, and outputs each character until the termination byte (00H) is reached: –

TEMP1           equ     0x20
TEMP2           equ     0x21

do_message      movwf   TEMP1
                movlw   0x02                    ; set message table page
                movwf   PCLATH
                movf    TEMP1, w
                call    message_tab             ; get message page offset
                movwf   TEMP1
do_message1     movf    TEMP1, w
                call    message_read            ; get message character
                movwf   TEMP2
                xorlw   0x00                    ; check for end (00H)
                btfsc   STATUS, Z
                return
                movf    TEMP2, w
                call    output_char             ; send character to output
                incf    TEMP1, f
                goto    do_message1

And this is a simplified example routine of writing to an LCD module: –

output_char     movwf    LCD_PORT_DATA          ; write character to LCD port
                bsf      LCD_PORT_CNTL, LCD_RS	; set RS line high
                nop
                bsf      LCD_PORT_CNTL, LCD_E   ; latch in data
                nop
                bcf      LCD_PORT_CNTL, LCD_E
                goto     delay_40us             ; do 40us delay between writes