The variable rc is short for return code. You can use
the return code as a verification device as the return code
in this case should be equal to the character that was sent.
We can use the same sendchar function to arbitrarily set
the cursor position. The syntax for cursor positioning is
0xFE 0x47 [column][row]:
//**********************************************
//* SET THE CURSOR POSITION
//**********************************************
void position_cursor(char column,char row)
{
rc = sendchar(0xFE);
rc = sendchar(0x47);
rc = sendchar(column);
rc = sendchar(row);
}
When displaying text, positioning the cursor is an
absolute necessity. Being able to clear the screen is also a
very desirable function. I think you’ve already broken the
code. So, if I give you the command syntax for clearing
the LCD panel (0xFE 0x58), I believe your code would
look like this:
//**********************************************
//* CLEAR THE SCREEN
//**********************************************
void clear_screen(void)
{
rc = sendchar(0xFE);
rc = sendchar(0x58);
}
Piece of cake. This is all fine until we get ready to
push some text out to the display. What if we wanted to
display the message “NUTS AND VOLTS” at the home
position? You already know how to send the cursor home.
So, here’s the code to display our message:
//**********************************************
//* DISPLAY SOME TEXT USING SENDCHAR
//**********************************************
void display_text(void)
{
rc = sendchar(‘N’);
rc = sendchar(‘U’);
rc = sendchar(‘T’);
rc = sendchar(‘S’);
rc = sendchar(‘ ‘);
rc = sendchar(‘A’);
rc = sendchar(‘N’);
rc = sendchar(‘D’);
rc = sendchar(‘ ‘);
rc = sendchar(‘V’);
rc = sendchar(‘O’);
rc = sendchar(‘L’);
rc = sendchar(‘T’);
rc = sendchar(‘S’);
}
That’s a lot of typing to only display 14 characters.
Even if you cut and paste the sendchar statements, you
would need a road map to navigate the longer messages
in your source code.
The sendchar method works well with commands
and short pieces of text. However, what if we needed to
THE DESIGN CYCLE
display hundreds of characters? How would we handle
displaying data that is constantly changing over time?
Let’s rewrite our NUTS AND VOLTS message code:
//**********************************************
//* DISPLAY SOME TEXT USING PRINTF
//**********************************************
void display_text(void)
{
printf(“%c%c%c%c NUTS AND VOLTS”,
0xFE,0x47,1,1);
}
Whoa! Only one line of code! There’s even a position
the cursor command mixed in with our text message.
Each %c in the printf statement is respectively associated
with the numeric values outside of the quotes. Those
values located at the end of the printf statement constitute
a position cursor command. The coordinates of the
position cursor command are column 1, row 1. Thus,
the text NUTS AND VOLTS will be displayed beginning at
column 1, row 1.
The printf function does not utilize the interrupt-driven
EUSART firmware. So, nothing gets buffered and no
EUSART interrupts are triggered when the printf function
is called. I think you already know how to rewrite all of the
sendchar cursor movement functions using the printf
method. So, we’ll move on.
Suppose we want to monitor and display four tank
temperatures driven by three independent systems. Just
thinking about performing this task using the sendchar
method gives me the willies. So, let’s write the code
using the easier and cleaner printf method. We’ll start by
rewriting our clear screen function:
//**********************************************
//* CLEAR SCREEN
//**********************************************
void cls_lcd(void)
{
printf(“%c%c”,0xFE,0x58);
}
I don’t think we need to expound on the obvious.
With that, here’s the display code:
//**********************************************
//* DISPLAY TANK TEMPERATURES
//**********************************************
void display_data(void)
{
cls_lcd();
printf(“%c%c%c%c NUTS AND VOLTS / DESIGN
CYCLE”,0xFE,0x47,3,1);
printf(“%c%c%c%c TANK1”,0xFE,0x47,1,5);
printf(“%c%c%c%c TANK2”,0xFE,0x47,1,6);
printf(“%c%c%c%c TANK3”,0xFE,0x47,1,7);
printf(“%c%c%c%c TANK4”,0xFE,0x47,1,8);
printf(“%c%c%c%c SYS_A”,0xFE,0x47,7,3);
printf(“%c%c%c%c SYS_B”,0xFE,0x47,14,3);
printf(“%c%c%c%c SYS_C”,0xFE,0x47,21,3);
tempF = (1.8 100) + 32;
printf(“%c%c%c%c %3.2f”,
0xFE,0x47,7,5,tempF);
printf(“%c%c%c%c %3.2f”,
November 2008 73